An interesting trick you can do with a a fast CPU and a GPIO pin mapped directly to memory is an FM transmitter. Just toggle a pin on and off fast enough, and you have a crude and kludgy transmitter. [Brandon] saw a few builds that turned a Raspberry Pi into an FM radio transmitter and realized a lot of toy remote control cars use a frequency in the same range a Pi can transmit at. It’s not much of a leap to realize the Pi can control these remote control cars using only a length of wire attached to a GPIO pin.
The original hack that turned a Pi GPIO pin into an FM transmitter mapped a GPIO pin to memory, cycled through that memory at about 100 MHz, and added a fractional divider to slightly adjust the frequency, turning it into an FM transmitter. Cheap RC cars usually listen for radio signals at 27 and 49 MHz. It doesn’t take much to realize commanding RC cars with a Pi is possible.
The only problem with this idea is that most RC cars use pulse modulation. For an RC transmitter to send the command for ‘forward’, a synchronization pulse is sent, then a series of pulses and pauses. The frequency doesn’t change at all, something the originally FM code doesn’t do. [Brandon] realized that if he just moved the frequency up to something the RC car wasn’t listening to, that would register as a zero.
All that was left was to figure out the command codes for his RC truck. For this, [Brandon] decided brute force would be the best option. Armed with a script and a webcam, he cycled through all possible combinations until the webcam detected a moving truck. Subtlety brilliant, if you ask us. Of course more complex commands required an oscilloscope, but now [Brandon] has a git full of all the code to control a cheap RC car with a Pi.
18 thoughts on “Controlling RC Toys With The Raspi”
Will a neckbeard please step up and say how you can do this using only components and zero fancy schmancy programming?
you can do this using only components and zero fancy schmancy programming.
Something like a 27MHz crystal and a NOT gate would be one. Actually a NAND gate, so the Pi could turn it on and off. Or some oscillator built around a single transistor, the sort of stuff they use in cheap RC toy remotes in the first place. My neckbeard powers unfortunately lack XP in the analogue class, so I couldn’t actually design it for you.
There’s certainly more sensible things to do with all those cycles than toggle pins into transmitting RF. They were doing it in the 60s with AM radios, indeed I once wrote something using loops on a Z88 in BASIC that had an awful, but definitely real effect.
A gate might not have enough bandwidth. Use a FET and bang on it at the baseband modulation rate.
What, you mean just switch a FET on and off 27 million times a second from a GPIO? If not, how’d you mean bang on it? That would increase the signal strength perhaps but still be massively wasteful of a CPU, doing a job a few pence worth of components could, and often do, do.
The point, I thought, was how to do it “properly”, ie a 27MHz oscillator controlled or gated by the Pi.
No, I meant use the FET to gate the oscillator output. I think we’re talking about doing the same thing. I just don’t know if a discrete NAND gate would pass the high frequency very well. AM radio is easy enough to heterodyne with logic gates, but I’ve never tried it at 27MHz+.
Logic gates especially those newer lower voltage ones (e.g.) LVC are built with much smaller (lower voltages) and faster technology. They can easily run at 100MHz.
One trick I like to use is to use a PWM output of a microcontroller as a transmitter. It works well for up to a few MHz, which nicely works out for low speed PLC.
Back in the day, you could send hex words to imitate the proper control pulses
You could use one of those TTL oscillator cans if you wanted to simplify the software but still avoid designing any real hardware. You might even be able to power the oscillator directly from an IO pin, avoiding the need for any other components. Some of them also have enable inputs.
Oscillators have a startup time as they have to build up their amplitude… 10 milliseconds is the order of magnitude, so might not work too well with RC servo which have pulse width in the 1ms range. On the other hand, the enable pin are plenty fast.
Reading HCMOS/TTL CERAMIC SMD OSCILLATORS F3160/F3165 datasheet.
Startup time: 10ms, Enable/disable time (from the /INH input): 100ns.
This is neat to see this applied again; some guy on the Arduino forums was playing around with this kind of control as well a while back:
Couldn’t you just set a GPIO to PWM mode with a frequency of ~49MHz, and then toggle the dutycycle between 0 and 50% to send bursts ?
Might be useful for making Pi powered RC toys, as it would reduce the amount of wiring needed and also retain normal RC functionality for when the unit gets into trouble.
Also useful, reading back signal strength so when the unit goes out of range it automagically returns to base in the reverse direction until signal comes back.
this is so cool! easy raspi robots!
You can take nand gates and create inverters by tying the inputs together. You have to cascade them in odd numbers (3 NOT stages – aka inverters) and use a crystal or rc netwrok to control the frequency. With two chips (quad nand) you can have both a carrier and modulation, using the second chip to gate the first chip, or vice versa. You can tweak the frequency using a second pin to alter the RC constant of whatever network you use to set timing of the oscillator.
Add a 555 timer, a 558 timer or PLL and you could get all kinds of bizarre beepity-boop and bizarre tonal sequences going up well into the AM spectrum, and up to 30 mhz using the faster parts. Audio was easy. Any micro controller can do audio – apply the output pin to one input on a gate, and you can have anything you like – from speech to audio playback. I would expect that the newest microcontrollers can get up into FM without much more than an upconverter of some kind. AM is pretty easy – 1Mhz is in the middle of the band.
Of course, these won’t be very elegant designs, and they will bleed all over the spectrum until you master filtering and construction. You might be causing interference somewhere – just like the new gas meters manage to jam the FM band or microwave ovens jam wifi. And if you’re pumping out PWM, you can turn it into analog by hanging a resistor and a cap off the output.
However, anyone with an am radio and microcontroller can play – simply buffer the output of an IO pin and add a 6″ wire pulled up vertically to play antenna. Write a routine to turn the pin on, subtract one from a counter/register, turn it off, jump out if zero and then repeat it again from step one.
You may have to put a few nops or junk instructions in between turn on and turn off, (and really, if you can figure out instruction times that add up to the time between cycles (a rate in between 510,000 and 1,530,000 khz – or cycles per second), you’ve just built a radio transmitter. You can even put a variable delay in between on and off to change frequency on the fly. Do it at 93,000,000 times per second and you’re in the fm band.
Welcome to the fun world of digital radio!
Digital reception is not much harder for simple cases – you’ll need to reverse the process, and you really need a tuned circuit to do it right. However, if you can sample the state of the antenna at least 4x faster than your carrier signal frequency, you can run an average and detect the presence of your signal. And it works way better if you can sample 16x faster.
This will only let you guess if the carrier is present or not – if you want to decode things like voice or a more complex modulated carrier, you’ll need to start hanging out in the analog and/or slightly complex math section of the digital world. It isn’t really that much harder, for simple signal types.
And then it’s just a “hop, skip and a jump” to software defined radio.
Caution for the tinfoil hat crowd: Once you get into software defined radio and start looking into signal capture, you may grow slightly paranoid. It’s quite an iceberg, this wonderful future of ours!
Hi, Is there a link where it’s explained in detail. I am new to raspberry and would like to connect raspberry to RC remote and control the toys
Any inputs, links would help
googling from lat 4 days, no success
Thanks in Advance
Did you ever get a response?
Please be kind and respectful to help make the comments section excellent. (Comment Policy)