433MHz comms

Hi, I have hit a brick wall trying to send 2 variable numbers from one uno to another uno via a cheap and basic 433MHz set.
My application is reading 2 single axis joysticks and sending the raw data scaled from 0-1023 to 0-255 and then sending those numbers to the receiving uno where they can be rescaled to 0-1023 before I do the other programming steps. I have no problems with any of the other parts of the sketch except the radio comms. I’m getting 0 on the serial monitor of the receiving uno.
I’ve tried the “hello world” sketch to test the comms modules and that works fine. but when I try to progress to the next step of comms I’m getting nowhere.
I’ve pasted a copy of my sketches below. (I know it says sensors but this sketch seemed the most promising thing that I could find, I’m just looking at the numbers to see if they send, everything else I’ve tried failed )
If anyone can help, I would be deeply obliged.

Many thanks

Bill

/*.............................................................
Sending Multiple Variables Using VirtualWire. Transmitter
Author: Rodrigo Mompo Redoli
For controlrobotics.rodrigomompo.com
//Modified by Bill McLean sept 10 2020 for Radiohead using ASK library with 433MHz tx & rx set
//Adapted to send 2 single axis joystick values from Transmitting Arduino Uno to receiving Arduino Uno
//..............................................................*/


#include <RH_ASK.h>
#include <SPI.h>


int Sensor1Pin = A0;// The pins were sensor are attached
int Sensor2Pin = A1;
int dt=200;
RH_ASK rf_driver; 
int ledPin = 13;
int Sensor1Data;// The variable were the data from each sensor
int Sensor2Data;// will be stored 

char Sensor1CharMsg[22];// The string that we are going to send through rf 

void setup() {

 // LED 
 pinMode(ledPin,OUTPUT);
 
 // Sensor(s)
 pinMode(Sensor1Pin,INPUT);
 pinMode(Sensor2Pin,INPUT);
  rf_driver.init();
Serial.begin(9600);
// Rx pin. Default is 11


}

void loop() {
  
  // Read and store Sensor Data
  Sensor1Data = analogRead(Sensor1Pin);
Sensor1Data= map(Sensor1Data, 0, 1023, 0, 255);
  Sensor2Data = analogRead(Sensor2Pin);
Sensor2Data= map(Sensor2Data, 0, 1023, 0, 255);  
   
  sprintf(Sensor1CharMsg, "%d,%d,", Sensor1Data, Sensor2Data);
 
 // Turn on a light to show transmitting
 rf_driver.send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
rf_driver.waitPacketSent(); // Wait until the whole message is gone
 // Turn off a light after transmission
 delay(40);
Serial.print("Sensor1Data= ");
Serial.print(Sensor1Data);
Serial.print(" Sensor2Data= ");
Serial.println(Sensor2Data);
}

}

//This is the receiver code

//*.............................................................
//Sending Multiple Variables Using VirtualWire(Now radiohead). 
//Author: Rodrigo Mompo Redoli
//For controlrobotics.rodrigomompo.com
//Modified by Bill McLean sept 10 2020 for Radiohead using ASK library with 433MHz tx & rx set
//Adapted to send 2 joystick values from Transmitting Arduino Uno to receiving Arduino Uno
//..............................................................*/

#include <RH_ASK.h>

#include <SPI.h>

RH_ASK rf_driver;
// Sensors 
int Sensor1Data;
int Sensor2Data;
char StringReceived[22]; 
 
 
 
void setup() {
 
rf_driver.init(); 
    // Bits per sec
Serial.begin(9600);
  //  rx_pin(11);   
} // END void setup
 
void loop(){
    uint8_t buf[22];
    uint8_t buflen = sizeof (buf);
     
//Taking the data from the control base
    if (rf_driver.recv(buf, &buflen)) 
    {
 int i;
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
 {            
        // Fill Sensor1CharMsg Char array with corresponding 
        // chars from buffer.   
        StringReceived[i] = char(buf[i]);
 }
 
      sscanf(StringReceived, "%d,%d,&Sensor1Data, &Sensor2Data"); // Converts a string to an array
         
        // Turn off light to and await next message 
        
    }
 
 memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived

Serial.print("SensorAData= ");
Serial.print(Sensor1Data);
Serial.print(" SensorBData= ");
Serial.println(Sensor2Data);

}

billmcl61:
Hi, I have hit a brick wall trying to send 2 variable numbers from one uno to another uno via a cheap and basic 433MHz set.

The RF absorption factor of brick is very high at that frequency. What kind of antennas are you using?

One software question - you are sending C strings. Did you remember to include a terminating null ( '\0' ) at the end of each string, and ensure that it is processed correctly at the RX end?

Hi Brattain,

Many thanks for your answer, I haven't got antennas fitted as yet, they are just sitting close to each other on the table, as the hello world sketch worked perfectly I didn't fit them.
I didn't know about the string terminating null, simple answer "nope" but this has given me a new line of inquiry to explore.

Ah I see where you are coming from now, I've got the 2 numbers separated with a ",", so that turns it into a C string ?, so that would that return a number *** *** ? I'll try it and see how it goes.
What I'm trying to achieve is sending 2 separate numbers (joystick x & y) and then use these numbers at the other end for motor speed and servo position. The code I'm using at the moment is just to find out how to send and receive these numbers. If I can see these numbers at the Rx end then I can find away to extract them.

Many thanks

Bill

A very typical data record looks like,

123, 456<line feed>

and by I mean a character I can’t print here, its the unprintable character with value 10. It’s the command that allows text to start on a new line. It’s the thing that ‘Serial.println()’ sends.

To decode it, first you look for a value string, in this case you can accept blanks or numeric characters until they run out. That happens when you reach the comma. Now you start looking for a string value, good… then you hit the line feed. Complete! It’s only a matter of choosing the right commands to do the job. But often there is more than one way.

I noticed you only send Sensor1 data. What happens to Sensor2 data?

What do you see if you skip a lot of your receiver processing and just print out the value of buflen and the contents of buf.

The sprintf() function in your tx code should produce a null terminated character string.

As an aside, your tx buffer you defined is big enough to hold the two 4-digit numbers coming from your sensors. You don't have to scale then down I you don't have to.

Also, and I may be wrong here, but I think your sscanf() function call should look like:

sscanf(StringReceived, "%d,%d", &Sensor1Data, &Sensor2Data);

Hi Guys,

Many thanks for your replies and my apologies for not getting back to you sooner, I’ve actually tried a different code and the results look promising, I’m getting both values on the receiving uno using a very cut down version of the code, but just as strings, I found a possible way to convert the received strings to integers, but need sleep first:) then I’ll enter the full code, hook everything up again and try it, with everything crossed.

Best regards

Bill