Introduction: Raspberry Pi Smartphone Controlled Rc Car

Use your raspberry pi to control a 1/10 scale RC car via a web page hosted wirelessly on your PI. All you need to do is set up your PI to use your mobile as a hotspot then log onto the appropriate web page (hosted by the Pi) and tilt your phone to control your car like a Wii Remote. I've used an old Tamiya hornet in this example; any car will do but if you are buying one try and get one with enough space under the bodyshell to fit all your electronics. This is a fork of an existing github project that I've modified to make easier to install and to get rid of some components. It's also possible to add a video camera but I didn't do this.

The main project page is hosted here if you need more information:

https://github.com/lawsonkeith/picar

There's a video of the project here:

Step 1: Step 1 Measure Servo Signal Levels.

We'll be using PWM to control the servos which will be capable of driving 0-3.3V in 3.3mv steps; it is therefore necessary first to measure what your servo command signal voltage levels are and check they fall within this range. You can do this with a multi-meter connected to the receiver pins. On my car speed and steering both use 3 pin headers which are wired:

  • Gnd - Black
  • Power - Red
  • Throttle / Steer - Orange or White

For my car the throttle voltages were:

  • Full Fwd: .19
  • VIdle: .28V
  • Full Reverse: .36V

The steering voltages were:

  • Full Left: .19V
  • Fwds: .28V
  • Full Right: .355V

Once you are happy about how you are going to power your PI and that the GPIO are up to the job you can start thinking about wiring it up.

Step 2: Step 2 Wire Up Your Car

For the servo 3 pin headers I used 2.54mm PCB header and soldered wired direct. I then used superglue to stop the pins moving about. You'll also need heat-shrink or equivalent to cover over the solder joints. To power the PI I chopped a micro USB cable and used the black and red wires from that as my 5V supply. For my linear power supply I used an LM7805 circuit and put a heatsink on it to keep it nice and cool.

I then attached a PP3 battery clip and 6xAA pack with a PP3 connector on it. I've also used a 26w header socket to attach to the raspberry PI GPIO lines; I like this method as it means it's hard to mis-wire when re-connecting plus you can quickly remove you Pi as required.

Note - See the github page for details on running without the extra battery pack and linear regulator.

Step 3: Step 3 Check Everything Fits in Your Car

The Pi Is placed in a plastic bag for protection; it's worth putting piece of card underneath it to make sure the PCB doesn't poke through the plastic.

Step 4: Step 4 - Setup the Pi Software

The Pi uses node.js to run a web server; a wi-fi dongle on the PI uses your phone as a wireless hotspot to enable wifi communications. Once you enter the web address of the PI a dialog box appears prompting you to begin racing; at that point you can control your car by tiliting oyur phone. An emergency stop is built into the app so if it loses comms to your phone the vehicle stops accelerating and steers forwards. The Pi-Blaster program allows pins 17 and 18 of the PI to act as PWM outputs and control steering and throttle.

The app runs on raspbian using a raspberry PI rev B although you could use the A model. To setup your Pi you need to download some software packages then setup your Pi to run the node.js program on boot.

Step 5: Step 5 Download Required Packages

Get the app

First we need to clone the app from github and place it in it's own directory.

  • [cd /home/pi]
  • Get this project from GITHUB.
  • [sudo git clone https://github.com/lawsonkeith/picar]
  • [cd picar]
  • Note - do everything in this dir from now on unless instructed otherwise.

Download node.js

Download a new version of node.js

  • [sudo wget http://nodejs.org/dist/v0.10.21/node-v0.10.21-linux-arm-pi.tar.gz]

  • Then unzip it.
  • [sudo tar -xvzf node-v0.10.21-linux-arm-pi.tar.gz]
  • [sudo rm node-v0.10.21-linux-arm-pi.tar.gz]
  • Create symbolic links to the node executables
  • [sudo ln -s /home/pi/picar/node-v0.10.21-linux-arm-pi/bin/node /bin/node]Package manager
  • [sudo ln -s /home/pi/picar/node-v0.10.21-linux-arm-pi/bin/npm /bin/npm]

Download additional node packages

Next we use the node package manager (npm) to install some packages that we are going to use in node to give us the functionality required to control our RC car.

  • [sudo npm install socket.io node-static sleep optimist pi-blaster.js]

Step 6: Step 6 - Setup PWM

Setup the pi to boot to command line

You will want to not boot to the windows environment because the PWM library can interfere with it. If you do need to use the desktop you can always start it with the command

  • [startx].

Download PI Blaster soft PWM daemon

The Pi blaster node library also requires a daemon to be downloaded that runs in the background and runs the PWM. Have a look at [https://github.com/sarfata/pi-blaster.js/] to get some more info about this package.

  • [sudo git clone https://github.com/sarfata/pi-blaster]
  • [sudo apt-get install autoconf]
  • [cd pi-blaster]
  • [sudo ./autogen.sh]
  • [sudo ./configure]
  • [sudo make]
  • [sudo make install]
  • [cd ..]

Note - you will want to be able to stop the daemon; see note at end.

Setup your PWM defaults

I've included a node script file called pwm_test2. To run this you enter:

  • [node pwm_test2]

We are now going to integrate the pi int the RC car and check we can control the servos. You can either connect your Pi to your TV and a keyboard or setup vpn or ssh to do this.

The pi-blaster node setPwm() API requires a pin and demand parameter. For example setPwm(17,.5) would set ppin 17 to 50% PWM demand or 3.2/2 V.

First off make sure you are happy with how the API works and make sure you can set the output voltage on pins 17 and 18 using a meter. Once you are happy with this you can connect up your steering servo and work out the constants you Need to send to get it to steer left; right forwards and backwards. Make sure that when you go full left or Right that the servo isn't over driving as you can damage the servo. Do the same with throttle; the demand magnitudes should be the same so it should be just a case of proving the Wiring and signal directions.

You should now be fairly confident about controlling the servos and powering your pi from the RC platform. Just modify what's in 'pwm_test2' and keep running it till you are happy with how it all works. Enter your platform specific constants into the 'readme' file; we'll use them later to do some scaling.

Step 7: Step 7 - Setup Your Phone

Configure PI to use Smartphone WiFi

We now need to set your Pi up to use your phone as wifi.

  • On your phone enable the wifi hotspot option.
  • On your Pi disable the existing WiFi option and connect to your phone.
  • You may need to enter a network key to do this; this will be in your phone somewhere.
  • Check it all works by accessing the internet from your Pi.
  • Reboot your Pi and check it still all works.
  • You are now going to set your Pi IP address to static.
  • Enter [ifconfig] write down your IP address for wlan0.
  • Edit your network setup file [sudo nano /etc/network/interfaces] file and set to to the current wlan0 IP address and from dhcp to static using the 'interfaces' file in this project as an example.
  • Reboot the Pi and check all still works; your IP address will differ.

Setup your smartphone defaults

With the Wifi Setup you can now test out the phone.

  • [node app.js]

Navigate to http://PI_IPADDRESS:8080/socket.html on your phone.A message comes up and asks you to race.On the Pi you should see the values being sent to the setPWM API by the web page running on your Pi.If these work; great you can skip the next step.Setup html file for your setup You may need to setup the scaling specific to your platform...

  • In socket.html comment out the min and max gamma if statements.
  • Also comment out the scaling M and C terms so the event.beta and event.gamma numbers are sent to the Pi.
  • Run up your app [node app.js] and make a note of the raw numbers in the specific orientation you want to use your phone in.
  • The numbers are degrees; in my example I tilted +/- 30 degrees to steer and 0 was full fwds and 60 full reverse.
  • Put your numbers in the readme file
  • Using excel or a calculator work out the constants you need to use to convert your phone tilt values into the setPWM API demands required to control your car.
  • Comment out the min max demands if construct and enter your specific min max constants at the top.
  • Now edit app.js.
  • In the emergency stop function enter the values for steering and throttle that stop your Pi.Now run up the app a few times and convince yourself it's all working.

Step 8: Step 8 - Set App to Auto Run

Configure PI to run node app by default

We now need to configure the app to run as default when we power up the Pi. [sudo cp node-server.sh /etc/init.d/][sudo update-rc.d node-server.sh defaults]Reboot your Pi and check you can log onto the web page. You should now be ready to race.

Issues

PiBlaster can cause issues with the Pi windows environment; mine kept crashing when I moved them when it was running. If you stop running it the problem will go away.

  • [sudo /etc/init.d/pi-blaster stop]

Once you're sick of this project you can uninstall it using:

  • [cd ~/picar/pi-blaster]
  • [sudo make uninstall]

For more command info see the 'readme' file.

Comments

author
Deiv1100 (author)2017-05-18

Hi,

it looks very interesting, i tried it, but.. when i started app.js, i only recieved tis error: http://www.imgup.cz/images/2017/05/18/IMG_20170518...

What to do with it?

Thank you.

author
Deiv1100 (author)2017-05-04

Will it work with RPi Zero? Thanks in advance.

author
grahamnewman (author)2016-06-17

Ah so close! I got down to:

pi@picar:~/picar/pi-blaster $ sudo make install
make[1]: Entering directory '/home/pi/picar/pi-blaster'
/bin/mkdir -p '/usr/sbin'
/usr/bin/install -c pi-blaster '/usr/sbin'
/bin/mkdir -p '/lib/systemd/system'
/usr/bin/install -c -m 644 pi-blaster.service '/lib/systemd/system'
make install-data-hook
make[2]: Entering directory '/home/pi/picar/pi-blaster'
systemctl enable pi-blaster
Created symlink from /etc/systemd/system/multi-user.target.wants/pi-blaster.service to /lib/systemd/system/pi-blaster.service.
systemctl start pi-blaster
Job for pi-blaster.service failed. See 'systemctl status pi-blaster.service' and 'journalctl -xn' for details.
Makefile:846: recipe for target 'install-data-hook' failed
make[2]: *** [install-data-hook] Error 1
make[2]: Leaving directory '/home/pi/picar/pi-blaster'
Makefile:771: recipe for target 'install-data-am' failed
make[1]: *** [install-data-am] Error 2
make[1]: Leaving directory '/home/pi/picar/pi-blaster'
Makefile:719: recipe for target 'install-am' failed
make: *** [install-am] Error 2

Sorry to bug you!

author
lawsonkeith (author)grahamnewman2016-06-20

Hi

Look at:

https://github.com/sarfata/pi-blaster

Check what you need

You on a debian based package? Also note you need autoconf to build it.

Keith

author
grahamnewman (author)lawsonkeith2016-06-24

Hi Keith,

We used autoconf and nearly got there, however these errors still appeared:

make install-data-hook
make[2]: Entering directory '/home/pi/picar/pi-blaster'
systemctl enable pi-blaster
systemctl start pi-blaster
Job for pi-blaster.service failed. See 'systemctl status pi-blaster.service' and 'journalctl -xn' for details.
Makefile:846: recipe for target 'install-data-hook' failed
make[2]: *** [install-data-hook] Error 1
make[2]: Leaving directory '/home/pi/picar/pi-blaster'
Makefile:771: recipe for target 'install-data-am' failed
make[1]: *** [install-data-am] Error 2
make[1]: Leaving directory '/home/pi/picar/pi-blaster'
Makefile:719: recipe for target 'install-am' failed
make: *** [install-am] Error 2

Thanks - Graham

author
RussellW25 (author)2016-06-23

I have four questions:

1. Would it be possible to modify this for control from a computer using arrow keys and on screen buttons?

2. Could you run this on a server and access the car from anywhere with a wifi/data connection?

3. Could you have a live feed from a raspberry pi camera on the website?

4. Is this compatible with raspberry pi 3?

Sorry for the barrage of questions. If you do respond, thanks!

author
grahamnewman (author)2016-06-13

Hi Keith. I have followed your instructions to the letter. All good until I get to running the node 'pwm_test2' bit where nothing happens :( I have the GPIO pins on 17 and 18 with a RPi2 + Jessie. Any help sincerely appreciated mate, there are two little boys itching to go out and play with this Tamiya Mad Bull!

author
lawsonkeith (author)grahamnewman2016-06-13

Hi

Did you install the PWM daemon?

Try and get a multimeter and on the command line just make yourself happy the pwm works.

It's the pins referenced to zero. I had an early pi I'm not sure if that changes the pinouts?

Also I think you can control the GPO on the command line:

echo "17=1" > /dev/pi-blaster

to debug.

author
grahamnewman (author)lawsonkeith2016-06-17

Still struggling I'm afraid. Do you have a
.iso that we could reverse engineer? Sorry to be a pain!

author
GaryS125 (author)2016-03-01

this is wild. is there tech like that where I can control the rc car from anywhere in the world via my smart phone as long as the car and the phone are connected via the web?

author
odaniel petru (author)2014-10-04

Awesome project! is it possible to have the soft for the sd card ready made as an .iso or .rar ? i'm zero in therms of programming but i'm good at the hardware

author

Hi I'll look into this; to be honest the setup of the SD card is a bit of a mare. I'll try and gt something uploaded within a month?

author
kaiga (author)lawsonkeith2016-02-19

any update? Im having trouble with the latest Raspian release Jessie lite.

author
LarsW9 (author)2015-09-20

Hi,

great work i love this project and i want to install it in our Kids RC Car

but if i start the "app.js" i got no input from my iphone 5s on 8.4.1

one time i forgot in the "pi-pblaster" dir the "make install" command at this time i got the phones input on pi.

author
revanthk (author)2015-02-07

how can we get to know which pin on the car will lead us to a particular direction? I suspect this wont be the same for all rc cars? Is there a way we can get the documentation for the car we are buying? If so where? Thanks in advnace.

author
lawsonkeith (author)revanthk2015-02-08

Hi

Also you can play with a multimeter and see what happens when you go fwd/back etc. It needs to be within 0-3.3V as the pi can only PWM this range without additional electronics.

author
lawsonkeith (author)revanthk2015-02-08

Hi

Basic procedure is to play around. There's a shell script that sets the PWM output; if you use it to first calibrate the steering; this is the easiest one to set as the wheels aren't spinning around. You can use the same numbers for the throttle.

It's easy enough to edit the shell script in nano and quickly run it ; have a look at pwm_test2 in my github page, open it up you'll see what I mean check out the readme there's a section on it.

author
navneetcsgowda (author)2014-12-19

ll u post a video on how to connect yr phone to RPi

author

Hi; I'll look into it in the new year. It's not that straight forward as you have to use DHCP to connect to your phone; In the example text I then set this IP to static so I knew what IP address it would be on. Thinking about it it may have been better to leave it as DHCP then use SSH ans ifconfig to get the address of the PI. This way you'd be able to connect to different devices a lot easier. The static method only relally works for whatever IP range your phone is on.

author
navneetcsgowda (author)2014-12-19

plz mention the name of the app used to control it

author

Hi you use a web browser; there is no app to control it as such it hosts a web page, you view it on your phone then the web page uses the phones accelerators to control the car over wifi.

author
Spencer Snider (author)2014-11-28

What is the range on this?

author

Hi

10-20m outdoors depending on your phones wifi power.

Keith

author

Awesome project! you should enter it in the remote control contest! https://www.instructables.com/contest/rc2014/

author

I did unfartunately it didn't win anything : (

author
wbannister (author)2014-08-03

what rc Car is that?

author
lawsonkeith (author)wbannister2014-10-07

Hi it's a Tamiya Hornet.

About This Instructable

114,489views

83favorites

License:

More by lawsonkeith:DIY Christmas decorations with the kidsProtobot - Raspberry Pi + Wifi + Xbox + IMU + PicameraArduino & MPU-6050 IMU controlled Bee Bot / Big Trak clone
Add instructable to: