Introduction: Raspberry Pi 2 WiFi RC Car

Picture of Raspberry Pi 2 WiFi RC Car

In this tutorial we will go over how to convert an old RC car to work over WiFi or internet using Raspberry Pi 2. So you put geek hats on and lets get started. I have seen few RC Car projects on the web but they either were ESC (electronic speed controllers) based or 4 motor robotic type projects. This project uses 2 motors, one for throttle and the other for steer. You will be able to control this RC Car from any device (phone/tablet/laptop/desktop).

This is purely based on WebIOPi framework which provides easy HTML/JQuery based implementation to call Python scripts which contains the macros.

Step 1: Components We Need

Picture of Components We Need

Step 2: Wiring Pi and Components

Picture of Wiring Pi and Components

In order to correctly complete the wiring we need to understand the Raspberry Pi 2 GPIO pins which are used to connect various components to the Pi. These pins send the signals to the components connected, which could be turning on a light to driving a motor or reading data from a temperature or proximity sensor.

The ones highlighted in green are the 17 basic GPIO pins which is what we are going to use in our project. These pin can be configured in either input or output mode.

I connected the Anode (+ve) of 2 sets of LED’s for left and right turn signals with one 330Ω resistor each. Resistors help keep the amount of current passing through the LED’s at a correct level, otherwise you could burn out the LED very quickly.

Step 3: Connecting Pi and L298N Motor Drive Controller

Picture of Connecting Pi and L298N Motor Drive Controller

If you look at the above wiring you will notice that i connected the 9V supply to the L298N Dual H Bridge which will further power up the 9V Motors. Now, you may ask why do i need this additional component to power motors. Can I connect the motors to the Raspberry Pi GPIO pins? The answer is yes and no. The reason why we rely on a motor drive controller is because this can handle two motors up to 35V. Raspberry Pi only sends a maximum of 3.3V as its high signal. It not only provides enough power but controls direction and speed as i explained earlier.

L298N Motor Drive Controller Dual H-Bridge is the key component of my Raspberry Pi WiFi RC Car which powers all the motors and sends signal to controls the direction and speed of the motors. This controller can drive 2 motors with PWM (Pulse Width Modulation) signal. PWM in itself is a vast topic so we won’t cover it here. Think of this as a technique to control the amount of power going through pretty much anything you want.

Step 4: Software Required

Step 5: Installing Prerequisites

Format the SD card and install Raspbian Wheezy using Noobs or directly – https://www.raspberrypi.org/help/noobs-setup/

Update your Raspberry Pi using the script by Rob Seder

Install the WiFi adapter and connect to your wireless network

Now install WiringPi using the following commands

sudo apt-get install git-core
sudo git clone git://git.drogon.net/wiringPi
cd wiringPi
sudo git pull origin
sudo ./build

To use WiringPi to help you make proper GPIO connection type the following commands

gpio -v
gpio readall

To install WebIOPi type the following commands

$ sudo wget  http://sourceforge.net/projects/webiopi/files/Web...
$ sudo tar xvzf WebIOPi-x.y.z.tar.gz
$ cd WebIOPi-x.y.z
$ sudo ./setup.sh

Step 6: Confgiuring WebIOPi and Weaved

The basic configuration required is to tell where our custom python script will reside which can be done by editing the config file under HTTP section using the following command.

$ sudo nano /etc/webiopi/config
//Edit this section of the config, mainly the doc-root and welcome-file attributes. [HTTP] enabled = true port = 8000 doc-root = /home/pi/picar welcome-file = index.html


To start webiopi service with verbose output and the default config file. This is recommended when developing and debugging your scripts.

$ sudo webiopi -d -c /etc/webiopi/config

You can also start/stop the background service, the configuration will be loaded from /etc/webiopi/config.

$ sudo /etc/init.d/webiopi start
$ sudo /etc/init.d/webiopi stop //To check if the service is running or not $ sudo /etc/init.d/webiopi status


Once you are done building your project you should put this service to auto start when the Pi boots. To manage service at boot here are the commands.

//To setup your system to start webiopi at boot:
$ sudo update-rc.d webiopi defaults //To remove webiopi start from boot: $ sudo update-rc.d webiopi remove

Step 7: Building User Interface

Picture of Building User Interface

To access the pi over local network open a browser and navigate to http://ipAddressOfPi:8000/ from any device in your network. Make sure to type the ip address of the Pi in the url. Default user “webiopi” and password is “raspberry“.

UI is pretty much a basic HTML page with images mapped for directions and stop commands that are wired to the onmousedown event. Those events are then mapped to the python macros which are exposed by the webiopi framework.

Step 8: Conclusion

I hope you enjoyed this tutorial and will try to build something interesting. Let me know what you think about this project. Further I plan add the following features to this project.

  • Adding Telemetry Support – includes reading temperature, speed of the motors, real time battery status
  • Low Battery Notification
  • Integrate Pi Camera Module
  • Remove UI lag and make it more responsive
  • Allow Device Accelerometer

Comments

Dabnug (author)2017-10-03

I cannot get the custom HTML page to load. Was getting some compatibility errors from the python script when I loaded the verbose webservice, so I stripped the python script down to basics, the errors went away, but the HTML page still will not load.

My config file has saved into two versions, config and config.save. I updated both with the path for the python script and the HTML page. I tried both standard and fully qualified path. No success. I do not have my files in the same folder as the example solution specifies.

Is there somewhere else that references the path that I am missing?

Do we need a def destroy(): in the python script?

Dabnug (author)Dabnug2017-10-06

Found it. The default page will load when you browse IPADDRESS:8000 because that is what the webservice provides at that path. You will need to reference the actual path in your file browser to the HTML file you wish to load.

ie. 192.168.0.111:8000/myCar/project/HTML/

Dabnug (author)2017-10-03

also, the folder name I created originally had a space. I used "rename" in the file browser to remove the space, but I am wondering is there is some aliasing for the UI that is causing the path to the HTML file to not be found?

junhyoung (author)2017-08-30

i install & starting webiopi. but when i connected Webpage, This phenomenon occurs. I definitely put a png files in /home/pi/picar . please help me ..

Dabnug (author)junhyoung2017-10-03

Open your HTML file and fully qualify the image path. I was able to get the images loading locally. But the layout is off, each of the 3 buttons from teh center row appear left justified on individual lines.

UzayerM (author)junhyoung2017-09-08

I have this same problem as well!

AndrewB201 (author)2017-08-15

Getting this error, where are the macros supposed to be located?

jquery.js:4 POST http://192.168.1.108:8000/macros/ButtonTurnRight/... 404 (ButtonTurnRight Not Found)

TháiN18 (author)2017-06-27

Very cool but Connecting Pi and L298N Motor Drive. Board in picture very different with board L298N. Can you help me connect ?

CodeRewind (author)TháiN182017-06-28

That is correct as the tool i used to design the circuit did not have that exact model but the concept is the same. Let me know.

TháiN18 (author)CodeRewind2017-07-01

I am having same point don't understand with this image. I try your code with. IN1: pin 7, In2: pin 11, ENA: pin 29, IN3: pin 13, IN4: 15, ENA: 31 and don't have a pin for LED. I try with default WebIO web it can controll motor. But when run your code it not work. I already change pins in piCar.py

eddyuhl (author)2017-03-29

Hi,

i try to realize that project, but i have a problem. I
have installed the software and changed the config file. I also can
reach the webinterface. I now try to measure some signals at the pi gpio
when i hit any button on my smartphone but nothing happens. When i
start Webiopi by "sudo webiopi -d -c /etc/webiopi/config" i can see that
a button was pressed but then it shows an error "post
/macros/buttonStop/ HTTP/1.1"- 404 not found.

the picar.py and index html are in "/home/pi/picar".

Please help me whats wrong?

CodeRewind (author)eddyuhl2017-06-28

I am not sure but it could be a path issue. Are all the dependancies installed?

CarlosM175 (author)2017-05-22

Amanhã já vo tentar criar o meu próprio RC

CodeRewind (author)CarlosM1752017-06-28

Did you try to create this? How did it go?

adashh (author)2016-06-03

hey are the connections to Rpi3 same too as of Rpi2 which you used? i m trying to make the same using Rpi3 !

CodeRewind (author)adashh2017-06-28

It should be the same. But you should refer to the pin diagram for Pi 3 to make sure.

firedl (author)2017-05-07

hi what HTML editor did you use there are none installed on my Pi 3 can you help?

CodeRewind (author)firedl2017-06-28

If you are on Raspbian you can use LEAFPAD. But i usually write my code on my PC using Sublime Text and then move the file to the Pi box.

ahhzhe (author)2016-05-09

Hi, thanks for posting this out, it really helps. Btw i wondering how the power supply will able to distribute the power to 2 DC motor with different voltage of power? Is L298N handle it automatically ? Example, 1 DC motor with 3v and 1 DC motor with 9v...Appreciate if you could answer my doubts..

CodeRewind (author)ahhzhe2016-05-10

I am glad it helped. Yes, this is where L298N can be handly, It will deliver the required power needed for both motors as far as i understand.

CarlosA115 (author)2015-12-02

Hi! Thanks so much for posting this up! I'm relatively new to the RPi so I'm sorry for what may be simple questions. But the source forge link url is not working for me when I download from it using sudo wget. I found a way to download it through the mirror link url that I copied upon actually clicking and looking around the link you provided, but I'm not sure if that was the proper way to do it. Is it fine so long as I have a "working" WebIOPi directory in my home/pi/ directory? Also, my rc car only has a 7.5 v battery pack, will that suffice? And my last question, how do I properly download your PiCar script onto my Pi and where should I put the python script that's in the folder? I found a way to do it, googling around, but I'm not sure it was the best way or if I placed it in the right location. I was able to access the html page you made remotely through the ip address link but are there things I should change in the code to get it to actually connect to the gpio? Once again, I apologize for the barrage of what may be obvious. I will appreciate any help you can give me. Thanks again!!

CodeRewind (author)CarlosA1152015-12-09

I actually use a 5V out battery pack for powering the Pi board. And a separate 9V drives the RC.

Yash Sorathiya (author)2015-12-09

Hi Carlos! Nice to meet you!!! I'm too new to the rpi 2 and I am trying to make this project from this guide. I know your problem. Well your 7.5v battery pack is fine but its on how much voltage it gives as the specific amount of output from the use. I mean that Pi only uses 5v so if you want to check the output, you shall see the back of the box of your battery pack also if you want to easily access the "Pi Car" script, you shall better put it on the desktop. To activate the script, I select it from the desktop(I write the steps of opening and running the script on a paper as I only use a keyboard handy and I cannot remotely access the Pi's desktop environment with my Tab to use it as a display ;) ) I had some problems doing this earlier but this is probably one of the best ways to run the script. Okay guy, SMELL YA!! ;)

Yash Sorathiya (author)2015-11-30

Hey Bro, I've got a problem on another subject. I want to use my android tablet as my pi's display. I followed many guides but none worked.Could you please tell me if I can use an hdmi to micro usb? please tell me.

CodeRewind (author)2015-11-06

You can use a 2600mAH battery also, since this battery will only be used for powering the Pi, it depends on how much Pi can run. Motor drive controller user a separate battery bank which is located underneath the car in my case.

CodeRewind (author)2015-11-05

Thanks Yash. Let me know how it goes.

JoePalazzolo (author)2015-10-25

Very nice. A great use for that "old" RPi Model B I have sitting around. Looking forward to your integration of the camera module.

seamster (author)2015-10-15

Very cool, thanks for sharing how to do this!

CodeRewind (author)seamster2015-10-15

Thanks seamster!

About This Instructable

29,353views

79favorites

License:

Bio: I am a .NET Developer, Tech Entrepreneur @CouncilSoft and Blogger @CodeRewind which is a place for developers, designers and tech enthusiasts who wants to keep ... More »
More by CodeRewind:Raspberry Pi 2 WiFi RC Car
Add instructable to: