Created
January 27, 2014 03:36
-
-
Save shnae/8642916 to your computer and use it in GitHub Desktop.
Arduino sketch showing a very basic method of sending a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <nRF24L01.h> | |
#include <RF24.h> | |
#include <RF24_config.h> | |
/* | |
This sketch sends a string to a corresponding Arduino | |
with nrf24 attached. It appends a specific value | |
(2 in this case) to the end to signify the end of the | |
message. | |
*/ | |
int msg[1]; | |
RF24 radio(9,10); | |
const uint64_t pipe = 0xE8E8F0F0E1LL; | |
void setup(void){ | |
Serial.begin(9600); | |
radio.begin(); | |
radio.openWritingPipe(pipe);} | |
void loop(void){ | |
String theMessage = "Hello there!"; | |
int messageSize = theMessage.length(); | |
for (int i = 0; i < messageSize; i++) { | |
int charToSend[1]; | |
charToSend[0] = theMessage.charAt(i); | |
radio.write(charToSend,1); | |
} | |
//send the 'terminate string' value... | |
msg[0] = 2; | |
radio.write(msg,1); | |
/*delay sending for a short period of time. radio.powerDown()/radio.powerupp | |
//with a delay in between have worked well for this purpose(just using delay seems to | |
//interrupt the transmission start). However, this method could still be improved | |
as I still get the first character 'cut-off' sometimes. I have a 'checksum' function | |
on the receiver to verify the message was successfully sent. | |
*/ | |
radio.powerDown(); | |
delay(1000); | |
radio.powerUp(); | |
} |
Hi!
For solve your problem of cut-off, put in your code a delay above "radio.write(charToSend,1);".
delay(1);
radio.write(charToSend,1);
PS.: Sorry my english! I hope this help you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It´s there any way to send the whole string at the same time? I mean, in this code you are sending the message letter to letter, is there any way to send all the letters at the same time?