Hello everyone
I'm trying to use two 433 Mhz RF modules, to allow communication between Arduino UNO and Arduino MEGA.
I would like to send at least 4 data, variables of type float.
Try to use these two sketches, work, but with these sketches can only send variables of type integer.
That trick I use to be able to send data of type float? (Even with only one decimal place)
how can I convert data from float to integer, send, and then convert them back to a float?
I also read the dtostrf function () but I do not know how to use it to concatenate multiple variables of type float
Help me, I'm stuck =( =(
Thank you!
Transimetter
#include <VirtualWire.h>
int ledPin = 13;
int Sensor1Data;// The variable were the data from each sensor
int Sensor2Data;// will be stored
int Sensor3Data;
int Sensor4Data;
char Sensor1CharMsg[21];// The string that we are going to send trought rf
void setup() {
// LED
pinMode(ledPin,OUTPUT);
// VirtualWire setup
vw_setup(2000); // Bits per sec
vw_set_tx_pin(52);// Set the Tx pin. Default is 12
}
void loop() {
Sensor1Data = 152;
Sensor2Data = 258;
Sensor3Data = 325;
Sensor4Data = 412;
sprintf(Sensor1CharMsg, "%d,%d,%d,%d,", Sensor1Data, Sensor2Data, Sensor3Data, Sensor4Data);
// Turn on a light to show transmitting
vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
vw_wait_tx(); // Wait until the whole message is gone
// Turn off a light after transmission
delay(40);
}
RECEIVER
#include <VirtualWire.h>
// Sensors
int Sensor1Data;
int Sensor2Data;
int SensorData3;
int SensorData4;
char StringReceived[22];
void setup() {
Serial.begin(9600);
// VirtualWire
// Initialise the IO and ISR
// Required for DR3100
// Bits per sec
vw_setup(2000);
vw_set_rx_pin(8);
// Start the receiver PLL running
vw_rx_start();
} // END void setup
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
//Taking the data from the control base
if (vw_get_message(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,%d,%d",&Sensor1Data, &Sensor2Data,&SensorData3,&SensorData4); // Converts a string to an array
Serial.println(Sensor1Data);
Serial.println(Sensor2Data);
Serial.println(SensorData3);
Serial.println(SensorData4);
}
memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived
}