國外使用 Arduino 及 RF Module
simple. It just sends the numbers 0-255 repeatedly and prints them out
to serial (use the serial monitor to watch the bytes fly by). The part
that threw me for awhile was that the receiver has two data pins. I
read somewhere
(*ahem* SparkFun KLP Walkthrough Tutorial) that only one of them was
useful (pin 2) and the other (pin 3) was optional and could be tied to
ground. After banging my head against the wall, I looked at the
receiver data sheet which clearly shows that the data pins should be
tied together! Once I corrected my wiring, it worked beautifully. So,
last but not least, a photo.
Arduino RF Link
I bought two RF links from SparkFun a while back (a 315Mhz and a 434Mhz).
A few nights ago, I actually hooked one of them up and successfully ran
a test program between two Arduinos. Here's the code for the receiver:
#define rxPin 2<br />#define txPin 3<br /><br />byte incomingByte = 0;<br /><br />SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);<br /><br />void setup() {<br /> pinMode(rxPin, INPUT);<br /> pinMode(txPin, OUTPUT);<br /> rfSerial.begin(2400);<br /> Serial.begin(2400);<br />}<br /><br />void loop() {<br /> incomingByte = rfSerial.read();<br /> Serial.println(incomingByte, DEC);<br /> incomingByte = 0;<br />}</pre>And for the transmitter:<pre>#define rxPin 2<br />#define txPin 3<br /><br />SoftwareSerial rfSerial = SoftwareSerial(rxPin, txPin);<br />byte outgoingByte = 0;<br /><br />void setup() {<br /> pinMode(rxPin, INPUT);<br /> pinMode(txPin, OUTPUT);<br /> rfSerial.begin(2400);<br /> Serial.begin(2400);<br />}<br /><br />void loop() {<br /> Serial.println(outgoingByte, DEC);<br /> rfSerial.println(outgoingByte, BYTE);<br /> outgoingByte++;<br /> delay(10);<br />}Pretty
simple. It just sends the numbers 0-255 repeatedly and prints them out
to serial (use the serial monitor to watch the bytes fly by). The part
that threw me for awhile was that the receiver has two data pins. I
read somewhere
(*ahem* SparkFun KLP Walkthrough Tutorial) that only one of them was
useful (pin 2) and the other (pin 3) was optional and could be tied to
ground. After banging my head against the wall, I looked at the
receiver data sheet which clearly shows that the data pins should be
tied together! Once I corrected my wiring, it worked beautifully. So,
last but not least, a photo.
沒有留言:
張貼留言