Wireless working

So I had a great deal of problems with an USB wifi adapter for the Raspberry Pi that I bought on dealextreme.com. It just wasn’t stable.

Yesterday I got another USB wifi adapter, the Edimax EW-7811Un. It works great, I can recommend it. So I now had the hardware to try out prototype #2 for my R/C car.

Right now I have my Raspberry Pi powered by a USB battery pack. It runs alright but I’m not sure how much time I will get from a full charge. Then the Arduino is plugged into one USB port on the RPi, and the Edimax adapter in the other port. A 3-cell LiPo battery (mentioned before) gives power to the H-bridge and I ended up using the switch mode adapter to get 5V for the servo, as I had problems with it drawing too much current from the Arduino board and thus resetting it, sometimes just once, sometimes many times after each other.

On the RPi I have installed: nginx, uwsgi and Flask. These make my webserver. I followed one of many guides on the web to get those 3 to work together – it took hours to figure out because my linux skills are limited at best.

Here is my python code for Flask:

from flask import Flask, render_template, request, url_for
app = Flask(__name__)
import serial

def do(action):
    port = serial.Serial("/dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_5533033393035131C012-if00", baudrate=9600, timeout=3.0)

@app.route("/", methods=['POST', 'GET'])
def hello():
    if request.method == 'POST':
	return "OK"
    	return render_template('index.html')

if __name__ == "__main__":
    app.run(host='', port=8080)

I used this long path for serial control instead of simply “/dev/ttyACM0” because it would sometimes change to “/dev/ttyACM1” and then I had to change the code every time. I didn’t have that problem with this path, so I am guessing it won’t change.

This is index.html:

<!doctype html>
<title>Hello from Flask</title>

function sendAction(action)
xmlhttp=new XMLHttpRequest();
xmlhttp.open(“POST”, “/”,true);
xmlhttp.send(“action=” + action);

<link rel=”stylesheet” type=”text/css” href=”static/style.css”/>

<h1>Hello World!</h1>

<div id=”buttons”>
<div id=”upleft”>
<input type=”image” onClick=”sendAction(‘M,50,S,-25’)” src=”static/upleft.gif” />
<div id=”upup”>
<input type=”image” onClick=”sendAction(‘M,100,S,0’)” src=”static/upup.gif” />
<div id=”upright”>
<input type=”image” onClick=”sendAction(‘M,50,S,25’)” src=”static/upright.gif” />
<div id=”up”>
<input type=”image” onClick=”sendAction(‘M,50,S,0’)” src=”static/up.gif” />
<div id=”stop”>
<input type=”image” onClick=”sendAction(‘M,0,S,0’)” src=”static/stop.gif” />
<div id=”down”>
<input type=”image” onClick=”sendAction(‘M,-50,S,0’)” src=”static/down.gif” />
<div id=”downleft”>
<input type=”image” onClick=”sendAction(‘M,-50,S,-25’)” src=”static/downleft.gif” />
<div id=”downdown”>
<input type=”image” onClick=”sendAction(‘M,-100,S,0’)” src=”static/downdown.gif” />
<div id=”downright”>
<input type=”image” onClick=”sendAction(‘M,-50,S,25’)” src=”static/downright.gif” />


So for each button I have a div so I can control its position with css. I am using AJAX to send the request to python without having to reload the page each time I push one of the buttons.

I remapped the serial commands, so instead of full speed being “M,255,S,0” it is now “M,100,S,0”. Seems more logical.

The css file:











As you can see, most of the buttons didn’t need to be positioned. The page now looked like this:


Pushing any of the buttons will send a POST request which will be handled by the python script and sent by serial connection to the Arduino. It worked alright until it suddenly wouldn’t run in reverse, so I sadly didn’t get to record any videos of it functioning.

IMG_20140913_135943 IMG_20140913_135950

It seems I broke my H-bridge. I don’t really know how, but I know that I won’t make another myself! I will keep it as an artifact (hmm maybe frame it? lol) and buy an IC for the project instead.

Some nice people on the subreddit /r/arduino recommended for me to add some diodes for the current to flow back from the motors to the battery, when the motors are turned off, to prevent the current from going through the transistors the wrong way. I did actually do that. So I am truly puzzled.

I guess I will also have to move away from the lunchbox as platform, and the straw and cardboard solution. Any ideas? Comments are more than welcome.


See ya



2 Responses to “Wireless working”

  1. Jai siger:

    Yeah, the h-bridge experience is a great one, but the L298 is just so much easier. Look at one of the cheap boards from china.

    That’s great work on getting it all running via the webpage!

    • the curious siger:

      Yeah. I’m thinking of soldering my own board still, because I need the soldering experience. But I got an IC to use in a socket, so it’s easy to replace the part if it burns down 🙂
      Thank you 🙂

Skriv et svar

Din e-mailadresse vil ikke blive publiceret. Krævede felter er markeret med *