Sunday, 11 October 2015 11:27

Wi-Fi controlled Remote Control Car without microcontroller

Wi Fi controlled Remote Control Car without microcontroller

This is a Wi-Fi controlled remote control car with camera that can be driven over the internet. The RC car is very unique since it's using a wireless router and eliminate the need of a microcontroller.

Car Structure

  • This is a two wheels drive RC car
  • An universal wheel in the front.
  • Two wheels and the car motors on the back.

Car Structure

 

Materials

 Materials

 

Block Diagram

As shown in block diagram, everything is controlled by a wireless router, the webcam is connected to the wireless router via USB port that allows live streaming video, the motor controller board is connected directly to the router via GPIO in order to control the motors without the use of a microcontroller.
Wi Fi car block diagram

 

Wireless Router

I chose the GL.iNet 6416A for this project because it is an extremely small wireless router (dimension: 58*58*22mm), the 5 GPIOs & serial port are all easily accessible via though holes or headers.

GL.iNet 6416

GL.iNet GPIOs

All other wireless routers supporting OpenWrt should work fine provided there is enough space in flash, you can find a list of supported router models on OpenWrt's website.

Most of the wireless router may not have enough GPIO to control the motors, however, you can use other pin on the router such as the LED pin, this require to unload the leds_gpio module or this way to control LED manually.

 

Webcam

I do already have a Microsoft HD-5000 webcam, it’s capable of capturing video up to 1280x720 pixels. The auto-focus was really getting annoying and I do not want autofocus in a car, so why not disable this feature (see here).

Microsoft HD-5000 webcam
Those USB webcams that are UVC compliant should work for this project.
 

Motor Controller Board

A motor may require significantly more current than the wireless router can provide, it may damage your router if you control the motor without a H-bridge. Hence the L298N Motor Driver Controller Board Module is used in this project in order to control the direction & speed (see PWM) of two DC motors.

I found out that there is about 1.5V voltage drop between the input voltage and the L298’s motor outputs.
L298N Motor Driver Controller Board
 

Multifunctional DIY DC to DC Converter Auto Step - Up Step - Down Boost Buck Solar Power Supply Module

This is a buck–boost converter that has an output voltage magnitude that is either greater than or less than the input voltage magnitude.

Comparing with linear regulator, dc-dc converters primarily strive for efficiency, it can deliver efficiencies greater than 95% while boosting and hence reducing power consumption.

Here is a simple test for the module. I set the module output to 5V and feeding 2V-24V to its input, no matter the input voltage is higher or lower than 5V, I always get a very stable 5V except the input is lower than 2.6V.

dc dc converter

 

Car Chassis Kit

Chassis is made from acrylic material, size(L x W x H) 19.8 x 14.0 x 6.5 cm which is smaller than expected, I ended up spending hours and scratch my head on how to fixed all the gadgets/modules/devices onto the chassics.

The kit included two deceleration motors, two plastic wheel, a battery holder for 4xAA batteries, and there are also two speed encoder which I'm not using.

The motor power supply is 3V-12V according to the product description given by Gearbest.com, following is the additional specifications getting from internet.

  1. Recommended operating voltage of about 6 to 8V
  2. Maximum torque: 800gf cm min @3V
  3. No-load speed: 1:48 @3V
  4. Load current: 70mA (250mA MAX) @3V

Something very interesting, the two deceleration motors is small but it is very strong that can push and move a placstic chair.

Car Chassis Kit

 

Batteries and voltage supply

I'm using 4 pcs 3.7V 18650 Li-on Rechargeable Batteries, 2 pcs connecting in series and the other 2 pcs connecting in parallel yielding 7.4V (full charge = 8.4V). Charging or using the batteries incorrectly may cause explosion or fire, therefore I suggested to use the batteries with built-in protection circuits.

Li on battery

The RC car may require two different voltage supplies depend on the input voltage of motors, the 5V goes to the wireless router and the other voltage supply goes to the motors.

Before building the RC car, I order a Double USB Voltage Step Down Regulator Module as shown in figure below and a DC to DC Converter (Auto Step-Up & Auto Step-Down) (Auto Step-Up & Auto Step-Down). The Double USB Voltage Step Down Regulator Module provide a constant 5V to the wireless router and webcam via a USB cable, while the DC to DC Converter required to adjust its output voltage before power the motors.

Double USB Voltage Step Down Regulator Module

During testing, I found out that the input voltage of the motor must not exceed 5V, otherwise the RC car is running too fast or in worse case the power is shut down automatically (battery protection circuit triggered).

Based on the results of the experiment, I only need a DC to DC Converter that the output voltage is adjusted to 4.5V, while the Double USB Voltage Step Down Regulator Module is not using in this project. Therefore the wireless router & webcam is running on 4.5V, and the two motors is running on 3V (4.5V-1.5V voltage drop, see here).

 


OpenWrt - a Linux distribution for your router

The GL.iNet wireless router comes with OpenWrt Barrier Braker pre-installed, it includes their newly designed easy to use web interface for configuring the router. Navigate to http://192.168.8.1 & login to the router, the GL.iNet web interface should appear on the screen.

GL.iNet main menu

You can click on the Advance Settings (or navigate to http://192.168.8.1/cgi-bin/luci) in order to open the traditional Luci Web Interface.

Luci Web Interface

I'm faced with a problem that the video streaming is not working without login to the router, for this reason I have to download the image file from OpenWrt website and flash it to the router.

If you do not already have a OpenWrt firmware on your router, please refer to this tutorial for instructions on how to upgrade the firmware.

 

Network and Internet Connection

The router need to have internet connection in order to perform the package installation. Check this tutorial out, it gives you a detailed guide to setting up network and internet connection for your router. Additonal it shows you how to create a new virtual interface (SSID) that allows your computer/notebook/smartphone connect to the router.
Wireless_Bridge

 

Installing packages - Install Additional Software On Router

By default, OpenWrt includes standard software that lets the router create wireless network or join existing ones, it would require to install additional software on the router which is currently not included. Steps below show you how to install all the software needed by webcam, you can skip this section if you don't have a webcam or you don't need video streaming.

  • SSH to router and execute the command line by line, preferred PuTTY.
    PuTTY
  • You must download the current list of packages available from local package repositories before you can install packages onto your router.
    opkg update #update list of available packages
  • Set Up a Web Camera, please read this turotial for more info.

    opkg install kmod-video-uvc #UVC camera driver
    opkg install mjpg-streamer #stream JPEG files over an IP-based network

  • Edit the file /etc/config/mjpg-streamer in order to enable video. I'm using WinSCP to edit file.

    config mjpg-streamer core
       option enabled "1"
       option device "/dev/video0"
       option resolution "640x480"
       option fps "10"
       option www "/www/webcam"
       option port "8080"

  • Require to install uvcdynctrl if you want to disable/enable auto-focus.
    opkg install uvcdynctrl
  • Require to install lsof if you want to get the webcam status.
    opkg install lsof
  • Start video on router reboot.
    /etc/init.d/mjpg-streamer enable
  • Reboot the router and you are ready to stream.
  • Command below will temporary disable auto-focus. You should disable auto-focus on startup (see here).
    uvcdynctrl --set='Focus, Auto' 0
  • Getting webcam state via lsof command
    lsof /dev/video0

 

 

Disable auto-focus on startup

Save the following code to /etc/init.d/disableAutoFocus. Please click here for more information about Init Scripts.

#!/bin/sh /etc/rc.common

START=99
STOP=15

start() {
uvcdynctrl --set='Focus, Auto' 0
}

stop() {
uvcdynctrl --set='Focus, Auto'
}

  • Set file permission to 0755, you can also use WinSCP to changing permission.
    chmod 0755 /etc/init.d/disableAutoFocus
  • Disable auto-focus when needed
    /etc/init.d/disableAutoFocus start
  • Enable service autostart
    /etc/init.d/disableAutoFocus enable

 

 

Schematic

wifi car schematic

 

Source Code

The core code for this project is written in Lua scripting languages, while the web interface is written in html and javascript. All the files are packed into a single zip file which is available here.

Lua is an interpreted language, a change in a script will not necessarily require a rebuild of the entire project, its code is executes immediately after you have saved it, and therefore it is easier to update and maintain. Please read the following Lua files for those interested in seeing how it works.

  • /usr/lib/lua/gpio.lua
    GPIO's read/write function for router, more information is available here.
  • /usr/lib/lua/2w_motor.lua
    Work with gpio.lua in order to control 2 DC motors, more information is available here.
  • /www/cgi-bin/control
    A program that acts as an interface between browser (web page) and router.

 

As mentioned above, the web interface is written in html and javascript. Please study the following files for those who wants to develop their own interface (GUI).

  • /www/car/index.html
    The main program, load the external js & css files and implement image onClick events.
  • /www/car/pantilt.html
    The main program, bigger video size.
  • /www/car/car.css
    Layout options such as image postion, colors, and fonts.
  • /www/car/car.js
    Consists of javascript function.
  • /www/images
    A folder consists of the images which shows on the web page.
  • /www/codebase
    Consists of javascript components to create slider (dhtmlxSlider), more information is available here.

 

Software Installation

The software do not need installation, make sure you have transfer them to the correct folders on router. I'm using WinSCP to manage files and folders.

WinSCP is a SFTP/FTP/WebDAV/SCP client for Microsoft Windows that allow you to transfer files and manage folders between computer and router. 

WinSCP

Assumes you already have WinSCP running on your computer and are connected to the router. Now extract the downloaded file (2W_WiFi_car.zip) to your computer and transfer them to the respective folders on router as shown in figure below.

Files and folders tree view

The /www/cgi-bin/control file require execute permission, please change its permission to 0755 (rwxr-xr-x) as shown in figure below. Please refer to WinSCP on how to changing permission.

Change file permissions

 

 

PWM - Speed Control

GL.iNet wireless router use Atheros AR9331 CPU and it doesn't have hardware PWM, the only way to implement PWM is through adopt software PWM. 

Kernel after 3.14 , OpenWrt such as Barrier Breaker and Chaos Calmer has dropping support for PWM over gpio, therefore you must compile your own OpenWrt firmware in order to enable the software PWM feature.

I'm trying to follow this tutorial and compile the OpenWrt firmware successful, when I upload the compiled image to the GL.iNet router, it bricked my router (the network interface is not working). Lucky it is recovered easily.

I've been playing around with the gpio-pwm-ar9331, I downloaded the precompiled ipk file and uploaded to my router, but it failed to install with the following errors:

Installing kmod-gpio-pwm-ar9331 (3.10.49-1) to root...
Collected errors:
* satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-gpio-pwm-ar9331:
* kernel (= 3.10.49-1-69f3c9d824d79ff97e8c05f8219a41f3) *
* opkg_install_cmd: Cannot install package kmod-gpio-pwm-ar9331.

Moreover, i recompiled the gpio-pwm-ar9331 from source, this time it can install onto my router, unfortunately it is not working.

I found out a tutorial related to software PWM that is not fully tested yet. It is now compiled succesful for my router. Hopefully it can run without any problem.

At the moment, the PWM is not working for my router, hopefully this will get fixed on the next few week. If anyone has any idea how we can fix this, please let me know.

 

Controlling the car

You can control the car from a web browser (do not use Internet Explorer, recommended Google Chrome) or Android application.

  • Open up a browser and navigate to http://routerIP/car/ (eg. http://192.168.8.1/car/) or http://routerIP/car/pantilt.html
    Web interface
  • Click on the images or use  a keyboard to control the car
  • Keep pressing a key on the keyboard will keep the car running, release the key will stop the car.

 

Keyboard shortcut

Keyboard Function Command
8 or Up arrow Move forward routerIP/cgi-bin/control?RUN=8
2 or Down Arrow Move backward routerIP/cgi-bin/control?RUN=2
4 or Left Arrow Move left routerIP/cgi-bin/control?RUN=4
6 or Right Arrow Move right routerIP/cgi-bin/control?RUN=6
5 or Space Stop routerIP/cgi-bin/control?RUN=5
7 Enable/Disable webcam routerIP/cgi-bin/control?CAM
9 Headlight ON/OFF (use GPIO20) routerIP/cgi-bin/control?LED=20
1 Horn (not implemented) routerIP/cgi-bin/control?SPK
3 Enable/Disable mic input (not implemented) routerIP/cgi-bin/control?MIC
Q Speed 1 (lowest speed) routerIP/cgi-bin/control?SPD=40
W Speed 2 (low speed) routerIP/cgi-bin/control?RUN=60
E Speed 3 (high speed) routerIP/cgi-bin/control?RUN=80
R Speed 4 (full speed) routerIP/cgi-bin/control?RUN=100

 

I'm Wi-Fi RC Car

My name is Wi-Fi RC Car, I was born in Malaysia on Oct 2015. I can run, I can see, I'm strong, I'm handsome, please try to knowing me, I'm sure you love me.

Wi Fi car 1

Wi Fi car 2

Higher resolution images available on Flickr

Read 5620 times Last modified on Sunday, 12 June 2016 10:19

4 comments

  • Comment Link admin Sunday, 15 January 2017 10:58 posted by admin

    Yes, there is only one speed. The speed is depend on the voltage apply on the L298N Motor Driver Controller Board. The higer the voltage, the faster the speed, make sure the voltage deliver to the motors did not exeed its voltage limit.

    Please read this article for more information about L298N Motor Driver Controller Board:
    http://ediy.com.my/blog/item/129-l298n-motor-driver-controller-board

    I'm supplying 5V to the L298N Motor Driver Controller Board, you can see the car moving speed from the youtube video.

  • Comment Link Paul Hogan Sunday, 15 January 2017 03:26 posted by Paul Hogan

    Thanks for the reasons, so does that mean their is only one speed? And if so, how fast is that?..Thanks again..Paul.

  • Comment Link admin Saturday, 14 January 2017 21:31 posted by admin

    PWM is not working yet. You can control the car without the function of PWM except the speed controlling.

  • Comment Link Paul Hogan Thursday, 12 January 2017 18:54 posted by Paul Hogan

    Hi there,
    I really like how you did thisproject and I'm going to give it a go!
    i was wondering if you got the PWM working? Is it working inthe video that you posted? Or is is possible to run the car without it?
    Thanks,
    Paul.

Leave a comment

Back to Top