I am pretty new to Arduino programming and this forum and am hoping someone can help...
I have an Arduino Pro Micro (ATmega32U4) running a complex code for a HAM radio satellite antenna rotator. The design of the hardware and code was kindly provided by a HAM club in Australia (THANKS! Check it out here: https://sarcnet.org/projects/project_rotator.html). The Pro Micro receives azimuth and elevation setpoints from an app on a Raspberry Pi over the USB serial port. The Pro Micro uses an azimuth and elevation sensor (LSM303DLHC) to know its position and uses two servo motors to turn the antenna toward the setpoint targets. This part all works great!
What I want is to add a TFT display for 4 float variables (actual azimuth & elevation and setpoint azimuth & elevation). I tried dumping the Pro Micro code into an Adafruit Huzzah Feather but then the code does not work. I tried to connect a different TFT display to the Pro Micro but I could not get that to work either, not enough pins. So I need to get the Pro Micro talking to the Huzzah Feather.
The easiest way I think to do this is to use the Huzzah Feather to receive serial data from the Pro Micro over the RX-TX pins and feed this data to the attached TFT display. I actually had some success using the I2C for serial communication but then my sensor (which is also on I2C) did not work. I have tried to send data over Serial1 (RX-TX) without success and tried SoftwareSerial but I get nothing coming in.
My wiring connections are as follows:
Connect Pro Micro RX to Huzzah TX
Connect Pro Micro TX to Huzzah RX
Connect Pro Micro VCC&GND to Huzzah VCC&GND
Connect Huzzah USB to PC, Pro Micro USB not connected after program upload for this testing
Here is the code for the Sender (Arduino Pro Micro) using Serial1:
// For Sending Serial Data over TxRx pins
// For use with Arduino Leonardo
// Variables as declared in Antenna Rotator code, values used just for demo/testing purposes
float az = 120.01; // Antenna azimuth
float el = 45.02; // Antenna elevation
float azSet = 125.03; // Antenna azimuth set point
float elSet = 50.04; // Antenna elevation set point
void setup(){
Serial.begin(9600); // This pipes to the USB serial monitor (later connected to Rasp Pi)
while(!Serial);
Serial1.begin(9600); // This pipes to TX RX pins (connected to Huzzah RX TX pins)
}
void loop(){
char azStr[4]; // 4 character place holder for the az string
char elStr[4]; // 4 character place holder for the el string
char azSetStr[4]; // 4 character place holder for the azSet string
char elSetStr[4]; // 4 character place holder for the elSet string
// The following should output like this " 120, 45, 125, 50/n"
Serial1.print(dtostrf(az, 4, 0, azStr)); // formats a float to a string using 4 characters with nothing after decimal point
Serial1.print(",");
Serial1.print(dtostrf(el, 4, 0, elStr));
Serial1.print(",");
Serial1.print(dtostrf(azSet, 4, 0, azSetStr));
Serial1.print(",");
Serial1.println(dtostrf(elSet, 4, 0, elSetStr));
Serial.print(dtostrf(az, 4, 0, azStr));
Serial.print(",");
Serial.print(dtostrf(el, 4, 0, elStr));
Serial.print(",");
Serial.print(dtostrf(azSet, 4, 0, azSetStr));
Serial.print(",");
Serial.println(dtostrf(elSet, 4, 0, elSetStr));
delay(250);
}
Here is the code for the Receiver (Adafruit Huzzah Feather) using Serial1:
// For Receiving Serial Data over TxRx pins
// For use with Adafruit Huzzah Feather with TFT Display
// Incoming Serial Data will be "az,el,azSet,elSet" and look something like " 120, 45, 125, 50/n"
// Final Serial Monitor output should be integers with no spaces and look like "120,45,125,50"
int az = 0; //Antenna azimuth
int el = 0; //Antenna elevation
int azSet = 0; //Antenna azimuth set point
int elSet = 0; //Antenna elevation set point
String inString = ""; // string to hold input
void setup(){
Serial.begin(9600); //This pipes to the serial monitor (connected to PC)
while(!Serial);
Serial1.begin(9600); // This pipes to TX RX pins (connected to Pro Micro RX TX pins)
// send an intro:
Serial.println("Testing TxRx Serial Data");
Serial.println();
}
void loop(){
// Read serial input:
Serial.println("Checking for Serial1...");
while (Serial1.available() > 0) {
Serial.println("Serial1 is available...");
int inChar = Serial1.read();
if (isDigit(inChar)) {
// convert the incoming byte to a char and add it to the string:
inString += (char)inChar;
}
// if you get a comma, convert the string to integer and increment the counter:
if (inChar == ',') {
if (counter = 1) az = inString.toInt();
if (counter = 2) el = inString.toInt();
if (counter = 3) azSet = inString.toInt();
if (counter = 4) elSet = inString.toInt(); counter = 0;
counter = counter + 1;
// clear the string for new input:
inString = "";
}
// if you get a carriage return then print four integers and wait for next data set
if (inChar == '\n') {
Serial.print(az); Serial.print(",");
Serial.print(el); Serial.print(",");
Serial.print(azSet); Serial.print(",");
Serial.println(elSet);
}
}
delay(250);
}
I will have to make a second post for the code using SoftwareSerial (too long otherwise)