Hello all,
I have recently followed this tutorial HERE to transmit data between two arduinos via 433 MHz modules.
The big picture idea is to sync two variables if one of them changes. So I am able to send data from the Tx to the Rx with no issue, as long as the value of the variable is 1000 or greater. When I send, say 1 or 100, I get the “*” operator displayed on the serial monitor. I am assuming this is because I am expecting a buffer size of 4 on the Rx, but am only sending a value that is 1 or 3 (value of 1 or 100 respectively).
Any idea on how to clear this up? Essentially I want to receive a value of 1 when I send a value of 1, not 1**8. Below are my codes for the Tx and Rx arduinos.
Tx Arduino
int red_score = 0;
int blue_score = 0;
String blue_scoreSTR;
String red_scoreSTR;
String ScoreSTR;
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup()
{
// Initialize ASK Object
rf_driver.init();
Serial.begin(9600);
blue_score = 0;
red_score = 2;
}
void loop()
{
// blue_scoreSTR = String(blue_score);
// red_scoreSTR = String(red_score);
ScoreSTR = String(blue_score + red_score);
static char *msg = ScoreSTR.c_str();
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
Serial.println("Data Sent");
//red_score++;
delay(1000);
}
Now the Rx arduino
String blue_scoreSTR;
int score = 0;
String ScoreSTR;
int ii =0;
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
Serial.println("listening..");
}
void loop()
{
// Set buffer to size of expected message
uint8_t buf[4];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
{
// Message received with valid checksum
Serial.print("Message Received: ");
Serial.println((char*)buf);
ScoreSTR = String((char*)buf);
score = atoi(ScoreSTR.c_str());
Serial.println(ScoreSTR);
Serial.println(score);
for (ii=0;ii<=5;ii++){//just to play with the received value
score = score + ii;
Serial.println(score);
}
}
}
On a fresh upload, I receive this in the serial monitor:
Message Received: 2**8
2**8
2
2
3
5
8
12
17
Now, if I make the Tx code send a value of 2000 (blue_score = 2000, red_score = 0), I get this:
Message Received: 2000
2000
2000
2000
2001
2003
2006
2010
2015
Any help is greatly appreciated.