hl2-interface/hl2-interface.ino

128 lines
4.5 KiB
Arduino
Raw Permalink Normal View History

2023-05-08 22:49:04 +00:00
//***************************************************************************************
2023-05-16 12:23:16 +00:00
//* Hermes Lite 2 Interface Box *
2023-05-08 22:49:04 +00:00
//* *
2023-05-16 12:23:16 +00:00
//* Reads I2C data from the Hermes Lite 2 and a) controls an antenna switch based *
//* on the selected band and b) sets the correct LPF of the Hardrock 50 Power Amp *
//* *
//* Based on HL2-PA70 by Cesc Gudayol (EA3IGT) Version 3.0.1 from 01/04/2021 *
2023-05-17 05:34:45 +00:00
//* More info: https://github.com/ea3igt/HL2-PA70 *
2023-05-16 12:23:16 +00:00
//* *
//* Adapted by Michael Clemens (DK1MI) *
2023-05-17 05:34:45 +00:00
//* More info: https://dk1mi.radio/hl2-hr50-interface *
2023-05-08 22:49:04 +00:00
//* *
//***************************************************************************************
//* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND *
//***************************************************************************************
//
// Pin Configuration:
// - PIN A04 INPUT: SDA for I2C Slave (Hermes Lite 2 Control bus)
// - PIN A05 INPUT: SCL for I2C Slave (Hermes Lite 2 Control bus)
2023-05-16 12:23:16 +00:00
// - PIN D10 OUTPUT: Antenna Switch
2023-05-08 22:49:04 +00:00
#include <Wire.h> //For I2C control
#include <EEPROM.h> //To store values from PA70-Controller
#include <util/delay.h> //Library to delay inside one Interrupt
//#define TEST //Uncomment if Testing (Serial Monitor traces)
// Declaration for the Hermes Lites v2 I2C (Listen to Adress 0x20)
// HW SDA pin A4
// HW SCL pin A5
2023-05-16 12:23:16 +00:00
#define Antenna 10 //Pin D10
2023-05-08 22:49:04 +00:00
// Other Configurations
byte previousI2CBand; //to store previously I2C Band decoded
int selected_antenna = 0;
// SetUp function initializations
void setup() {
Serial.begin(9600);
// I2C Slave Setup
Wire.begin(0x20); // join i2c bus with address to listen
Wire.onReceive(receiveEvent); // register event
// Antenna
pinMode(Antenna, OUTPUT);
delay(200);
//Get stored Band from EEPROM for initial filter selection
previousI2CBand=EEPROM.read(1); //Read I2C byte Band from EEPROM byte 1
decodeBand(previousI2CBand);
2023-05-08 21:54:52 +00:00
}
2023-05-08 22:49:04 +00:00
// Main loop program
void loop()
2023-05-08 21:54:52 +00:00
{
2023-05-16 12:23:16 +00:00
// do nothing
2023-05-08 22:48:28 +00:00
}
2023-05-08 21:54:52 +00:00
2023-05-08 22:49:04 +00:00
void receiveEvent(int howMany) { //Triggered when receive I2C information from HL2
byte c[10];
int i= 0;
while (0 < Wire.available()) { // loop through all but the last
c[i] = Wire.read(); // receive byte as a character
i++;
}
2023-05-08 21:54:52 +00:00
2023-05-08 22:49:04 +00:00
#ifdef TEST
Serial.print(F("I2C BUS DATA:"));
Serial.println(c[1]); // write to usb monitor
#endif
2023-05-08 22:48:28 +00:00
2023-05-08 22:49:04 +00:00
byte myC=c[1] & B00111111; //Get 6 least significative bits
2023-05-08 22:48:28 +00:00
2023-05-16 12:23:16 +00:00
decodeBand(myC); //Decode Band
2023-05-08 22:48:28 +00:00
2023-05-08 22:49:04 +00:00
// toggle Antenna
digitalWrite(Antenna,selected_antenna);
//Store Last Selected Band into EEPROM
2023-05-16 12:23:16 +00:00
EEPROM.write(1,myC); //Byte 1 for I2C decoded
2023-05-08 22:49:04 +00:00
#ifdef TEST
// write to usb monitor
Serial.print(F("LPF BAND CONTROL (Binary):"));
Serial.println(selectedBand);
Serial.print(F("PTT CONTROL:"));
Serial.println(PTTStatus);
#endif
}
2023-05-08 22:48:28 +00:00
2023-05-08 22:49:04 +00:00
//Function to decode HL2 band and select/map the filter
//**************** Change accordingly *****************
void decodeBand(byte c)
{
switch (c) {
case 0x1: //160m
selected_antenna = 0;
2023-05-16 12:23:16 +00:00
Serial.println("HRBN10;"); // sets the Hardrock-50 to 160m
2023-05-08 22:49:04 +00:00
break;
case 0x2: //80m
selected_antenna = 0;
2023-05-16 12:23:16 +00:00
Serial.println("HRBN9;"); // sets the Hardrock-50 to 80m
2023-05-08 22:49:04 +00:00
break;
case 0x4: //60m & 40m
selected_antenna = 0;
2023-05-16 12:23:16 +00:00
Serial.println("HRBN7;"); // sets the Hardrock-50 to 40m
2023-05-08 22:49:04 +00:00
break;
case 0x8: //30m & 20m
selected_antenna = 1;
2023-05-16 12:23:16 +00:00
Serial.println("HRBN5;"); // sets the Hardrock-50 to 20m
2023-05-08 22:49:04 +00:00
break;
case 0x10: //17m & 15m
selected_antenna = 1;
2023-05-16 12:23:16 +00:00
Serial.println("HRBN3;"); // sets the Hardrock-50 to 15m
2023-05-08 22:49:04 +00:00
break;
case 0x20: //12m & 10m
selected_antenna = 1;
2023-05-16 12:23:16 +00:00
Serial.println("HRBN1;"); // sets the Hardrock-50 to 10m
2023-05-18 06:56:19 +00:00
break;
2023-05-08 22:49:04 +00:00
}
2023-05-16 12:23:16 +00:00
}