4W 3 band ssb transceiver

Even though it may not look like it in the picture, key development phases have been completed.
Development of Spots Two continues. Here is a clip about passband tuning in SSB transmission.
Here is the audio using the power amplifier (PA). As expected, distortion and compression increase. Keep in mind that the PA operates at only 7.6V and delivers a maximum output of 5W.
Test of the output power of the PA running only 7.8V power
Testing the input sensitivity of the Spot Two prototype against the proven Elecraft KX2:
The comparison is a bit unfair to us. The bandwidth set on the Spot Two is noticeably wider, which means more noise. Furthermore, the unshielded design generates additional background noise. Incidentally, the signal arrived at 0.1 µV—that’s an S0 reading! :-))
///////////////////////////////////////////////////////////////////////////////
// SPOTA TWO
// Board Waveshare RP2040-Zero
// Display Nokia 5110 / PCD8544 with 84x48 pixel // Display x=84 y=48 px
// Textsize 1 6x8 px // Textsize 2 12x16 px including spaces
///////////////////////////////////////////////////////////////////////////////
String version="Ad"; // 2026.08.18 (A,B,C ... big steps and a,b,c ... small step)
///////////////////////////////////////////////////////////////////////////////
// DEBUG Mode switch ----------------------------------------------------------
// #define DEBUG_MODE <-------DISABLED
// DEBUG Mode switch ----------------------------------------------------------
#include <Adafruit_NeoPixel.h> // <---------- Adafruit Onboard LED driver
#include <Rotary.h> // <--- CaggyRotary by Martin Evans
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <si5351.h> // <--- Etherkit_Si5351
#include "Wire.h"
#include "EEPROM.h" // <--- maintainer=Earle F. Philhower see libary -> docs
#include "RP2040_PWM.h" // <--- RP2040_PWM by Khoi Hoang
// Bitmaps ----------------------------------------------------------
/*////// PCD BITMAP SHEET ////////////////////////////////////////////////////
Draw XBitMap Files (*.xbm), exported from GIMP,
Usage:
Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor.
C Array can be directly used with this function
void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h,
uint16_t color)
*////////////////////////////////////////////////////////////////////////////
#define logo_width 84
#define logo_height 48
static unsigned char logo_bits[] = {
0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0x01, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf0, 0x01, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
0x03, 0x3f, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xc3,
0x07, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xe7, 0x01,
0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0xe7, 0x00, 0x00,
0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0f, 0x00, 0x00, 0x0e,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0x00, 0x00, 0x8c, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x1e, 0x00, 0x00, 0xc0, 0x07, 0x00,
0x00, 0x00, 0xc0, 0x01, 0x0f, 0x1e, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00,
0x00, 0xe0, 0x03, 0x0f, 0x3c, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00,
0xe0, 0x87, 0x07, 0x3c, 0x00, 0x00, 0x78, 0x1e, 0x00, 0x00, 0x00, 0xe0,
0x9f, 0x07, 0x38, 0x80, 0x03, 0x7c, 0x1e, 0x00, 0x00, 0x00, 0xe0, 0xff,
0x03, 0x78, 0xc0, 0x07, 0x3e, 0x1c, 0x00, 0x00, 0x00, 0xf0, 0xfc, 0x03,
0x70, 0xf0, 0x0f, 0x1f, 0x3c, 0x00, 0x00, 0x00, 0xf0, 0xf8, 0x03, 0xf0,
0xf8, 0x1e, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0xf0, 0xe0, 0x01, 0xe0, 0x7c,
0xbe, 0x07, 0x78, 0x00, 0x00, 0x00, 0x70, 0xc0, 0x00, 0xe0, 0x1f, 0xfc,
0x03, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0xe0, 0x0f, 0xf8, 0x01,
0x70, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0xc0, 0x07, 0xf0, 0x00, 0xf0,
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0xc0, 0x01, 0x60, 0x00, 0xf0, 0x00,
0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00,
0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x00, 0xfc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xfe, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x03, 0x00, 0xe0, 0xff,
0x07, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x1f, 0x00, 0xfc, 0xff, 0x7f,
0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0xff, 0xc0, 0x3f, 0x00, 0xfe, 0x03,
0x00, 0x00, 0x3c, 0x00, 0x00, 0xf8, 0xff, 0x0f, 0x00, 0xe0, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f,
0xfe, 0xc3, 0x3f, 0xfe, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x8e,
0xe3, 0x70, 0xe0, 0x00, 0x1f, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x0e, 0x77,
0xe0, 0xe0, 0x80, 0x1b, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x8e, 0x73, 0xe0,
0xe0, 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x71, 0xe0, 0xe0,
0xc0, 0x31, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0e, 0x70, 0xe0, 0xe0, 0xc0,
0x7f, 0x00, 0x00, 0x00, 0x20, 0x70, 0x0e, 0xe0, 0x70, 0xe0, 0xe0, 0x70,
0x00, 0x00, 0x00, 0xe0, 0x3f, 0x0e, 0xc0, 0x3f, 0xe0, 0x60, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#define cockatoo_width 20
#define cockatoo_height 42
static unsigned char cockatoo_bits[] = {
0x70, 0x00, 0x00, 0x88, 0x41, 0x00, 0x04, 0x7e, 0x00, 0x2c, 0x46, 0x00,
0x0a, 0x24, 0x00, 0x12, 0x1c, 0x00, 0x16, 0x04, 0x00, 0x18, 0x08, 0x00,
0x20, 0x08, 0x00, 0x40, 0x08, 0x00, 0x30, 0x0e, 0x00, 0x08, 0x11, 0x00,
0x88, 0x20, 0x00, 0x48, 0x40, 0x00, 0x10, 0x80, 0x00, 0x10, 0x80, 0x01,
0x10, 0x00, 0x01, 0x10, 0x00, 0x01, 0xa0, 0x00, 0x02, 0xa0, 0x10, 0x02,
0x20, 0x21, 0x02, 0x40, 0x42, 0x02, 0x80, 0x84, 0x02, 0x80, 0x08, 0x01,
0x00, 0x11, 0x02, 0x00, 0x22, 0x02, 0x00, 0x45, 0x00, 0x00, 0x09, 0x04,
0x00, 0x96, 0x00, 0xc0, 0x27, 0x05, 0x20, 0x40, 0x07, 0x00, 0x40, 0x04,
0x00, 0x40, 0x04, 0x00, 0x00, 0x05, 0x00, 0x80, 0x05, 0x00, 0x00, 0x01,
0x00, 0x00, 0x09, 0x00, 0x00, 0x09, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x08,
0x00, 0x00, 0x08, 0x00, 0x00, 0x08 };
// GPIO Ports --------------------------------------------------------------
#define CS 0
#define DC 1
#define CLK 2
#define DIN 3
#define RST 4
#define encoderPortA 5
#define encoderPortB 6
#define encoderPushPort 7
#define mySDA 8
#define mySCL 9
#define dotPPTPort 10
#define dashPort 11
#define txPort 12
#define bandwidthPort 13
#define filterRelayPort 14
#define sidetonePort 15
#define ledPort 16
#define pushButtonsPort 26
#define uBatteryPort 27
#define uRevPort 28
#define uFwrPort 29
// GPIO Ports --------------------------------------------------------------
// Onboard LED -------------------------------------------------------------
Adafruit_NeoPixel pixel(1, ledPort, NEO_GRB + NEO_KHZ800);
// Onboard LED -------------------------------------------------------------
// Display ---------------------------------------------------------
// Adafruit_PCD8544 display = Adafruit_PCD8544(CLK, DIN, DC, CS, RST);
// Hardware SPI (faster, but must use certain hardware pins):
Adafruit_PCD8544 display = Adafruit_PCD8544(CLK, DIN, DC, CS, RST);
// Display ---------------------------------------------------------
// SI5351 --------------------------------------------------------------
Si5351 si5351;
int32_t calFactor = 120000U; // 13500U;
// SI5351 -----------yyyxxxU ------------------------------------
// Frequency ------------------------------------------------------------
// unsigned long freq = 700000; // 700000 = 7.000.000 Hertz there is no 1Hz step
unsigned long stepFactor[] = {0, 10000, 1000, 100, 10, 1}; // 0 means no freq change
// Frequency ------------------------------------------------------------
// Cursor arrangement on the display Initial Cursor 1kHz C3 --------------
// TEMPORY!!!
// ^ ----------------------------------
// | - - - v
// | C9---C8---C7-C6--
// | SSB 15 KEY 10:10 |
// | 1 4 . 2 8 5 . 0 0 v
// --C0---C1-C2-C3--C4-C5--
// TEMPORY!!! loShift:10-14 bandwith:15 = maxCur
// ---------------------------------------------------
// Cursor -------------------------------------------------------------------------------------------
int cur = 3, maxCur = 15;
// Cursor -------------------------------------------------------------------------------------------
// Bands and Mode 0(40m CW) 1(40m SSB) 2(30m CW) 3(20m CW) 4(20m SSB) 5(17m CW) 6(17m SSB) ---------
String bandModeStr[] ={"CW", "LSB", "CW", "CW", "USB", "CW", "USB"} ;
unsigned long freqMin[] = {700000, 700000, 1010000, 1400000, 1400000, 1806000, 1806000};
unsigned long freq[] = {703000, 710000, 1011200, 1406000, 1428500, 1808000, 1812000};
unsigned long freqMax[] = {720000, 720000, 1015000, 1435000, 1435000, 1816800, 1816800};
int maxBandMode = 6, band = 1; // 40m mode SSB is inital band and mode---------------------------------
// LO shift in 10Hz ----------------------------------------------------------------
unsigned long loShiftFreq[] {982920, 982880, 982920, 982920, 983070, 982880, 983070}; // 7x4=28 bytes, see EEPROM Write
// LO in 10Hz ----------------------------------------------------------------
// Bandwith PWM value for the varibale capacitor in the crystal filter--------
int bandwidth[] {6, 16, 6, 6, 16, 6, 16}; // 7x4=28 bytes, see EEPROM Write
// Badwith --------------------------------------------------------------------
// EEPROM --------------------------------------------------------------
const long magic = 123456789; // This random number ist written in the EEPROM to check the validity of the data, 4 bytes, see EEPROM Write
static unsigned long eepromTimer = 0;
void EEPROMwrite() {
// To prevent the EEPROM write function from being called too frequently, a 10-second pause is implemented.
unsigned long timer = millis();
// TEMPORARILY
#if defined(DEBUG_MODE1)
Serial.println(timer);
Serial.println(10000 + eepromTimer);
#endif
// TEMPORARILY The settings will only be saved, when 10s are gone after the last setting. There could be a loss of the last setting by shutdown
if (timer < 10000 + eepromTimer)
return;
// TEMPORARILY
#if defined(DEBUG_MODE1)
Serial.print("Ready to go ");
Serial.println(eepromTimer);
#endif
eepromTimer = timer;
#if defined(DEBUG_MODE1)
Serial.print("Go on ");
Serial.println(magic); //
#endif
EEPROM.put(0, magic); // This random number ist written in the EEPROM to check the validity of the data, 4 bytes, see EEPROM Write
EEPROM.put(4, loShiftFreq); // 7x4=28 bytes, see variable definion above
EEPROM.put(32, bandwidth); // 7x4=28 bytes, see variable definion above
#if defined(DEBUG_MODE)
if (EEPROM.commit())
Serial.println(eepromTimer);
else
Serial.println("ERROR!");
#else
EEPROM.commit();
#endif
}
// EEPROM write ----------------------------------------------------------------------
// WPM Mode Clock Power SWR calculation ---------------------------------------------
int mode = 0, keyMode = 0, tuneMode = 1, memMode = 2, maxMode = 5;
int wpm = 15, minutes, minutesOffset = 600; // Start bei 10:00
String keyModeStr[] ={"KEY", "TUN", "CQS", "CQP", "CQH", "CQT"};
char clockString[8];
float uFwr, uRev, uEff, pwr, swr;
// ----------------------------------------------------- WPM Mode und Clock
// CW Memory --------------------------------------------------------
String cwStr[] = {"-.-.#--.-##...#---#-#.-##-..#.##-..#.-..#.----#-.-.#.-.#-..-.#.--.############",
"-.-.#--.-##-..#.##-..#.-..#.----#-.-.#.-.#-..-.#.--.############",
"-.-.#--.-##-..#.##-..#.-..#.----#-.-.#.-.############",
"-#.#...#-##-..#.-..#.----#-.-.#.-.############"};
// -------------------------------------------------------- CW Memory
// Encoder ---------------------------------------------------------
Rotary rotary = Rotary(encoderPortA, encoderPortB);
long rot=0, encoderDir=0;
void rotate() {
unsigned char result = rotary.process();
switch (result) {
case DIR_CW:
rot++;
break;
case DIR_CCW:
rot--;
break;
}
}
bool checkEncoder(){
encoderDir = rot / 2 ; // <------ No intermediate step
if (encoderDir != 0) rot = 0;
return (encoderDir != 0);
}
// Encoder press function
bool encoderPush() {
return digitalRead(encoderPushPort) == 0;
}
// Encoder ---------------------------------------------------------
// Keyer -----------------------------------------------------------
int count = 0;
int dot = 1;
int dash = 1;
int sidetone = 700;
int dotmem = 0;
int dashmem = 0;
int cwPause; // cwPause = 1200 / wpm;
long timeStamp = -1000;
// Keyer -----------------------------------------------------------
// Harmonic filter relais ----------------------------------------------------------
void setHarmonicFilter () {
// Relais
digitalWrite(filterRelayPort, band/2); // LOW at band 0, 1 otherwise HIGH
}
// Harmonic filter relais ----------------------------------------------------------
// Tune ------------------------------------------------------------------
void tune() {
if (mode == tuneMode)
txOn();
else
txOff();
}
// Tune ------------------------------------------------------------------
// Keyer ----------------------------------------------------------
void keyer() {
cwPause = 1200 / wpm;
if (dotmem == 1) makedot();
if (dashmem == 1) makedash();
count = 0;
check_paddle();
}
void txOn() {
si5351.output_enable(SI5351_CLK0, 1);
tone(sidetonePort, sidetone);
digitalWrite(txPort, LOW);
}
void txOff() {
digitalWrite(txPort, HIGH);
si5351.output_enable(SI5351_CLK0, 0);
noTone(sidetonePort);
}
void makedot() { //function to make dots
count = 0;
dotmem = 0;
txOn();
while (count < cwPause) {
dash = digitalRead(dashPort);
if (!dash) {dashmem = 1; timeStamp = millis();}
delay(1);
++count;
}
count = 0;
txOff();
while (count < cwPause) {
dash = digitalRead(dashPort);
if (!dash) {dashmem = 1; timeStamp = millis();}
delay(1);
++count;
}
}
void makedash() { //function to make dashs
count = 0;
dashmem = 0;
txOn();
while (count < (cwPause * 3)) {
dot = digitalRead(dotPPTPort);
if (!dot) {dotmem = 1; timeStamp = millis();}
delay(1);
++count;
}
count = 0;
txOff();
while (count < cwPause) {
dot = digitalRead(dotPPTPort);
if (!dot) {dotmem = 1; timeStamp = millis();}
delay(1);
++count;
}
}
void check_paddle() { //function for checking iambic paddle status
dot = digitalRead(dotPPTPort);
dash = digitalRead(dashPort);
if (!dot | !dash) {timeStamp = millis();}
if (!dot) makedot();
if (!dash) makedash();
}
// Keyer ----------------------------------------------------------
// cwMemory -------------------------------------------------------
void cwMemory() {
if (mode < memMode) return;
cwPause = 1200 / wpm;
while (mode >= memMode){
for (int i=0; i<cwStr[mode-memMode].length(); i++) {
if(checkEncoder()) {
mode += encoderDir;
if (mode < 0) {mode = maxMode;}
if (mode > maxMode) {mode = 0;}
return;
}
switch (cwStr[mode-memMode].charAt(i)) {
case '.':
txOn();
delay (cwPause);
txOff();
delay (cwPause);
break;
case '-':
txOn();
delay (3*cwPause);
txOff();
delay (cwPause);
break;
case '#':
delay (3*cwPause);
break;
} // switch
} //for
} //while
}
// cwMemory -------------------------------------------------------
// tuneGenerator ------------------------------------------------------------
unsigned long f, l, c; // Memory for SI5351
void tuneGenerator() {
if (f != freq[band]) f = freq[band];
if (l != loShiftFreq[band]) l = loShiftFreq[band];
// CW Shift
c = 0;
if (bandModeStr[band] == "CW") c = 70;
si5351.set_freq(10 * (c + f + l) * SI5351_FREQ_MULT, SI5351_CLK0); // Local Oszillator Low
si5351.set_freq(10 * l * SI5351_FREQ_MULT, SI5351_CLK1); // BFO Oszillator
}
// tuneGenerator ------------------------------------------------------------
// setBandwidth-------------------------------------------------------------
RP2040_PWM* PWM_Instance;
void setBandwidth() {
// bandwidth 0...20 -> 100%...0% -> 3.3V...0V // The voltage regulator inverts it to ~0...~8V
float pwmValue = 100 - (bandwidth[band] * 5); // bandwidth 0...20 -> 100%...0%
PWM_Instance->setPWM(bandwidthPort, 20000, pwmValue);
#if defined(DEBUG_MODE)
Serial.print("______SETBANDWIDTH________ pwmValue:");
Serial.println(pwmValue);
#endif
}
// setBandwidth-------------------------------------------------------------
// Clock string --------------------------------------------------------------
void myClock() {
minutes = minutesOffset + millis() / 60000; // 60000 Minutentakt
sprintf(clockString, "%02d:%02d", (minutes / 60) % 24, minutes % 60);
}
// Clock string --------------------------------------------------------------
// myDisplay ------------------------------------------------------------
void myDisplay () {
// Display x=84 y=48 px // Textsize 1 6x8 px // Textsize 2 12x16 px including spaces
int x, y;
float f;
display.clearDisplay();
display.setTextSize(1);
// Mode
display.setCursor(0, 0);
display.print(bandModeStr[band]);
// WPM value
display.setCursor(19,0);
display.print(wpm);
// Key Mode
display.setCursor(33,0);
display.print(keyModeStr[mode]);
// Clock
myClock();
display.setCursor(53,0);
display.print(clockString);
// Frequency digits
if (freq[band] <1000000){ ///< 10.000.00
display.setCursor(12, 11);
}
else {
display.setCursor(0, 11);
}
display.setTextSize(2);
display.print(freq[band]);
// Decimal dots
display.drawRect(22,23,2,2, BLACK) ;
display.drawRect(36+22,23,2,2, BLACK) ;
/////////// Only TEMPORARILY to support development /////////
// Lo Shift digits
display.setTextSize(1);
display.setCursor(6, 38);
display.print(loShiftFreq[band]);
display.setCursor(42, 38);
display.print("LO");
//
// Bandwidth digit
display.setTextSize(1);
display.setCursor(60, 30);
display.print(bandwidth[band]);
display.print("BW");
/////////// Only TEMPORARILY to support development /////////
// Frequency Cursor
x = 12+12*cur; y=26;
switch (cur) {
/////////// Only TEMPORARILY to support development /////////
// LOC SHIFT CURSOR
case 10: // LOCSHIFT x0000
x = 9; y = 46; break;
case 11: // LOCSHIFT 0x000
x = 15; y = 46; break;
case 12: // LOCSHIFT 00x00
x = 21; y = 46; break;
case 13: // LOCSHIFT 000x0
x = 27; y = 46; break;
case 14: // LOCSHIFT 0000x
x = 33; y = 46; break;
//
// Bandwith Cursor
case 15: // BANDWITH x
x = 59; y = 38; break;
/////////// Only TEMPORARILY to support development /////////
case 6: // Minute
x = 71; y = 8; break;
case 7: // Hour
x = 54; y = 8; break;
case 8: // KEY
x = 37; y = 8; break;
case 9: // WPM
x = 20; y = 8; break;
}
display.drawRect(x,y,10,2, BLACK);
// Voltage of pushbutton
display.setCursor(59,39);
display.print(analogRead(pushButtonsPort)); //
// TEMPORARILY
/*///////////// RF Power
uFwr = float(analogRead(uFwrPort));
uEff =(4.886e-3 * uFwr + 0.4)*7.07; // uEff = 10*(5/1023 * uFwr +0.4V)*0.707
pwr = uEff * uEff * 0.02; // pwr = uEff^2 / 50
if (pwr < 0.2) pwr=0;
display.setTextSize(1);
display.setCursor(2,39);
display.print(pwr,1);
display.print("W");
// SWR
uRev = float(analogRead(uRevPort)); // swr = (uFwr + uRev) / (uFwr - uRev)
swr = 1;
if (uFwr > uRev) {swr = (uFwr + uRev) / (uFwr - uRev);}
display.setCursor(30,39);
display.print(swr,1);
////////////// RF Power
// Voltage
display.setCursor(59,39);
display.print(0.0044689*float(analogRead(uBatteryPort)),1); // voltage divider 100k/22k 4095=3.3V
display.print("V");
*///////////////////////////////////////
// Update Display
display.display();
}
// myDisplay ------------------------------------------------------------------------
// SETUP --------------------------------------------------------------
void setup(void) {
// EEPROM Read-----------------------------------------------------------
EEPROM.begin(512);
// When the software runs for the first time, no valid EEPROM data is available yet.
// In this case, the initial values are used instead.
long checkMagic;
EEPROM.get(0, checkMagic); // 4 bytes
if (checkMagic == magic) {
EEPROM.get(4, loShiftFreq); // 4x7 bytes
EEPROM.get(32, bandwidth); // 4x7 bytes
#if defined(DEBUG_MODE1)
// TEMPORARILY
Serial.print("EEPROM magic ok");
#endif
}
// EEPROM Read-----------------------------------------------------------
// Onboard LED ----------------------------------------------------
pixel.begin();
pixel.setPixelColor(0, pixel.Color(0,0,16)); // low light blue
pixel.show();
// Onboard LED ----------------------------------------------------
// SERIAL TEMPORARILY ------------------------------------------------------------
#if defined(DEBUG_MODE)
Serial.begin(115200);
while (!Serial && millis() < 10000UL);
Serial.println("Serial started");
#endif
// SERIAL ------------------------------------------------------------
// Keyer, encoderbutton, tx out, Bandfilter Relais, Forward, Revers -------------------
pinMode(encoderPortA, INPUT_PULLUP);
pinMode(encoderPortB, INPUT_PULLUP);
pinMode(encoderPushPort, INPUT_PULLUP);
pinMode(uBatteryPort, INPUT);
pinMode(uFwrPort, INPUT);
pinMode(uRevPort, INPUT);
pinMode(dotPPTPort, INPUT_PULLUP);
pinMode(dashPort, INPUT_PULLUP);
digitalWrite(txPort, HIGH); // off
pinMode(txPort, OUTPUT);
pinMode(bandwidthPort, OUTPUT); // PWM for the filter bandwidth
digitalWrite(filterRelayPort, LOW); // off
pinMode(filterRelayPort, OUTPUT);
setHarmonicFilter();
// Keyer, encoderbutton, tx out, Bandfilter Relais, Forward, Revers -------------------
// Encoder -----------------------------------------------------------
attachInterrupt(digitalPinToInterrupt(encoderPortA), rotate, CHANGE);
attachInterrupt(digitalPinToInterrupt(encoderPortB), rotate, CHANGE);
// Encoder -----------------------------------------------------------
// SI5351 --------------------------------------------------------------
Wire.setSDA(mySDA);
Wire.setSCL(mySCL);
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, calFactor);
si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA);
si5351.output_enable(SI5351_CLK0, 1);
si5351.drive_strength(SI5351_CLK1, SI5351_DRIVE_8MA);
si5351.output_enable(SI5351_CLK1, 1);
// SI5351 ------------------------------------------------------------
// PWM for varicap of the crystal bandfilter ----------------------------
PWM_Instance = new RP2040_PWM(bandwidthPort, 20000, 70); // frequency 20 KHz, duty cycle 70%
#if defined(DEBUG_MODE)
Serial.println("new RP2040_PWM(bandwidthPort, 20000, pwmValue)");
#endif
// PWM for varicap of the crystal bandfilter ----------------------------
// Timestamp für den Keyer ----------------------------------------
timeStamp = millis() - 500;
// Timestamp für den Keyer ----------------------------------------
// myDisplay Init and Welcome----------------------------------------
// Display init
display.begin();
display.setContrast(60); // <------------------------
display.clearDisplay();
display.setRotation(2); // upside down
//Draw Spota logo
//void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
display.drawXBitmap(0,0,logo_bits, logo_width, logo_height, BLACK);
display.display();
delay (1000);
display.clearDisplay();
//Draw Cockatoo
//void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
display.drawXBitmap(64, 0, cockatoo_bits, cockatoo_width, cockatoo_height, BLACK);
// Print welcome text
display.setTextColor(BLACK);
display.setTextSize(2);
display.setCursor(3,3);
display.println("COCKA");
display.setCursor(10, 20);
display.println("TWO");
// Version
display.setTextSize(1);
display.setCursor(50, 26);
display.print(version);
// Builder
display.setTextSize(1);
display.setCursor(3, 40);
display.println("VK3HN & DL1CR");
display.display();
// Skip Welcome pages
for (int i=0; i<5000; i++) {
if (encoderPush() || checkEncoder()) return;
delay(2);
}
display.clearDisplay();
// myDisplay Welcome ----------------------------------------------
}
// SETUP-------------------------------------------------------------
// LOOP --------------------------------------------------------------
void loop(void) {
// Keyer
do {
keyer();
} while (millis() < timeStamp + 500); // 500 Millisekunden warten
// ect.
setBandwidth();
tuneGenerator();
myDisplay();
//// tune(); //<- see setup() ------------ ON
cwMemory();
// Tune
if (checkEncoder()) { // frequeny oder cursor has changed
if (encoderPush()) { // Move cursor
cur = cur + encoderDir;
if (cur < 0) {cur = maxCur;}
if (cur > maxCur) {cur = 0;}
}
else {
switch(cur) {
case 0: // change band / frequency digit for MHz
if (encoderDir !=0) {
band = band + encoderDir;
if (band < 0) {band = 0;}
if (band > maxBandMode) {band = maxBandMode;}
setHarmonicFilter();
}
break;
case 6: // minute
minutesOffset += encoderDir;
if (minutesOffset < 0) {minutesOffset = 0;}
break;
case 7: // hour
minutesOffset += encoderDir * 60;
break;
case 8: // Modus
// mode += encoderDir; <------ DISABLE Check the var mode and rename it!!!!!
if (mode < 0) {mode = maxMode;}
if (mode > maxMode) {mode = 0;}
break;
case 9: // WPM
wpm += encoderDir;
if (wpm < 10) {wpm = 10;}
if (wpm > 25) {wpm = 25;}
break;
/////////// Only TEMPORARILY to support development /////////
// LoShift frequency
case 10: case 11: case 12: case 13: case 14:
loShiftFreq[band] += stepFactor[cur-9] * encoderDir;
break;
case 15: // Bandwidth in the range 0..9 // TEMPORARILY
bandwidth[band] += encoderDir;
if (bandwidth[band] < 0) {bandwidth[band] = 0;}
if (bandwidth[band] > 20) {bandwidth[band] = 20;}
break;
/////////// Only TEMPORARILY to support development /////////
default: // change frequency
freq[band] += stepFactor[cur] * encoderDir;
if (freq[band] > freqMax[band]) {freq[band] = freqMax[band];}
if (freq[band] < freqMin[band]) {freq[band] = freqMin[band];}
}
}
// save changed parameter, if necessary and 10 sec has gone
EEPROMwrite();
}
}
// LOOP------------------------------------------------------------

