Hi All,
I have a project that I am working on at present that involves wireless serial communication using a cloned 3DR 915MHz radio set. I am experiencing a few issues with it and was hoping for some input from the community if possible.
The Setup:
Transmitter (Mobile station) - I have an old school joystick/pan that I am mapping the pots of with three analog pins of an Arduino Leonardo. I also have a 3DR radio air module connected to the Leonardo.
Receiver (Ground Station) - I have an Arduino Uno connected to a 3DR radio air module that receives the data transmitted by the Ground Station.
A link to the actual radio set.
The Goal:
The three pots from the joystick simulate roll, pitch and yaw. I map these pots and write the values to an array. I then send the data wirelessly to the Ground Station and store that in an array ready for processing by the rest of the sketch.
The Code:
Mobile Station (Leonardo):
#include <Wire.h>
int RPYPin[3]; // Array to store connection pins
float arrRPY[3]; // Array to store roll, pitch & yaw values
void setup()
{
// Defining analog pins
RPYPin[0] = 0;
RPYPin[1] = 1;
RPYPin[2] = 2;
// Opening up serial port
Serial1.begin(57600);
// Delay to open serial window manually
delay(5000);
}
void loop() {
// Roll pin mapping
arrRPY[0] = analogRead(RPYPin[0]);
arrRPY[0] = map(arrRPY[0], 0, 1023, -10.00, 10.00);
// Pitch pin mapping
arrRPY[1] = analogRead(RPYPin[1]);
arrRPY[1] = map(arrRPY[1], 0, 1023, -10.00, 10.00);
// Yaw pin mapping
arrRPY[2] = analogRead(RPYPin[2]);
arrRPY[2] = map(arrRPY[2], 0, 1023, -10.00, 10.00);
// Print data serially (Wireless)
Serial1.print("<");
Serial1.print(arrRPY[0]);
Serial1.print("|");
Serial1.print(arrRPY[1]);
Serial1.print("|");
Serial1.print(arrRPY[2]);
// Print data serially (USB port)
Serial.print("<");
Serial.print(arrRPY[0]);
Serial.print("|");
Serial.print(arrRPY[1]);
Serial.print("|");
Serial.println(arrRPY[2]);
}
Ground Station (UNO)
float arrRPY[3];
void getRPY() { // Get roll, pitch & yaw function
byte byteRead; // Read first byte of the incoming transmission
boolean startByte = false; // Boolean opperator
while (Serial.available() > 0) { // While there is serial data being trasmitted
byteRead = Serial.read(); // Read first byte received
Serial.println(byteRead); // Visual check for myself to see what it is
while (byteRead >= 60 || byteRead <= 60) { // 60 is ASCII code for <, which is my identifier
byteRead = Serial.read(); // read next byte until it is 60 (<)
Serial.println(byteRead); // Visual check for myself
}
if (byteRead == 60) { // If 60 (<) is detected
startByte = true; // Change boolean operator value
if (startByte = true) { // If startByte is detected use Serial.parseFloat() to detect the next floating
arrRPY[0] = Serial.parseFloat(); //point value in the serial communication and write the floating
arrRPY[1] = Serial.parseFloat(); // point value to the storage array.
arrRPY[2] = Serial.parseFloat();
}
}
Serial.print(arrRPY[0]); Serial.print(" | "); Serial.print(arrRPY[1]); Serial.print(" | "); Serial.println(arrRPY[2]); // Visual check to see what has been written to the array.
}
My Findings
I have two air modules (No USB connector) and one ground station module (USB connector). If I run the joystick module independently from the computer with its own power and I use the ground station module in my computer and I open up the serial terminal with the correct baud rates I get flawless results. I can see the values being stored in the array change as I move the joy stick. The same result when I use the second air module with a FTDI/TTL tool. So this tells me that the radios are paired correctly.
Now, when I bring the Ground Station into the mix is when things go wrong. The two air module pair well and I can see that they are communicating because the communication LED's are flashing. From what I can see, I have the data being written into the storage array but it is not being constisent, see attached a screen shot of the serial terminal output. When it does write data to the array, it is in the correct form, ie. 0.00 | 0.00 | 0.00. But if I move the joystick it remains this, thus I am losing something somewhere.
Mobile Station serial terminal screen grab:
So this is what is being transmitted. Notice the changing values due to moving the joystick.
Ground Station serial terminal screen grab:
This is evidently what is being written to the array and then it stops. Notice that the ASCII values after the initial 0.00 | 0.00 | 0.00 coincide with what I am listening for, but somehow it is getting a bit confused! Also, the initial values should coincide with the first screen grab, but they don't.
And then another screen grab from the serial terminal from the Ground Station:
This is with a two second delay to the Mobile Station sketch, so the 255/null character makes sense, but as for the rest... Can't figure it out!
My Suspicions:
I have a feeling that the two culprits are either my receiving loop or that the transmission is simply too fast. Having said that, if I put a two second delay on the joystick reading sketch and I still don't get values that are changing as I move the joystick. Or could it be my general approach to wireless serial transmission?
Any help or assistance would be much appreciated and if you have any questions, please don't hesitate to ask.
Thanks everyone,
Dylan