Devices & Components
Arduino Nano
Project description
Code
Aerial Switch Controller Software
c_cpp
Code is designed to toggle up and down between pages of text on LCD screen, and generate a 3bit BCD output for the page selected and store the selected page to EEPROM. Thus after power down, on the next reboot the system will restart with the last setting. Using port connections to an Arduino NANO as per the schematic this code can be used to drive a remote BCD decoder for selecting remote RF relays. LCD displays antenna selected with 16 characters available for description. First line of display can be used for station callsign and Maidenhead locator. System settings are only saved to eeprom when changing the antenna selection thus write cycles are kept to a minimum and not for each program loop. A test for eeprom value is included at the end of the program loop to ensure the returned value is within the scope of this program.
1//Antenna switch control software Issue-1 2//description, antenna relay switch controller with LCD display display using 3 wire [binary] control to switch up to 6 remote RF relays. Requires ATmega328P-PU (Arduino Nano), 1x SPDT toggle switch [mom-off-mom] and either I2C 16x2 or 20x4 LCD module 3//display information and relay switch driver(s) are stored in EEPROM and recalled on power rebootA 4//Added test for EEPROM corruption, code lines 203 204.. 5//David Allen G8LHD © 22nd June 2021 6 7#include <EEPROM.h> 8#include <Wire.h> 9#include <LiquidCrystal_I2C.h> //library installation required from GitHub 10 11// * Download LiquidCrystal_I2C zipped library from GitHub https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library 12// * install in Arduino > libraries > new folder "LiquidCrystal_I2C" 13// * After placing in folder run Arduino IDE software, Sketch > Include Library > Add.ZIP Library... 14// * May be necessary to reboot Arduino IDE software after library installation 15// * Change text strings in following lines of code to your own preferences 16// * Line56, declare lcd type, 16 x 2 line default or 20 character x 4 line alternative. 17// * Line80, add station call sign 18// * Line131; add antenna description, NOTE fill LCD text string statement with spaces to stop LCD overlap of text string. 19// * Line142; add antenna description 20// * Line152; add antenna description 21// * Line162; add antenna description 22// * Line172; add antenna description 23// * Line182; add antenna description 24// * code lines 91 "if(page_counter <7)" and code line 110 "page_counter= 7;" the number used reflects the highest page number if not using all antenna ports, binary address '110' is used on last page, all relays off. 25 26 27//-------Pins-----// 28int up = 2; //Up button, digital pin2, PD2 ATmega328P 28pin dip = pin4, normally open = LOW, closed = HIGH 29int down = 3; //Down button, digital pin3, PD3 ATmega328P 28pin dip = pin5, normally open = LOW, closed = HIGH 30int outputA0 = 14; //A0, digital pin14, ATmega328P 28pin dip = pin23 31int outputA1 = 15; //A1, digital pin15, ATmega328P 28pin dip = pin24 32int outputA2 = 16; //A2, digital pin16, ATmega328P 28pin dip = pin25 33 34//----variable to move between pages----// 35int page_counter; 36 37//---------Storage debounce function-----// 38bool current_up = LOW; 39bool last_up=LOW; 40bool last_down = LOW; 41bool current_down = LOW; 42 43void setup() { 44 45checkpagecounterState(); //----Check last EEPROM stored page count----// 46 47pinMode(up,INPUT); //initialize digital pin PD2 as an input. 48pinMode(down,INPUT); //initialize digital pin PD3 as an input. 49pinMode(outputA0,OUTPUT); //initialize analogue pin A0 as an output. 50pinMode(outputA1,OUTPUT); //initialize analogue pin A1 as an output. 51pinMode(outputA2,OUTPUT); //initialize analogue pin A2 as an output. 52 53//----Check 0x27 is correct I2C address for LCD display----// 54 55LiquidCrystal_I2C lcd(0x27, 16, 2); // LiquidCrystal_I2C lcd(0x27, 20, 4); // use with 4 line LCD display 56lcd.init(); // Initialize the LCD 57lcd.backlight(); // turn on backlight 58lcd.clear(); // clear display 59} 60 61//----De-bouncing function for all buttons----// 62boolean debounce(boolean last, int pin) 63{ 64boolean current = digitalRead(pin); 65if (last != current) 66{ 67delay(40); //----40ms delay for debounce----// 68current = digitalRead(pin); 69} 70return current; 71} 72 73void loop() { 74 75 76LiquidCrystal_I2C lcd(0x27, 20, 4); //this is required inside loop for lcd.functions to work 77 lcd.backlight(); 78 lcd.setCursor(0,0); //----indent one charachter, line 0----// 79 lcd.print("Gxxxx Loc xxxxxx"); //write station callsign and Maidenhead grid square locator on first line of LCD display 80// lcd.print("1234567812345678"); Character number guide for 16 x 2 LCD display 81current_up = debounce(last_up, up); //Debounce for Up button 82current_down = debounce(last_down, down); //Debounce for Down button 83 84//----Page counter function to move between pages----// 85//----change code lines 91 "if(page_counter <7)" and code line 110 "page_counter= 7;" replace 7 with highest number of pages----// 86 87//Page Up 88 if (last_up== LOW && current_up == HIGH){ 89 lcd.clear(); //When page is changed, lcd clear to print new page 90 if(page_counter <7){ //Page counter never higher than 7(total of pages) 91 page_counter= page_counter +1; //Page up 92 93 } 94 else{ 95 page_counter= 1; //return to page 1 96 } 97 } 98 99 last_up = current_up; 100 101//Page Down 102 if (last_down== LOW && current_down == HIGH){ 103 lcd.clear(); //When page is changed, lcd clear to print new page 104 if(page_counter >1){ //Page counter never lower than 1 (total of pages) 105 page_counter= page_counter -1; //Page down 106 107 } 108 else{ 109 page_counter= 7; //----return to page 7----// 110 } 111 } 112 113 last_down = current_down; 114 115 116EEPROM.update(0, page_counter); //----write to ATmega328 EEPROM adress 0, page_counter variable (1-7)----// 117 118 119 120 121//----Aerial Switch function----// 122 123 switch (page_counter) { 124 125 case 1:{ //Design of home page 1 126 digitalWrite(outputA0,LOW); //----antenna port address 000, A0 least significant bit----// 127 digitalWrite(outputA1,LOW); 128 digitalWrite(outputA2,LOW); 129 lcd.setCursor(0,1); 130 lcd.print("A 6m/2m/70c Vert"); 131// lcd.print("1234567812345678"); Character number guide for 16 x 2 LCD display 132 } 133 break; 134 135 136 case 2: { //Design of page 2 137 digitalWrite(outputA0,HIGH); //----antenna port address 001, A0 least significant bit----// 138 digitalWrite(outputA1,LOW); 139 digitalWrite(outputA2,LOW); 140 lcd.setCursor(0,1); //indent one charachter, print on line 1 141 lcd.print("B 144MHz 2m Horz"); 142// lcd.print("1234567812345678"); 143 } 144 break; 145 146 case 3: { //Design of page 3 147 digitalWrite(outputA0,LOW); //----antenna port address 010, A0 least significant bit----// 148 digitalWrite(outputA1,HIGH); 149 digitalWrite(outputA2,LOW); 150 lcd.setCursor(0,1); 151 lcd.print("C 50MHz 6m Horz "); 152// lcd.print("1234567812345678"); 153 } 154 break; 155 156 case 4: { //Design of page 4 157 digitalWrite(outputA0,HIGH); //----antenna port address 011, A0 least significant bit----// 158 digitalWrite(outputA1,HIGH); 159 digitalWrite(outputA2,LOW); 160 lcd.setCursor(0,1); 161 lcd.print(" "); 162// lcd.print("1234567812345678"); 163 } 164 break; 165 166 case 5: { //Design of page 5 167 digitalWrite(outputA0,LOW); //----antenna port address 100, A0 least significant bit----// 168 digitalWrite(outputA1,LOW); 169 digitalWrite(outputA2,HIGH); 170 lcd.setCursor(0,1); 171 lcd.print(" "); 172// lcd.print("1234567812345678"); 173 } 174 break; 175 176 case 6: { //Design of page 6 177 digitalWrite(outputA0,HIGH); //----antenna port address 101, A0 least significant bit----// 178 digitalWrite(outputA1,LOW); 179 digitalWrite(outputA2,HIGH); 180 lcd.setCursor(0,1); 181 lcd.print(" "); 182// lcd.print("1234567812345678"); 183 } 184 break; 185 186 case 7: { //Design of page 7 187 digitalWrite(outputA0,LOW); //----unused antenna port address 110, A0 least significant bit, all relays off.----// 188 digitalWrite(outputA1,HIGH); 189 digitalWrite(outputA2,HIGH); 190 lcd.setCursor(0,1); 191 lcd.print("All relays off "); 192// lcd.print("1234567812345678"); 193 } 194 break; 195 196 }//switch end 197 198}//1st loop end 199 200void checkpagecounterState() //----program loop for reading EEPROM adress 0 pagecounter last stored value----// 201{ 202 page_counter = EEPROM.read(0); 203if (page_counter <1)return 1; //if eeprom value becomes corrupted returns a page_counter value of page 1 204if (page_counter >7) return 1; 205 206}//2nd loop end 207 208 209 210 211//end
Downloadable files
Aerial Switch Controller
Connections to Nano board and output line driver details
Aerial Switch Controller

BCD decoder - relay driver
Decodes BCD to drive individual relays with high current drive outputs.
BCD decoder - relay driver

BCD decoder - relay driver
Decodes BCD to drive individual relays with high current drive outputs.
BCD decoder - relay driver

Aerial Switch Controller
Connections to Nano board and output line driver details
Aerial Switch Controller

Comments
Only logged in users can leave comments