Penelopean robotics part 3 - radio transmissionsPosted Oct. 20, 2018 by Dave Griffiths
On the Penelope project, our plan was to develop technologies that could be useful in constructing a swarm of robots which could be livecoded by using the pattern matrix - a general purpose tangible programming system based on the Raspberry Pi. In order to make communication possible remotely, radio is the most obvious approach to get up and running quickly (other options that are intriguing are infra-red and audible sound).
A commonly used and extremely cheap module for radio communication is the nrf24l01+, which uses the 2.4Ghz band (the same as wifi) and allows you to send messages between arbitrary numbers of transceivers. It provides a very flexible networking setup - you can address them all individually, or broadcast to many at one go (which doesn't seem to be mentioned anywhere), or you can construct a mesh network, passing on messages to receivers outside of the range of the original sender.
There are a few examples online for getting these working with both Raspberry Pi, Arduino and bare-bones ATMel microprocessors as used in our prototyping system. However the tricky thing about radio communication is that it requires you to have both a transmitter and a receiver operating before you actually can tell if it works - it can be extremely difficult to know what is happening when you are developing both at the same time.
I found this quite a challenge - probably not helped by using different hardware at each end, as I needed to cobble together multiple examples to get anything to happen. Here are some things I picked up that might be handy if you are trying to get these radios to work:
- Before doing any sending or receiving, check that the SPI serial is set up properly by reading registers on the nrf24l01 and checking that they match the default settings in the data sheet.
- Then try writing to them and reading again to check that the writes actually take effect. Note that this only works when the radio is not sending or listening for transmissions! Not reading the documentation carefully cost me a few hours here.
- Make sure _all_ the registers match on both sides, there are obvious things like the frequency channel and data rate but also auto-acknowledge, crc and payload size all need to be exactly the same otherwise not even the interrupt will fire to let you know something has been received. Although it should have been obvious, most of my problems came down to this - using different example code and not knowing the defaults to begin with made it tricky to know for sure what was going on.
- Get the transmitter working first. There is a very useful function on the nrf24l01+ which allows you to check if a carrier signal is detected on a frequency without doing any other processing. There is an Arduino library scanner example program in the RF24 library which steps through all the frequencies checking for any carrier signals. You can easily see where your local wifi is with this, so you can pick an empty section of the frequency band to broadcast on and then watch for it's carrier to be detected. Once I had seen that the Pi was actually sending *something* (you need to make it send as many messages as possible for this to work well) I could concentrate on why the receiver was rejecting or not tuned to it.
- There is a lot of stuff on the internet about power supply being a problem - I worried about this a lot and tried many different capacitors across the voltage pins, but in the end all my problems were software based. On the robots we're using 3.7V Li-Ion batteries and a 3.3v regulator (a low-dropout one as the voltages are very close) plus 2.2uF capacitors to keep the supply smooth on both the 3.3v and 3.7v sides, which works fine even with the servos sharing the power.
Created: 15 Jul 2021 / Updated: 15 Jul 2021