Pair of ATmega328's With 433MHz RF Modules Not Talking

Hello,

I’m currently working on a project that requires some wireless communications. I’ve decided to do this using the 433Mhz RF Kit (WLS107B4B) modules and a couple of ATmega328’s. One ATmega328 transmits and the other receives.

My goal at the moment is to get the “transmitting” ATmega328p to transmit a single byte to the “receiving” one, just to get things started. The LED connected to the transmitting ATmega328 flashes with every byte sent, and the receiving ATmega328 should flash in response. So, they should flash in sync roughly every third of a second, as seen in the code below.

I’m currently using the Manchester library to handle the preamble/checksum parts of the RF communications. Since I’m not actually using the Arduino library, I’ve ported the Manchester library to something simpler that just uses predefined pins and does the port manipulation directly. This is a pretty simple task so I’m confident that I’ve done it correctly.

As far as I can tell, everything’s been set up properly.

But…there’s a problem. The transmitting ATmega328’s LED flashes as it should, but the receiving ATmega328’s does not flash in response.

It appears either as if the TX module isn’t transmitting, or the RX module isn’t receiving properly. I’ve previously verified with another LED (not shown in the images below) that the output pin for the transmitting ATmega328 is working, based on the fact that it blinks when it should be sending data to the TX module.

The RX module seems to be working as well, as some seral debugging output has revealed that it sometimes picks up RF garbage (but then ignores it, as it should). I’ve removed the serial debugging for simplicity in the code below.

I’ve tried unsuccessfully to get this small project to work with the VirtualWire library (again, a version that I’ve ported to use direct port manipulation without the Arduino stuff) as well. I’m also reasonably confident that I’ve ruled out any sort of issues with the physical TX and RX modules themselves, as I have two of each and have tried this with all of them, with no success.

I’ve attached a picture of my RX setup. The extra cables at the top of the image just go to my programmer. It’s tough to see, but the indicator LED is present on PC0 and there is a 17cm antenna coming straight up out of the RX module. I’m also using an external 8Mhz resonator, which is hard to see. (And because someone will ask: yes, the batteries were in fact plugged in when I tested this. :slight_smile: )

And the simplest version of the receiving ATmega328’s code that doesn’t work:

#include <avr/io.h>
#include <util/delay.h>
#include "Manchester.hpp"

#define LED_PORT PORTC
#define LED_PIN 0
#define LED_DIR DDRC

int main(void)
{
  uint16_t message; // the encoded message we receive
  uint8_t id; // an arbitrary message tag
  uint8_t data; // actual message data

  uint8_t i;

  // quick flash intro
  LED_DIR |= (1 << LED_PIN);
  for(i = 0; i < 5; i ++)
  {
    _delay_ms(30);
    LED_PORT |= (1 << LED_PIN);
    _delay_ms(30);
    LED_PORT &= ~(1 << LED_PIN);
  }

  // prepare manchester library and start background receiving
  man.setupReceive(MAN_1200);
  man.beginReceive();

  while(1)
  {
    if(man.receiveComplete())
    {
      // retrieve our new message and prepare for the next one
      message = man.getMessage();
      man.beginReceive();

      // if the message has a valid checksum, flash the LED
      if(man.decodeMessage(message, id, data))
      {
        LED_PORT |= (1 << LED_PIN);
        _delay_ms(30);
        LED_PORT &= ~(1 << LED_PIN);
      }
    }
  }
}

I’ve attached my TX setup, which is pretty similar to the RX setup. (And because someone will ask: no, I don’t endorse Co-Op, Coca Cola, or Pepsi. :slight_smile: )

And again, the simplest version of the transmitting ATmega328’s code that doesn’t work:

#include <avr/io.h>
#include <util/delay.h>
#include "Manchester.hpp"

#define LED_PORT PORTC
#define LED_PIN 0
#define LED_DIR DDRC

int main(void)
{
  uint16_t message; // the encoded message to send
  uint8_t i;

  // quick flash intro
  LED_DIR |= (1 << LED_PIN);
  for(i = 0; i < 5; i ++)
  {
    _delay_ms(30);
    LED_PORT |= (1 << LED_PIN);
    _delay_ms(30);
    LED_PORT &= ~(1 << LED_PIN);
  }

  // prepare manchester library for transmitting
  man.setupTransmit(MAN_1200);

  while(1)
  {
    // delay before transmission
    _delay_ms(300);

    // encode an arbitrary ID of 5 and some other arbitrary number, and then transmit it
    message = man.encodeMessage(5, 10);
    man.transmit(message);

    // flash the LED quickly
    LED_PORT |= (1 << LED_PIN);
    _delay_ms(30);
    LED_PORT &= ~(1 << LED_PIN);
  }
}

Even with the devices only centimeters apart, with 17cm straight antennas, the receiver doesn’t seem to pick up anything from the transmitter at all. Perhaps it’s lack of imagination, but I’m having a hard time figuring out what could be wrong. Is it possible there is 433Mhz interference from somewhere, so strong that my two devices can’t talk even if they’re right next to each other?

If anyone could suggest possible problems, or has any ideas, I’d greatly appreciate it. Thanks!

Geoff

Had some trouble uploading my JPG images, but got it now. I’ve attached the two images describing my TX and RX setup.

Thanks!

If VirtualWire doesn't work, to test either library, replace the radios with a two-wire connection (being sure to connect all the grounds together).

Thanks, Jim. I connected the output pin of the transmitting AVR to the input of the receiving one, and connected their two grounds, and the test programs I posted above worked exactly as expected. Looks like my port of the Manchester library was fine, unfortunately (I was hoping it was just something simple I had missed).

I had to make a slight change, though: since the two grounds were connected, the receiving AVR's LED lit up at the same time as the transmitting AVR's even with the receiving AVR powered down, since the LED output and the TX/RX pins share PORTC. So, I just modified the receiving program to flash the LED 3 times instead of just once so I could tell the difference. But everything worked just fine.

So, I tried the next step, although I had no idea if this would actually work at first: I re-connected the TX module and wired it back up to the transmitting AVR, and physically connected the antenna output of the TX module to the input pin of the receiving AVR. I kept the grounds connected, too. Unfortunately, this didn't work: the receiving AVR didn't flash its LED in response.

In hindsight, I feel silly and suspect that it should not have worked: don't TX modules send out a modulated radio signal that is then demodulated by the RX module? If so, then the input pin of the receiving AVR was just getting some useless analog signal instead (and not a digital one). Is this right? Excuse me while I read up on RF signals.

Unfortunately, I'm not sure what to try next. Any suggestions would be appreciated. Thanks!

Have you confirmed that the radio modules are indeed operational when used with two Arduino's instead of the breadboarded 328's?

Hi cattledog. Thanks for your quick reply.

Unfortunately, I don't have two Arduino's (or even one). I've verified that the RX module is doing something, by temporarily placing an LED across its output DATA pin and GND pin. The LED starts off bright, then fades away, and then flickers back up to full strength, all in about the space of two or three seconds after I first power it on. Then the LED just stays on. I assume this is the gain being cranked up by the RX module?

As for the TX module, no idea if it's working. (I've tried two of them, and they both wouldn't be non-functional...I hope.) Could I use an oscilloscope to test what's coming out of the antenna? Similarly, could I do the same with the RX module's antenna? Or is there an easier way to determine what's going wrong?

Thanks for any reply!

Well, something interesting just happened. I re-connected one of the other TX modules (disconnecting the old one) to the transmitting AVR and then the receiver began to respond properly.

The two breadboards were physically right next to each other, but my joy didn't last long: perhaps only 10-20 seconds or so passed before the receiving AVR stopped responding. So, I disconnected and then reconnected the receiving breadboard's batteries, and tried again, and the same thing happened: the receiving AVR responded for several seconds (to every 2nd transmitter pulse, not each one) before going silent again.

I've managed to get it working a few more times by placing my hands a few inches above the boards when they're next to each other. I figured this out by accident, but I don't know why this works (and it only works some of the time)! The fact that I've experienced some success with the other TX module might just be coincidental, too.

At least I know that the modules work now, but I have no idea what's going on or how to improve what limited success I'm having. I might try increasing the voltage to the TX module by powering the whole breadboard with a 9V battery (using a voltage divider for the AVR, of course). Am I getting interference from somewhere? Why does this behaviour occur?

Any advice would be helpful. Thanks!

I took my setup to my lab and hooked things up to the oscilloscope to see what’s what. (Having never used an oscilloscope before, I had to push a few buttons and otherwise mash my hands over some dials until I learned how the damn thing worked.) I apologize for the low quality of the image (which was taken with my phone): the 'scope is quite old and has no way to output the data to a computer.

First, I connected the probes to the input pin of the TX module. It looked like the data was being sent to the TX module correctly (which I already knew from previous experiments, but wanted to make sure nothing had changed).

The next step was to test the TX antenna. Hooking the probes up (one to the antenna and the other to GND) showed the attached image. Clearly data is being sent, but I have no idea as to the quality of the transmission. Does this look correct?

TX_antenna_reading.jpg

Hooking the probes up to the RX module’s antenna (one to the antenna and the other to GND), however, showed nothing but noise. A couple of times the receiving AVR blinked its LED, indicating that the receiver was working, but I couldn’t get a sample of what this looked like: every time I touched the probes to any of the RX module’s pins (and sometimes even when I moved the probes close to them), the receiver stopped working and I picked up nothing but noise.

I spoke with some colleagues here in the Comp Sci Department who are into wireless communications (although not as low-level as what I was doing), who pointed out a few things for me:

  • My antenna setup “did not look correct”. This was odd to me, since I know of multiple people on this forum who had used a similar approach with success: a 17cm wire antenna soldered onto each board’s ANT through-hole.
  • Breadboards can be a bit finicky when it comes to RF stuff.
  • My problem is not likely being caused by RF interference from Ham radios or other devices.

I’ve also tried hooking up a fresh 9V battery to my TX module, rather than powering it from the 4 AAA batteries that also power the AVR, and this didn’t make a difference.

So…here are some (non-mutually exclusive) possibilities:

  • One of the RF modules is not properly tuned.
  • My physical setup is such that there is enough interference to significantly degrade performance to something unusable.

Unfortunately, I don’t know how I would determine which of these factors is the cause, much less how to fix them.

In any case, I hope this experimentation has been valuable to someone who can lend a hand. Does anyone have any ideas about how to get my RF communications working more reliably? Thanks!

What voltage are you powering the receiver with.
They need as close as possible to 5V to work properly.

Hi mauried,

Each AVR shares 4 AAA batteries with its corresponding RF module.

Measuring the voltage directly across the VCC and GND pins of the RX module, I get 5.09V. I didn't realize that it relied on it being perfectly at 5V. I thought something like what I was getting would be close enough. Thanks for pointing this out!

I'll take a look and see how things improve as the receiver voltage drops down to 5V exactly, as I don't have any 5V regulators lying around anywhere at the moment.

Thanks,
Geoff

5.09 volts is just fine, but the receiver won't work on 3 volts, for example.

If you don't have an oscilloscope at home, the simplest test for a receiver is to use it stand-alone, and have the output fed into the line input of a laptop running Audacity. You need a voltage divider to drop the 5V receiver output to less than 1 V for the audio input. I use a 10K and 1K resistor for that. Then you can visualize the waveform. You can also save the data for analysis.

Here is an example showing the setup and the results: Interface with Remote Power Sockets – Final Version « RAYSHOBBY.NET

If you don’t have an oscilloscope at home, the simplest test for a receiver is to use it stand-alone, and have the output fed into the line input of a laptop running Audacity. You need a voltage divider to drop the 5V receiver output to less than 1 V for the audio input. I use a 10K and 1K resistor for that. Then you can visualize the waveform. You can also save the data for analysis.

That’s a great suggestion, thanks. So, that’s exactly what I spent this evening working on. I also changed the antennas to full-wavelength helical ones. Probably only made a centimeter or two of difference in terms of range. Here are some results.

The TX module DATA IN pin looks like this. This first image is a zoomed-out one that shows the data bursts being sent to the TX module.

tx_pin_large.png

The second here is a zoom-in on one of the peaks, including a weird ‘slide down’ at the end. No idea what that is or why it occurs. Shouldn’t it just cut right off after sending the digital signal?

I’m guessing that the first several evenly-spaced bits must be the preamble for the Manchester encoding. I have no idea why they’re not all at the same voltage: the signals seem to ascend for some reason, and then slide back down after the data is sent. Why is that?

tx_pin_med.png

The third is a zoom in on a peak, without the slide at the end. Again, we can see that the digital signals ascend in voltage, which is weird.

tx_pin_small.png

With this makeshift 'scope, I’m unable to see the voltages going through either of the antennas because the frequency (433MHz) is obviously too high for it. It just looks like noise.

So, here is a picture of the DATA OUT pin on my RX module. The (roughly-)first third of the image shows that data is being received properly (and the LED blinks in response to this as it should). The rest after that nothing coherent is picked up.

rx_pin_large.png

On a whim, I also decided to move transmitter board a little further away from the receiver (far enough away such that it shouldn’t hear anything…this is just a few centimeters, sadly), and listen to what the receiver was putting out on its DATA OUT pin:

rx_pin_noise.png

I also listened in to the same pins while the TX board was turned off, and it ended up looking pretty similar to the above.

Still quite confused as to what the problem is, unfortunately. Are there any other tests that might help narrow things down?

None of those traces look correct.

The input to the data in pin of the transmitter should be a rectangular wave, with digital (~0 and ~5V levels).

If you see a decay, it may be that you have not defined that pin as an output pin, and it is actually an input with the pullup resistor on (which happens when you write a "1" to an input pin). I have been bitten by this mistake several times.

jremington:
None of those traces look correct.

The input to the data in pin of the transmitter should be a rectangular wave, with digital (~0 and ~5V levels).

Ah, you know what? I think I goofed when connecting my voltage divider to my cable. Here is the reference schematic I used.

But I think I connected the blue segment to my voltage divider output, and the other two segments to GND. That blue part is supposed to be GND. What a mistake.

I'll fix this as soon as I can; this might not be until tomorrow when I have more time.

jremington:
If you see a decay, it may be that you have not defined that pin as an output pin, and it is actually an input with the pullup resistor on (which happens when you write a "1" to an input pin). I have been bitten by this mistake several times.

Double- and triple-checked for this just now. Seems okay. I'll fix the cable connections and see where that gets me. Thanks for pointing these things out.

Okay, well, more adventures in RF Land.

I indeed messed up the connections for my poor-man’s oscilloscope. It’s now fixed. Apparently, some of the strange results from the previous images were due to a number of factors such as the input settings on my computer, my incorrect wiring, and Goldwave not displaying my waveforms correctly. This has all been fixed. I’ve re-run my tests using CoolEdit this time. I might try Audacity next.

All my incompetent bumbling aside, here are the results I’ve obtained by running some tests again.

Here is a zoomed-out pic of the TX module’s DATA IN pin. Looks normal to me.

1_tx_pin_wide.png

Zooming in on one of the bursts, we can see the preamble bits on the left half and the data on the right.

2_tx_pin_narrow.png

When receiving correctly, continually, the RX module’s DATA OUT pin shows the following.

3_rx_pin_wide.png

Zooming in on one peak a bit more, we get this:

4_rx_pin_med.png

Showing only and exactly one complete receive sequence:

5_rx_pin_narrow.png

Zooming in further, we can see the data bits being received. Note that these match the signals coming out of the TX module’s DATA IN pin. So, that looks correct.

6_rx_pin_tiny.png

Next, I was curious what the RX module’s DATA OUT pin would look like with the modules physically spread out a bit, so that the RF signal wouldn’t be very strong. Below is what I got. I’ve labelled the three bursts that were received correctly (indicated by a flashing LED).

7_rx_pin_somewhat_close.png

We can also see that the receiver is regularly picking up the other data bursts, but not well enough to interpret them correctly. Sort of as if the signal isn’t strong enough.

I moved the receiver a few centimeters further away, so that nothing would be received:

8_rx_pin_far.png

There is a regular pattern, roughly 380ms apart (300 ms in between each TX burst, and about 80ms to send it), which indicates, again, that the receiver is picking something up, but not enough to interpret it.

Turning the transmitting board off makes the RX module’s DATA OUT pin look like this, which is just noise:

9_rx_pin_tx_off.png

So, right now, it just looks like the signal coming from the TX module isn’t strong enough to be picked up by the RX module at more than a couple centimeters or so. (And I often have to overlap the antennas quite a bit to make this work.)

The thing is, I’ve heard of folks getting tens of meters using these things. I’ll probably experiment with some different baud rates soon. Currently, I’m transmitting/receiving at 1200 baud, but I’ll try 600 and 300 next.

I've also tried hooking up a fresh 9V battery to my TX module, rather than powering it from the 4 AAA batteries that also power the AVR, and this didn't make a difference.

I am impressed by the progress you have made without an oscilloscope.

The latest traces confirm what your discovered when you connected the Rx and the TX pins with wires. Your software is correct and the issue is with the radio modules.

From what you've previously posted, you have the 17cm antennas soldered to the tx/rx modules. I have had the greatest range with my modules when I ran the TX at 12v.

I would also consider upgrading one notch from the super-regenerative receiver to a super-heterodyne model and a Tx unit with a saw wave oscillator. I've used these successfully

Yes, that is quite an improvement! Those traces look for the most part excellent. You seem to be doing the right thing, so the miniscule range is a puzzle.

I can get up to 300 meters range in the unobstructed open air with 434 MHz modules (simple superregenerative receivers, 17 cm wire antennas on TX and RX), so I agree with cattledog that something is wrong with one or the other of your modules. The receiver might be detuned, etc.

If you would like to try a different antenna, about 40cm of TV Coax will do the trick.

Strip off 17cm of outer plastic and tease away the shielding, and either trim the shielding to 17cm or remove most of it, and add a 17cm length of hookup wire. Tape it to go in the opposite direction to the exposed core (no need to strip it leave the plastic on).

Strip a very small amount off the other end and connect shield to GND and center to the Rx (and/or another to the Tx).

Basically makes a simple dipole. Worked the best for me.

Rob

Edit: You may like to try my self-contained Manchester routines on GIT-Hub. I suspect that you may not have a long enough preamble and the AGC on the Rx is not getting to the sweet spot to turn OOK into clean digital quick enough. You can control all of the Manchester set up eg preamble bits in my Rx/Tx combo.

Thanks very much for the feedback, everyone.

I made a few adjustments and shortened a couple of wires, and lowered the baud rate to 300. This actually managed to squeeze out a few (2-3cm) of extra range, which is positive. Unfortunately, this is the best I could get.

Just to rule out the possibility of some kind of interference from somewhere in the city, I took my modules with me when I visited a small town about 70-80km away. Still experienced the same problems, I'm afraid.

That's very odd that both pairs of my modules exhibit the same poor range despite some folks having great success with them at some decent ranges. It makes me think I've done something wrong. What are the chances that I've bought two faulty pairs of modules, separately?

cattledog:
From what you've previously posted, you have the 17cm antennas soldered to the tx/rx modules.

I've recently changed these to full wavelength (69cm) helical antennas a few posts ago. Not much improvement, I'm afraid.

cattledog:
I have had the greatest range with my modules when I ran the TX at 12v.

I would also consider upgrading one notch from the super-regenerative receiver to a super-heterodyne model and a Tx unit with a saw wave oscillator.

I'll try 12V soon. Eventually, I'll probably have to buy some different modules if I can't figure out and fix what's going wrong here. Those ones you mentioned look promising and have a similar form factor to the ones I've been using.

jremington:
I can get up to 300 meters range in the unobstructed open air with 434 MHz modules (simple superregenerative receivers, 17 cm wire antennas on TX and RX)

Could you please share more details about your approach, and some of the hardware used? I'm curious about anything fundamental that I might be doing wrong compared to your approach.

robwlakes:
If you would like to try a different antenna, about 40cm of TV Coax will do the trick...

Thank you for the suggestion. I'm pretty sure I have some spare Coax lying around.

I had another question: given that the most likely problem is my modules themselves, is this an issue that can be fixed? Examples might include re-tuning the module(s) somehow, or modifying the transmitter hardware to output a stronger signal, etc.

Thanks again!

Sorry just added an edit to previous post.

The 433Mhz modules are pretty broadly tuned and operate ok within that, as long as the software is OK as well. However a specific module maybe a little out of spec (eg the speed at which the AGC stabilizes) and the software may need to be tweaked (even it conforms completely at the moment to the Manchester protocol) eg a longer preamble, maybe 30-40 bits rather than 15 shown at the moment.

Just a thought bubble! :slight_smile:

Cheers, Rob