Here is the code for my latest Arduino based digital display for my old Yaesu FT-401b. It will work on a few of the old Yaesus including the Ft101 with very minor code tweaking. This one uses the Nextion 4.3 inch TFT touch display that communicates with the Arduino serially. This code is for the UNO but should work with other Arduinos.
Marty
N5KBP

/* Program to emulate a Yaesu YC-601 digital display for the old Yaesu FT401B
* Transceiver. It takes the output of the VFO. Counts it then manipulates the
* numbers to show the output on a Nextion 4.3 inch TFT touch display.
* It takes a little outside hardware. You have to condition the input
* to a square wave. I use a 74hc4046 to do that then the frequency must be diveded
* by 2 to get the 9 mhz output that the Yaesu outputs down to a frequency the Arduino
* Uno can handle. That is done with a 74hct4040 shift register. All the info on this can
* be found with a little help from Google.
* My experience is in Visual Basic. This is my first attmept at C so
* It is not as structured as I would like and is probably a memory hog. But it works.
* Thanks to all the library writers, code sharers and circuit sharers.
* I have thourally enjoyed this project and like most programs it will
* suffer from feature bloat eventually. :^)
* Code is release under the GNU GPL license
* Marty Duplissey
* N5KBP
*/
#include <FreqCount.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void print2txt(long count, int tenstrue);
void print2mode(int mode);
void print2res(int resolution);
int nextbuttonpressed(void);
struct config
{
byte initflag;
int displaytens;
byte lastmode ;
byte lastband ;
unsigned long bandoffset[11];
};
config configdata;
int mode ; // 0 = LSB, 1 = USB, 2 = CW/Tune 3 = AM
int currentband ;
long oldcount;
long count;
unsigned long lastsaved;
boolean configchanged;
int modeoffset[] = {150,-150,-70,0}; // LSB,USB,CW,AM
int buttons;
unsigned long buttonpressed;
int calamount = 1; // amount to change with calibrate buttons
void setup() {
EEPROM.get(0,configdata);
if (configdata.initflag != B10101011)
{
configdata.initflag = B10101011;
configdata.displaytens = true;
configdata.lastmode = 0;
configdata.lastband = 0;
configdata.bandoffset[0] = 1270000; // 80M
configdata.bandoffset[1] = 1620000; // 40M
configdata.bandoffset[2] = 2320000; // 20M
configdata.bandoffset[3] = 3020000; // 15M
configdata.bandoffset[4] = 3720000; // 10A
configdata.bandoffset[5] = 3770000; // 10B
configdata.bandoffset[6] = 3820000; // 10C
configdata.bandoffset[7] = 3870000; // 10D
configdata.bandoffset[8] = 1920000; // WWV 10 MHZ
configdata.bandoffset[9] = 3620000; // 11M
configdata.bandoffset[10] = 0;// change to 1070000 for 160m on FT101
EEPROM.put (0,configdata);
};
lastsaved = millis()+ 30000;
configchanged = false;
Serial.begin(57600);// for debugging
mySerial.begin(57600);
FreqCount.begin(100); // Gate time 1/10 th of a second
mode = configdata.lastmode;
if (configdata.displaytens == false) calamount = 10;
currentband = configdata.lastband;
print2res(configdata.displaytens);
print2mode(mode);
}
void loop() {
if (FreqCount.available()){
count = FreqCount.read();
//count = 447500; //debug code comment out for real use
count = count * 2; // compensate for the / 2 before
// counting done in hardware because of the
// limitations of the ardiuno
// count = configdata.bandoffset[currentband]- count; //Use instead of following
// line if using with FT101
if (currentband != 10) count = configdata.bandoffset[currentband]- count;
count = count + modeoffset[mode];
if (oldcount != count){
print2txt(count, configdata.displaytens) ;
oldcount = count;
}
}
if (lastsaved <= millis()){
lastsaved = millis()+ 30000;
if (configchanged = true) {
EEPROM.put (0,configdata);
configchanged = false;
}
}
buttons = nextbuttonpressed();
if (buttons != 0){
switch (buttons) {
case 50:// mode button
if (buttonpressed >= millis())break;
if (mode < 3)
{
mode = mode + 1;
}
else
{
mode = 0;
}
configdata.lastmode = mode;
buttonpressed = millis()+400;
print2mode(mode);
configchanged = true;
break;
case 60:// switch between 10s digit showing
if (buttonpressed >= millis())break;
if (configdata.displaytens == true){
configdata.displaytens = false;
calamount = 10;
}
else {
configdata.displaytens = true;
calamount = 1;
}
buttonpressed = millis()+400;
print2res(configdata.displaytens);
configchanged = true;
break;
case 10: // Band up button
if (buttonpressed >= millis())break;
if (currentband < 10)
{
currentband = currentband + 1;
}
else
{
currentband = 0;
}
configdata.lastband = currentband;
buttonpressed = millis()+400;
buttons = 0;
configchanged = true;
break;
case 20: //Band down button
if (buttonpressed >= millis())break;
if (currentband > 0)
{
currentband = currentband - 1;
}
else
{
currentband = 10;
}
configdata.lastband = currentband;
buttonpressed = millis()+400;
buttons = 0;
configchanged = true;
break;
case 30:// Calibrate up button
if (buttonpressed >= millis())break;
configdata.bandoffset[currentband] = configdata.bandoffset[currentband] + calamount;
buttonpressed = millis()+150;
configchanged = true;
buttons = 0;
break;
case 40:// Calibrate down button
if (buttonpressed >= millis())break;
configdata.bandoffset[currentband] = configdata.bandoffset[currentband] - calamount;
buttonpressed = millis()+150;
configchanged = true;
buttons = 0;
break;
}
}
}
int nextbuttonpressed(void){
static int keypress;
int returnbutton;
if (mySerial.available() > 0) {
static String buttonbuffer;
int thisChar = mySerial.read();
buttonbuffer += String(thisChar,HEX);
if (buttonbuffer.substring(buttonbuffer.length()-6) == "ffffff") {
char Button = buttonbuffer.charAt(3);
char Buttondnorup = buttonbuffer.charAt(4);
char nullstring = '\0';
buttonbuffer = nullstring;
switch(Button){
case '9': // Band up
if (Buttondnorup == '1')
{returnbutton = 10;}
else
{returnbutton = 11;}
break;
case 'a': // Band dwnp
if (Buttondnorup == '1')
{returnbutton = 20;}
else
{returnbutton = 21;}
break;
case 'b': // Cal up
if (Buttondnorup == '1')
{returnbutton = 30;}
else
{returnbutton = 31;}
break;
case 'c': // Cal dn
if (Buttondnorup == '1')
{returnbutton = 40;}
else
{returnbutton = 41;}
break;
case '4': // Mode
returnbutton = 50;
break;
case '7': // 10 hz
returnbutton = 60;
break;
default:
returnbutton = 0;
}
}
}
if (keypress){int i=0;}// a small delay to let nextion settle down.
// Just works better with it.
if (keypress / 10 >= 5) {keypress = 0;} // if 50 or 60 do not support holding button down
if (returnbutton){keypress = returnbutton;}
if (keypress % 10 == 1) {keypress = 0;} // if key release event stop button hold won
return keypress;
}
void print2res(int tenstrue){
String res;
if (tenstrue) {
res = String("10HZ");
}
else {
res = String("100HZ");
}
mySerial.print("b1.txt=");
mySerial.write(0x22);
mySerial.print(res);
mySerial.write(0x22);
mySerial.write(0xff);
mySerial.write(0xff);
mySerial.write(0xff);
}
void print2mode(int mode){
String butnlbl;
switch(mode){
case 0: //LSB
butnlbl = String("LSB");
break;
case 1: //USB
butnlbl = String("USB");
break;
case 2: //CW/TUNE
butnlbl = String("CW");
break;
case 3: //AM
butnlbl = String("AM");
break;
}
mySerial.print("b0.txt=");
mySerial.write(0x22);
mySerial.print(butnlbl);
mySerial.write(0x22);
mySerial.write(0xff);
mySerial.write(0xff);
mySerial.write(0xff);
}
void print2txt(long count, int tenstrue){
char countstr[15];
sprintf(countstr,"%lu",count);
int lenfreq = strlen(countstr);
char newcountstr[15];
if (lenfreq == 6){
newcountstr[0]= countstr[0];
newcountstr[1]= '.';
newcountstr[2]= countstr[1];
newcountstr[3]= countstr[2];
newcountstr[4]= countstr[3];
newcountstr[5]= '.';
newcountstr[6]= countstr[4];
if (tenstrue) {
newcountstr[7]= countstr[5];
newcountstr[8]= '\0';
}
else {
newcountstr[7]= '\0';
}
}
if (lenfreq == 7){
newcountstr[0]= countstr[0];
newcountstr[1]= countstr[1];
newcountstr[2]= '.';
newcountstr[3]= countstr[2];
newcountstr[4]= countstr[3];
newcountstr[5]= countstr[4];
newcountstr[6]= '.';
newcountstr[7]= countstr[5];
if (tenstrue) {
newcountstr[8]= countstr[6];
newcountstr[9]= '\0';
}
else {
newcountstr[8]= '\0';
}
}
mySerial.print("t3.txt=");
mySerial.write(0x22);
mySerial.print(newcountstr);
mySerial.write(0x22);
mySerial.write(0xff);
mySerial.write(0xff);
mySerial.write(0xff);
}