The setup:
I have 2 Bluno Beetles connected via bluetooth to each other. One is connected to an LCD, 2 temp sensors, and buttons and is the Master and is sending 4 variables to the other Bluno Beetle. The Slave Bluno Beetle is taking the incoming serial data from the Master and displaying it to the serial monitor.
Problem:
The data only shows up as ASCII characters. I need integer values so that the slave can make changes depending on the values. Changes will be made in future versions and for now I just need integer variables to work with. Essentially the variables are 2 temperature setpoints and 2 temperature readings. So they will all change over time depending on the user preferences.
Slave Code that essentially is just a copy from the Serial Input Basics page found here: Serial Input Basics - updated - Introductory Tutorials - Arduino Forum
// Example 3 - Receive with start- and end-markers
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
void setup() {
Serial.begin(115200);
Serial.println("<Arduino is ready>");
}
void loop() {
recvWithStartEndMarkers();
showNewData();
delay(1000);
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
Master Code...this isn't all of the master code. Just the part that is sending the data.
if (Serial.available())
{
Serial.write('<');
Serial.write(heat_setpointF);
Serial.write(',');
Serial.write(cold_setpointF);
Serial.write(',');
Serial.write(tank_temp22);
Serial.write(',');
Serial.write(cold_combined22);
Serial.write('>');
delay(10);
}
What I see on the Slave Bluno Beetle serial Monitor:
10:47:57.854 -> This just in ... ⸮,N,Q,Q
It should be 200,78,81,81 but all I get is ASCII characters.
I tried to modify example 5 from the Serial Input Basics page but it would only display the string value and no integers.
Any help would be greatly appreciated. FYI I am still fairly new to programming and especially working with serial/ASCII data.