Ever wanted to use a Raspberry Pi to remotely control an Arduino, but using something smaller and more portable than a keyboard? Here we’ll show you how to add a Pi Zero and wireless radio to a controller from an RC toy, turning it into a versatile and customisable project controller!
The full article can be found in The MagPi 46 and was written by James Lacey
Large RC car controller
Micro USB cable
STEP-01 Prepare the controller
Open up the controller by removing any screws and plastic retention clips. Locate and remove the main PCB of the controller. You will see contacts on the PCB, which the joysticks or buttons on the controller touch to send signals to the integrated circuit (IC) on the board. Using a multimeter, you should be able to follow each contact to a pin on the main IC. On this controller there are four contacts, so four IC pins should be found and labelled.
STEP-02 Remove the main IC
The IC will probably be soldered to the PCB, so cut off all the legs with pliers and desolder all the legs from the board. Now is also the time to remove other large components from the PCB that may interfere with the placement of the Pi Zero. Remembering which pin hole connects to which IC, solder differently coloured wires to each hole and the other half of the contacts (which are usually connected via a common trace). It’s now time to prepare the Pi Zero.
STEP-03 Preparing the Raspberry Pi
Solder on only the first ten pins of a male GPIO header to the Pi Zero, so the serial pins are populated with connectors. Leave the rest of the GPIO holes unpopulated so you can solder on the pin connectors. Prepare a microSD card with Raspbian Jessie Lite on it, then connect to an HDMI monitor, mains power, and a keyboard to run raspi-config. Next, get the code from the GitHub repository and place it in your home directory.
STEP-04 Wiring up the Pi
If you are using the code without alterations, solder the contact for the forward position to GPIO 27, the backward contact to GPIO 22, the right contact to GPIO 23, and the left contact to GPIO 24. Connect the other half of each contact to a 3.3V pin. Bend over the wires so they are as flush with the PCB as possible, so you can still attach the Slice of Radio transceiver. Turn on the Pi and run the code; the HDMI monitor should display no signal, and the LEDs on the Slice of Radio should flash when you move the levers.
STEP-05 Running the code at boot
Edit the /boot/cmdline.txt file to include the line "init=/home/pi/filename-of-code.sh". Verify that the code is correct and chmod +x the script. This is your last chance to change anything – the Pi will not boot to a terminal again without manual editing of cmdline.txt. Disconnect your HDMI monitor and keyboard, then reboot the Pi Zero. The LEDs on the Slice of Radio should flash to show that data is being transmitted.
STEP-06 Fitting the Pi in the controller
You may have to use a Dremel tool or wirecutters/pliers to remove parts of the internal structure of the controller, so that the Pi fits. We had to remove most of the battery compartment. After fitting, check that all the wires are still securely attached to the Pi and the controller. Test the controller again, ensuring the LEDs flash. You’ve completed most of the controller, but if you have sufficient space available, continue to the next step to get rid of that annoying power cable.
STEP-07 Fitting the battery
Prise the two halves of the power bank apart with a knife or screwdriver. You should see a cylindrical battery and a small PCB with a USB and micro USB socket. Remove these from the housing and desolder the large USB socket from the board. Using a multimeter, find and label the positive pad that the USB socket was soldered to. Cut off the large USB plug from the micro USB cable, then solder the red wire to the positive pad and the black wire to a terminal of the switch. Connect the other terminal to the negative pad on the PCB. Make a hole in the controller for the micro USB connector and glue it in place. You’re done!
#!/bin/bash # put this code in /etc/rc.local to execute at boot mount /dev/mmcblk0p2 / -o remount,ro # prevent SD card corruption by mounting read-only mount proc /proc -t proc # as this is executed just after the kernel has finished booting, /proc doesn't exist. This creates it. tvservice -o # Turn off HDMI stty -F /dev/ttyAMA0 9600 # set the baudrate of the Slice of Radio gpio -g mode 27 down # configure internal pull ups gpio -g mode 22 down gpio -g mode 23 down gpio -g mode 24 down TTY=/dev/ttyAMA0 while true; do A=0 B=0 C=0 D=0 [[ $(gpio -g read 27) == 1 ]] && A=1 # forward [[ $(gpio -g read 22) == 1 ]] && B=2 # backward [[ $(gpio -g read 23) == 1 ]] && C=4 # right [[ $(gpio -g read 24) == 1 ]] && D=8 # left SWSTATE=$(($A+$B+$C+$D)) case $SWSTATE in 0) echo "aAASTOP-----" > $TTY # stop and center, as there is no input on any switch echo "aAACENTER---" > $TTY sleep 0.5 ;; 1) echo "aAAFORWARD--" > $TTY echo "aAACENTER---" > $TTY ;; 2) echo "aAABACKWARD-" > $TTY echo "aAACENTER---" > $TTY ;; 4) echo "aAASTOP-----" > $TTY echo "aAARIGHT----" > $TTY ;; 5) echo "aAAFORWARD--" > $TTY echo "aAARIGHT----" > $TTY ;; 6) echo "aAABACKWARD-" > $TTY echo "aAARIGHT----" > $TTY ;; 8) echo "aAASTOP-----" > $TTY echo "aAALEFT-----" > $TTY ;; 9) echo "aAAFORWARD--" > $TTY echo "aAALEFT-----" > $TTY ;; 10) echo "aAABACKWARD-" > $TTY echo "aAALEFT-----" > $TTY ;; *) echo "DEBUG: $SWSTATE" # print to a debug terminal if there is an unknown option ;; esac done