Created
June 11, 2013 20:29
-
-
Save jadudm/5760353 to your computer and use it in GitHub Desktop.
Radios talking to each-other.
This file contains hidden or 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
//send data routine | |
// link between the computer and the Serial Shield | |
//at 9600 bps 8-N-1 | |
//Computer is connected to Hardware UART | |
//Serial Shield is connected to the Software UART:D2&D3 | |
// # LEFT /dev/tty.usbserial-A901N3TL | |
#include <SoftwareSerial.h> | |
SoftwareSerial Radio(8,9); // TX, RX | |
int buffer[64]; | |
int count=0; | |
void setup() | |
{ | |
Radio.begin(9600); // the Serial port of Arduino baud rate. | |
Serial.begin(9600); | |
} | |
int counter = 0; | |
void loop() | |
{ | |
delay(2000); | |
//digitalWrite(13,LOW); | |
digitalWrite(13, HIGH); | |
Radio.print("COUNTER "); | |
Radio.println(counter); | |
digitalWrite(13, LOW); | |
/* | |
Radio.print("TEST "); | |
Radio.println(counter); | |
*/ | |
counter++; | |
} |
This file contains hidden or 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
//send data routine | |
// link between the computer and the Radio Shield | |
//at 9600 bps 8-N-1 | |
//Computer is connected to Hardware UART | |
//Radio Shield is connected to the Software UART:D2&D3 | |
// # RIGHT /dev/tty.usbserial-A901N6CR | |
#include <SoftwareSerial.h> | |
const int BUFFERSIZE = 64; | |
SoftwareSerial Radio(8, 9); // TX, RX | |
int buffer[BUFFERSIZE]; | |
int count=0; | |
void setup() | |
{ | |
Radio.begin(9600); // the Radio baud rate | |
Serial.begin(9600); // the Serial port of Arduino baud rate. | |
} | |
void clearBufferArray() // function to clear buffer array | |
{ | |
for (int i=0; i < BUFFERSIZE;i++) | |
{ buffer[i]=NULL;} // clear all index of array with command NULL | |
} | |
void loop() | |
{ | |
delay(1000); | |
//Radio.write(0xAA); | |
//Radio.write(0xFA); | |
//Radio.write(0xE1); | |
if (Radio.available()) // if date is comming from softwareserial port ==> data is comming from Radio shield | |
{ | |
while(Radio.available()) // reading data into char array | |
{ | |
buffer[count] = Radio.read(); | |
if (count == 32) { | |
break; | |
} else { | |
count++; | |
} | |
} | |
for (int i=0; i < count; i++) { | |
Serial.print(char(buffer[i])); // if no data transmission ends, write buffer to hardware serial port | |
} | |
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array | |
count = 0; // set counter of while loop to zero | |
} | |
//if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook | |
// Radio.write(Serial.read()); // write it to the Radio shield | |
Serial.println("..."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment