Hello...
I have connected a wemos d1 mini to an oled 128x64, and when I upload a test file everything works fine, but when I load the sketch it goes wrong, my knowledge of Arduino programming is on the low side, so any help is welcome ;- :
I see two bars on both sides of the display and I can't get rid of them!
Where should I look for the error?
//***************************************************************************************
// ***mods by vk3pe Jan 2023. Compiled using Arduino IDE Ver 1.8.19
// Added address 0x60 for Si5351 module I used. ie my own Si5351 PCB
// Currently modified to run on the 10M band.
// Jan 24th 2023 added an OLED display to show the various states of the ESP3266_WSPR
// The additions are prefaced by "//OLED" to show the changes.
// Si5351 CALibrated using https://raw.githubusercontent.com/etherkit/Si5351Arduino/master/examples/si5351_calibration/si5351_calibration.ino
// to obtain CAL factor.
// 7hi x 6w Pixels for Font(1), 12hi x 12w ? for Font(2)
//***************************************************************************************
//ESP_WSPR_ver_3_006
//
// Simple WSPR beacon for ESP8266, with Si5351A Breakout board
// FIX CLK0 Output for 20 m band with Fast time sync to prevent weather dependent time drift.
//
//***************************************************************************************
// Hardware info
// ---------------------
// serial debug port baud rate: 115200
// Si5351A is connected via I2C on pin D1 (SCL) and D2 (SDA) as marked on Wemos D1 mini Lite
// freq0 is used in clock0 output. It runs with 8mA output setting as standard > vk3pe
//
// Hardware Requirements
// ---------------------
// This firmware must be run on an ESP8266 compatible board
// tested on Wemos D1 Mini
// Required Libraries
// ------------------
// Etherkit Si5351 (Library Manager)
// Etherkit JTEncode (Library Manager)
// Time (Library Manager)
// Wire (Arduino Standard Library)
// NTPtimeESP
// ESP8266WiFi
//*******************************[ LICENCE and CREDITS ]*********************************************
// Original Code of Multiband NODEMCU WSPR by Marco,IW5EJM
//
// Modified for one output, fast time sync and LED mode flash modifications by Barbaros Asuroglu,WB2CBA
//
//Simple WSPR beacon for ESP8266, with the Etherkit or SV1AFN Si5351A Breakout
// Board, by Jason Milldrum NT7S.
//
// Original code based on Feld Hell beacon for Arduino by Mark
// Vandewettering K6HX, adapted for the Si5351A by Robert
// Liesenfeld AK6L <ak6l@ak6l.org>. Timer setup
// code by Thomas Knutsen LA3PNA.
// License
// -------
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject
// to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/*
Hello all,
I realized it's quite difficult to find precise information about defined WSPR frequencies for all available bands. So I wrote a list for all bands, here you go! The TX frequency center is always +1500 Hz above the dial frequency.
last update: 2018/01/18
----------Band----------Dial Frequency----------TX Frequency center(+range)--------------
2190m--------------0.136000---------------0.137500 (+- 100Hz)
630m----------------0.474200---------------0.475700 (+- 100Hz)
160m----------------1.836600---------------1.838100 (+- 100Hz)
80m------------------3.568600---------------3.570100 (+- 100Hz) (this is the default frequency in WSJT-X v1.8.0 to be within the Japanese allocation.)
80m------------------3.592600---------------3.594100 (+- 100Hz) (No TX allowed for Japan; http://www.jarl.org/English/6_Band_Plan/JapaneseAmateurBandplans20150105...)
60m------------------5.287200---------------5.288700 (+- 100Hz) (please check local band plan if you're allowed to operate on this frequency!)
60m------------------5.364700---------------5.366200 (+- 100Hz) (valid for 60m band in Germany or other EU countries, check local band plan prior TX!)
40m------------------7.038600---------------7.040100 (+- 100Hz)
30m-----------------10.138700--------------10.140200 (+- 100Hz)
20m-----------------14.095600--------------14.097100 (+- 100Hz)
17m-----------------18.104600--------------18.106100 (+- 100Hz)
15m-----------------21.094600--------------21.096100 (+- 100Hz)
12m-----------------24.924600--------------24.926100 (+- 100Hz)
10m-----------------28.124600--------------28.126100 (+- 100Hz)
6m-------------------50.293000--------------50.294500 (+- 100Hz)
4m-------------------70.091000--------------70.092500 (+- 100Hz)
2m-----------------144.489000-------------144.490500 (+- 100Hz)
70cm--------------432.300000-------------432.301500 (+- 100Hz)
23cm------------1296.500000------------1296.501500 (+- 100Hz)
On all bands you have to use USB mode. Please check local licence conditions and band plans prior transmitting !
And always keep in mind that power output >5W is considered as QRO on WSPR!
Best 73 de
Saki, DD5XX
*/
//*********************************[ Libraries ]*****************************************
#include <si5351.h>
#include "Wire.h"
#include <JTEncode.h>
#include <int.h>
#include <TimeLib.h>
#include <NTPtimeESP.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
//******************************[ DEFINE'S ]********************************************
#define TONE_SPACING 146 // ~1.46 Hz
#define WSPR_DELAY 683 // Delay value for WSPR
#define WSPR_CTC 10672 // CTC value for WSPR
#define SYMBOL_COUNT WSPR_SYMBOL_COUNT
#define TX_LED_PIN 2 //integrated onboard led
#define SEND_INTV 10
#define RECV_TIMEOUT 10
#define SI5351_REF 25000000UL //si5351’s crystal frequency, 25 Mhz or 27 MHz >>> 250006000UL? for vk3pe build.
//****************************************************************************************************
//**************************[ USER DEFINED PARAMETERS DECLARATION ]***********************************
//****************************************************************************************************
//unsigned long freq = 14097100UL; //Frekansi farkli WSPR bandlari icin degistirebilirsiniz. Change this for different band frequencies.
//unsigned long freq = 10138700UL; //Change this for different band frequencies. >>>> vk3pe 30M band
unsigned long freq = 14097100UL;
//int32_t cal_factor = 0; // SI5351 Kalibrasyon Katsayisini buraya giriniz. SI5351 Calibration factor obtained from Calibration firmware plugged in here.
int32_t cal_factor = 133200; // for PD8GB
const char* ssid = "**----------**"; //Sizin WIFI SSID'nizi buraya girin. SSID of your Wifi network *****
const char* password = "---------"; //Sizin WIFI sifrenizi buraya girin. Password of your wifi network *****
char call[7] = "PD8GB"; // Sizin Cagri Kodunuzu buraya giriniz. USER CALLSIGN *****
char loc[5] = "JO32"; // Sizin MAIDENHEAD KONUMLAMA GRID'inin ilk dort harfini nuraya girin.Ankara icin KM69. USER MAIDENHEAD GRID LOCATOR first 4 letters. *****
#define TIME_ZONE +1.0f //WAS +3 VK3PE //UTC ve LOkal zaman farkini buraya girin.(Turkiye icin +3 saat girili) Your time zone difference in regards to UTC (floating point number)
//*****************************************************************************************************
//*********************************[ END OF USER DEFINED PARAMETERS ]**********************************
//*****************************************************************************************************
//****************************[ VARIABLES DECLARATION ]************************************************
uint8_t dbm = 22; //Tx power ***** standard barefoot power out of this project is about +10dBm. 100mW = +20dBm, 200mW = +23dBm.
uint8_t tx_buffer[SYMBOL_COUNT];
const char* WiFi_hostname = "ESP_WSPR";
//Sync clock every 12 hours
#define NTPSYNC_DELAY 1
//NTP Server:
const char* NTP_Server = "ntp1.inrim.it";
//Si5351 si5351;
Si5351 si5351(0x60); //added by vk3pe jan 2023 to ensure I2C ADDR for my own Si5351 pcb
JTEncode jtencode;
bool warmup=0;
NTPtime NTPch(NTP_Server);
strDateTime dateTime;
//add OLED -----------------------------------------
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
// OLED display TWI address
#define OLED_ADDR 0x3C //usual I2C address for OLED's.
// reset pin not used on 4-pin OLED module
Adafruit_SSD1306 display(-1); // -1 = no reset pin
//--------------------------------------------------
//****************************************[ TIME SYNC FUNCTION ]******************************************
time_t epochUnixNTP()
{
digitalWrite(TX_LED_PIN, LOW);
Serial.println("- NTP Time Sync...");
Serial.print("- NTP Time:");
NTPch.setSendInterval(SEND_INTV);
NTPch.setRecvTimeout(RECV_TIMEOUT);
do
{
dateTime = NTPch.getNTPtime(TIME_ZONE, 1);
delay(1);
}
while(!dateTime.valid);
NTPch.printDateTime(dateTime);
setTime(dateTime.hour,dateTime.minute,dateTime.second,dateTime.day,dateTime.month,dateTime.year);
Serial.println(now());
digitalWrite(TX_LED_PIN, HIGH);
return 0;
}
//*********************************[ WSPR ENCODE and TRANSMIT FUNCTION ]**********************************************
void encode()
{
uint8_t i;
jtencode.wspr_encode(call, loc, dbm, tx_buffer);
digitalWrite(TX_LED_PIN, LOW);
Serial.println("- TX ON - STARTING TRANSMISSION...");
//OLED
display.clearDisplay();
Erase_text2();
display.setCursor(05,33); //,10
display.setTextSize(2); //text size
display.print(" Start Tx");
display.display();
// Now do the rest of the message
for(i = 0; i < SYMBOL_COUNT; i++)
{
si5351.set_freq((freq * 100) + (tx_buffer[i] * TONE_SPACING), SI5351_CLK0);
delay(WSPR_DELAY);
}
// Turn off the output
si5351.set_clock_pwr(SI5351_CLK0, 0);
digitalWrite(TX_LED_PIN, HIGH);
Serial.println("- TX OFF - END OF TRANSMISSION...");
//OLED
display.setTextSize(2);
display.display();
Erase_text2(); //black out lines. ie delete
display.setCursor(05,33);
display.print (" End Tx ");
display.display();
}
//*****************************************[ WIFI CONNECTION FUNCTION ]****************************************
void ssidConnect()
{
Serial.println("- ESTABLISHING WIFI CONNECTION TO:");
Serial.println(ssid);
Serial.println(password);
WiFi.begin(ssid, password);
Serial.print("- Connecting");
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(TX_LED_PIN, LOW);
delay(300);
digitalWrite(TX_LED_PIN, HIGH);
delay(300);
Serial.print(".");
}
Serial.println();
Serial.print(F("- Connected to: "));
Serial.println(ssid);
Serial.print(F("- IP address: "));
Serial.println(WiFi.localIP());
//Add OLED
// display a line of text
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(14,10); //01,50 vk3pe
display.print("IP Adr: ");
display.display();
//display.setCursor(01,20);
display.print (WiFi.localIP());
display.display();
delay(2000); //temp
}
void Erase_text2(){
// fillRect(x corner, y corner, width, height, color)
// Draws and fills rectangle from corner x,y with the width and height
// ------------------------------------------------------------------------------------------------
display.fillRect(1, 30, 127,18, BLACK); //,15, bl
display.display ();
}
void Erase_text1(){ //text size 1
// fillRect(x corner, y corner, width, height, color)
// Draws and fills rectangle from corner x,y with the width and height
// ------------------------------------------------------------------------------------------------
display.fillRect(1, 30, 127,18, BLACK);
display.display ();
}
//**************************************[ SETUP FUNCTION ]*************************************************
void setup()
{
//OLED
// initialize and clear display
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();
// display a line of text
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(01,01);
display.print("ESP8266_WSPR");
display.display();
//added callsign at bottom //vk3pe
//display.setTextColor(WHITE);
display.setCursor(21,55);
display.print(" PD8GB");
display.display();
// Use the ESP8266 LED as a keying indicator.
pinMode(TX_LED_PIN, OUTPUT);
digitalWrite(TX_LED_PIN, LOW);
Serial.begin(115200); while (!Serial);
Serial.println(" ");
Serial.println("[ ESP WSPR - ESP8266 + SI5351A WSPR BEACON FW: ESP_WSPR_ver_3_006 ]");
Serial.println("- SERIAL COM setup Done!");
delay(10);
WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect)
WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot
ssidConnect();
// Set time sync provider
setSyncProvider(epochUnixNTP); //set function to call when sync required
// Initialize the Si5351
// Change the 2nd parameter in init if using a ref osc other
// than 25 MHz
Serial.println("- RADIO MODULE SETUP Begins...");
// The crystal load value needs to match in order to have an accurate calibration
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
// Start on target frequency
si5351.set_correction(cal_factor, SI5351_PLL_INPUT_XO);
//si5351.init(SI5351_CRYSTAL_LOAD_8PF, SI5351_REF, CORRECTION);
Serial.println("- RADIO Module initializing...");
//OLED
Erase_text2();
//gpp display.setCursor(5,30);
display.setCursor(5,30);
display.print("Module initialize");
display.display();
// Set CLK0 output
si5351.set_freq(freq * 100, SI5351_CLK0);
si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power
si5351.set_clock_pwr(SI5351_CLK0, 0); // Disable the clock initially
Serial.println("- Radio Module setup successful...");
Serial.println("- Entering WSPR TX loop...");
digitalWrite(TX_LED_PIN, HIGH);
//OLED
Erase_text2();
display.setCursor(10,30);
display.print("Module is setup.");
display.setCursor(10,40);
display.print("Enter Tx loop.");
display.display();
}
//*****************************************[ LOOP FUNCTION ]******************************************************
void loop()
{
// Trigger every 4 minute
// WSPR should start on the 1st second of the even minute.
// 30 seconds before trigger enable si5351a output to eliminate startup drift
if((minute() + 1) % 4 == 0 && second() == 30 && !warmup)
{ warmup=1; //warm up started, bypass this if for the next 30 seconds
Serial.println("- Radio Module Warm up Started...");
si5351.set_freq(freq * 100, SI5351_CLK0);
si5351.set_clock_pwr(SI5351_CLK0, 1);
//OLED
//clr prev text
Erase_text2();
display.setTextSize(2);
display.display();
display.setCursor(20,33);
display.print("WARM UP !");
display.display();
}
if(minute() % 4 == 0 && second() == 0)
{ //time to start encoding
Serial.print("- Start of Transmission Time:");
Serial.println(now()); //prints on serialport actual time
encode();
warmup=0; //reset variable for next warmup cycle wich will start in 4 minutes and 30 seconds
delay(4000);
//OLED
Erase_text2();
display.setTextSize(1); //text size
display.display();
display.setCursor(5,30);
display.print("Start Tx timing !");
display.display();
// Set time sync provider
setSyncProvider(epochUnixNTP); //set function to call when sync required
}
}
//*************************************[ END OF PROGRAM ]********************************************************