Hi,
I have to send an "long" number throught virtualwire.
I convert the long with itoa.
As soon as the number is up to 40000 (may be a little bit less), I receive a wrong value.
Do you know a way for solve my issue?
Hi,
I have to send an "long" number throught virtualwire.
I convert the long with itoa.
As soon as the number is up to 40000 (may be a little bit less), I receive a wrong value.
Do you know a way for solve my issue?
Use ltoa()
I have tried already BUT without changed itoa by atol in my receiver program....
Now it's ok.
Thanks
Why are you converting the long to a character array?
You can send and receive the four bytes of the long. Something like this
vw_send((uint8_t*) &dataSent, sizeof(dataSent));
if (vw_get_message((uint8_t*)(&dataReceived),&buflen)
//do something with dataReceived;
I tried your code then I have a error message.
"invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]"
vw_rx_start();
uint8_t buf=VW_MAX_MESSAGE_LEN;
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
// do what you want
If think that you can send "char" value only.
vw_rx_start();
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
// do what you want
it's corrected.
But each values received egal to 2257...
Please read reply #3 again, and try the suggested code.
Here is example code Transmit and Receive the four bytes of a long integer.
//Transmit long integer four bytes
#include <VirtualWire.h>
long dataSent = 123456;
void setup()
{
vw_setup(2000);
}
void loop()
{
long interval = 1000; //send every second
static unsigned long millisLast = millis();
if (millis() - millisLast > interval)
{
vw_send((uint8_t*) &dataSent, sizeof(dataSent));
vw_wait_tx();
millisLast += interval;
dataSent += 10;
}
}
//Receive long integer four bytes
#include <VirtualWire.h>
long dataReceived;
void setup()
{
Serial.begin(9600);
Serial.println("setup");
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message((uint8_t*)(&dataReceived), &buflen))
{
Serial.println(dataReceived);
}
}
good it's work fine !!!
Thanks for your help
there is a limitation for the int long sent through virtual ware?
there is a limitation for the int long sent through virtual ware?
No.