Back in October I received the two OpenSourceRF wireless arduino shield from the kickstarter I backed. I've poked around with them on and off but I haven't had a whole lot of success. Admittedly, I haven't really tried hard either. So today I settled in to try and get the two devices communicating.
First I started with two arduinos wired directly to one another. Once I could confirm the sketch for that worked, I slapped the shields on and tested them wired. Success.
So I pulled the wires out of the Rx and Tx ports on the arduinos and tested to see if the boards would still communicate. That's when I hit a snag.
I read the manual for the wireless shields and played around with some of the settings. After playing around a little I discovered the shields would communicate as long as the Serial Mode (SW4) Bank 1 switch was on. After that the devices were talking.
Of course the next snag I hit was that the receive arduino didn't understand what the send arduino was saying, just that it was saying something. Still, that's progress. I'l have to read up on serial communication to learn how to pass usable data between the devices.
I used an example from here, although I wired up a photoresistor instead of a potentiometer.
As you can see in the above photo, wiring the two arduinos is easy. Once everything is wired up, simply set the Serial Mode (SW4) Bank 1 switch (it's the top switch in the orange box) to ON. After that you should see the RF DIN and RFDOUT LEDs blink.
Here are the basic sketches I used.
Send Sketch
//Sending Arduino Code
int analogValue5;
void setup() {
// Serial port enable
Serial.begin(19200);
}
void loop() {
// read analog pin 5
analogValue5 = analogRead(5);
int val=analogRead(analogValue5);
Serial.println(val);
delay(100);
}
Receive Sketch
// Receiving Arduino Code
byte incomingByte;
void setup() {
Serial.begin(19200);
pinMode (11, OUTPUT); //set pin 11 to output - this is for the LED
}
void loop() {
// check if there are any bytes available across the serial port
if (Serial.available()) {
// set the values to the ‘incomingByte’ variable
incomingByte = Serial.read();
// write the value to the pin 11
analogWrite(11, int(incomingByte));
Serial.print(incomingByte);
}
}
Now the next step is to get a temperature sensor wired up and sending the proper information over RF.
0 comments:
Post a Comment