bit of an epic but I've tried to include all relevant info.
I bought a 4800bps 315Mhz RF link to have a play with..http://www.coolcomponents.co.uk/catalog/product_info.php?cPath=25&products_id=186
Connecting one side to an Arduino Duemilanove and the other to an Arduino Nano - both 328
Assumed it was broken and was about to give up when I tried the VirtualWire Library http://www.open.com.au/mikem/arduino/
copied over the example code and got the things talking.
My pleasure was somewhat diminished by my inability to understand the code or the helpfile.
This is the example sending code loop...
const char *msg = "hello";
vw_send((uint8_t *)msg, strlen(msg));
Which from what I can piece together from forum and doc surfing sets the multi character constant called msg
to have the string value hello
and then uses the vw_send command from the library to send that text with a length of 5?
What does the (uint8_t *) part mean? Is it just standard for the send command? Multi-byte?
The receive loop code is...
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
// Message with a good checksum received, dump HEX
for (i = 0; i < buflen; i++)
uint8_t is new to me (as is most of this I'm afraid) Again, reading into it, it seems to be saying define a byte array with the length being the length of the string sent.
Then define another for the length itself.
Then checks to see if there is a message....
if there is, it runs through the array and displays it as a series of HEX characters.
(Actually it has helped to type this out so hopefully I have some of it correct!)
Would appreciate if someone could check my understanding and comment please.
To take it a step further, I wanted to replace the HELLO message with the output from a pot connected to A0 (+5V and GND)
I mapped the reading to between 0 and 255 ...
analogValue = analogRead(0);
analogValue = map(analogValue, 0, 1023, 0, 255);
...but then got completely confused when trying to amend the code to send this data.
It did give me some readings but these tended to be 0, 8 a few other randoms or 255. Also when the pot was turned all the way the output stopped completely so I guess that tx wasn't sending.
I'm using the default send and receive port for VirtualWire (12,11).
Should I have had a resistor connected to the pot?
Tried this as a send command...
vw_send((uint8_t *)analogValue, 1);
Where analogValue was the mapped int reading from the pot.
Then left most of the original code in the receive end but replaced the print line with.
and took out the 'for' loop. Clearly wrong as it isn't giving me correct results.
Could someone assist please?
Many thanks in advance