Issue - I’ve set them up for the test program (see code below), however I’m not seeing any response from the receiving Arduino. I note that when I put a multimeter on the transmitter the +ve voltage on VCC is OK, and when I look at teh DATA line I see it stays at around VCC voltage but the needle moves a little every second, so it seems as if it getting the transmit signal ok. I don’t have antenna wires on them, but they are only a few centimeters apart so this should be ok no?
Question - Any advice on how to trouble shoot in this situation? I only order one of each of the units.
Transmitter Code
/* * Simple Transmitter Code
* (TX out of Arduino is Digital Pin 1)
* (RX into Arduino is Digital Pin 0) */
byte counter;
void setup(){
//2400 baud for the 434 model
//Serial.println("setup");
Serial.begin(4800);
counter = 0;
}
void loop(){
//send out to transmitter
digitalWrite(13, HIGH); // Flash a light to show transmitting
Serial.print(counter);
counter++;
delay(50);
digitalWrite(13, LOW);
delay(1000);
}
Receiver Code
/* * Simple Receiver Code
* (TX out of Arduino is Digital Pin 1)
* (RX into Arduino is Digital Pin 0) */
int incomingByte = 0;
void setup() {
//2400 baud for the 434 model
Serial.begin(4800);
//Serial.println("setup");
}
void loop(){
// read in values, debug to computer
if (Serial.available() > 0) {
digitalWrite(13, HIGH); // Flash a light to show receiving
incomingByte = Serial.read();
Serial.println(incomingByte, DEC);
digitalWrite(13, LOW);
}
incomingByte = 0;
}
These are OOK transmitter/receivers. What does the receiver output look like on an O’scope?
Try bit-banging a 1200Hz waveform into the transmitter and see if it shows up at the receiver. Don’t use serail tranfer functions yet. Just poll the input pin to detect the square wave.
Then read up on how to use OOK modulation for serial data.
OOK receivers need a preamble to set the data slicer threshold (integrator), that being a long string of 1010101… then in the data, code it so that long strings of all 1’s or 0’s cannot occur. Manchester coding, or byte table lookups.
Or simplify, use Digi XBee series on modules from SFE. More costly, but plug and play.
stevech:
OOK receivers need a preamble to set the data slicer threshold (integrator), that being a long string of 1010101… then in the data, code it so that long strings of all 1’s or 0’s cannot occur. Manchester coding, or byte table lookups.
thanks - can I ask:
a) but the code I’ve posted should work though correct?
b) re “need a preamble” - are you saying the receiver won’t actually work without this? My understanding of these tx/rx pair that the receive line (on/off) should just reflect the transmitter (on/off), so if fact the preamble would be more to do with the arduino’s serial operations expectation then? i.e. not to do with the transmitter itself
Yes, to actually pass data the Preamble is mandatory with OOK modulation.
No, the code you posted will not work with OOK. Although with some modification it may work part of the time. You can try sending data that keeps changing the level of the bits as Steve suggested. The letter ‘U’ is ASCII is 0x55 and a good one to use. Change the code to send this a 100 times without any breaks or delays between characters. The Receiver and receive code should be able detect these.
This will prove that the RF units work. Then look up the info that Steve suggested.
Also, search through the threads here as the problem has been discussed and solutions presented a number of times.
There is a real reason why OOK RF units are so cheap. You pay by added complexity of the interface and supporting code.
oh - I’m just wondering then how does this correlate with the code I’m trying which is actually based on the test program that is referenced from the vendor site? That is the specific doco with code:
This is something that trips up a lot of people. You need to have a low->high or high->low transition on the transmitter’s data line at least once every 30ms or so. If you simply output a constant “1” on the transmitter, you’ll get 30ms of “1” on the receiver and then a stream of garbage. In your program, when you delay(50), the receiver loses sync with the transmitter. Ditto for delay(1000).
About the baud rate: I use these units at 600 or 1200 baud - so far I’ve never gotten reliable data transmission at 4800 baud. But 600 baud works great (works fine at 50+ feet in my testing)
In your code, try setting the baud rate to 600 and removing all the delay()s so that you’re constantly outputting data. With any luck, the receiving end should be able to pick up something.
Incidentally, a good starting point is to just constantly output the char “U” and see if you can read a “U” on the receiving end.
ok - thanks (will try this tonight) - the reason I went to 4800 baud was I saw only this mentioned for the receiver at http://www.sparkfun.com/commerce/produc … ts_id=8950, but perhaps this was just the max then?
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}
void loop()
{
const char *msg = "hello";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
}
Receiver
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
digitalWrite(13, false);
}
}
PS another piece of advice I got from another forum was:
Connect the transmitter input to a pull-down resistor (5-10k should be fine) and use a button (or just touch a wire) to pull it up to the transmitter power. Connect the receiver output to a transistor switch and an LED, the same way you would do with n Arduino digital output pin. You should be able to turn the receiver LED on and off by taking the transmitter pin high and low.
Just tried removing delays, sending the “U” constantly, and setting to 600 baud rate (Serial.begin(600) - but still can’t receive anything.
Then I tried the no-Arduino test. Just applied (based on a button push) either 0V or 5V to the transmitter input. However at the receiver I don’t see any change when I push the transmitter button. The receiver data pin just shows a constant 2V (where VCC = 4V for the receive). Does this imply do you think one of the devices is faulty? I’m assuming on the receiver that where it’s got multiple 5V, GND pins etc, that I only have to connect one correct? (i.e. I don’t have to hook up 5V inputs to the two +5V pins of the receiver)
EDIT - Actually I just connected an LED on the receiver directly from GND to DATA. I also took the LED out and just measured voltage on the receiving DATA pin and it sits at VCC (=4V) and doesn’t change when I push the button on transmitter to toggle input voltage on it’s data line.
I’m assuming on the receiver that where it’s got multiple 5V, GND pins etc, that I only have to connect one correct? (i.e. I don’t have to hook up 5V inputs to the two +5V pins of the receiver)
That is a bad assumption unless you know for certian that all of the common pins are connected together on the board. An Ohm meter would confirm whether they are or or not. My guess is that they are not.
How come you’re using +4V to power the receiver? The (admittedly shoddy) datasheet says +4.5V is the bare minimum on Vcc, with +5V recommended.
You can use the unit with only one Vcc, Gnd, and Data pin connected. It’s OK to leave the others disconnected, it still works fine. But the range is only a few feet if you don’t hook up an antenna.
It says on the web site it’s a 5V Arduino, however I’m only seeing 4V at the VCC terminal? However it is just plugged into the USB port on my Mac…perhaps I need to get the power adaptor before it will produce 5V? (will try at home tonight)
Update: I’m still not able to receive serial data on the receiver HOWEVER I have managed to prove to myself that the receiver is receiving something from the transmitter.
When I connect an LED to the DATA pin of the transmitter and the other end to earth, I see the LED flickering, fairly soft (never hard on). I can adjust the timing of the transmitter with the delay() (i.e. put it back in for a bit) and I can see that the flickering on this LED on the receiver matches the timing of when the transmitter is sending.
When I connect the DATA pin up to PIN 0 of the receiver Arduino board however I note that:
(a) I still get no output in the Arduino serial monitor, i.e. when I click on “serial monitor”, nor see the pin 13 on board LED flash
(b) I also not that the LED in the chain (Rx_Data_Pin => LED & Arduino Rx Pin 0) that the LED go full on with no flickering when I connect the Rx_Data_Pin to the Arduino Rx Pin 0 too? Is this an issue? Should the LED effectively from the Arduino Rx Pin 0 to GND still not keep flickering just as it was?
Any other ideas? Should I try bringing the RF Rx receiver signal into a normal Arduino input pin and monitor for a change in this and flash a LED if it changes, just to prove the RF Rx is picking up true on/off signals? (as opposed to just letting the RF Rx output com into the Arduino pin 0 Rx)
thanks
PS Receiver code again is:
int incomingByte = 0;
void setup() {
Serial.begin(600);
}
void loop(){
if (Serial.available() > 0) {
digitalWrite(13, HIGH); // Flash a light to show receiving
incomingByte = Serial.read();
Serial.println(incomingByte, DEC);
digitalWrite(13, LOW);
}
incomingByte = 0;
}
Transmitter
byte counter;
void setup(){
//2400 baud for the 434 model
//Serial.println("setup");
Serial.begin(600);
counter = 0;
}
void loop(){
//send out to transmitter
digitalWrite(13, HIGH); // Flash a light to show transmitting
Serial.print("U");
counter++;
digitalWrite(13, LOW);
//delay(10);
}
PS I’ve been leaving my USB connections (two, one for each arduino) from my Macbook USB ports connected during testing. Is this ok? Doesn’t pose any issues with my attempted use of the pin 1 and pin 0 serial communications?
PSS Tried taking the USB connector out of the receiver arduino board but still no luck. I note when I connect the RF receiver DATA pin into the receiver arduino boards PIN 0 (Rx) that the LED flashes, but only triggered by the point when the connection is made. i.e. no more flashes, based on the code, indicates the board is not getting any incoming serial info to read.
Ardurino’s alone - So when I connect the PIN1 TX output from board one to the PIN0 RX input of board two directly the serial communications works like a charm, no problems.
RF Units Alone - When I apply to the RF transmitter DATA pin:
(a) 5V - the RF receiver data pin goes to 0V
(b) 0V - receive output jumps around a bit in the range of around 0.5V ?? (doesn’t seem good)
Good news - I got my extra transmitters and receivers. I substituted these in and now things are working. I’m sending “85” repeatedly and I’m picking this up at the receiver via RF.
One curious thing, I note that when I close then restart the serial monitor on the receive side the display jumps from getting incoming “858585858585…” to "58ª
Any ideas why this would be? One of of correcting it seems to be to set the serial monitor to another baud rate, then back to the correct one. This may not fix it the first time but within a few toggles the readout goes back to showing “85858585858585…”.