DC motor control (reverse engineering that old toy pt.2)

Since I had the electronics worked out the last time it was now time take this thing one step further and add some control to it. I first made sure the software in the Arduino controlling the DC motors was able to listen to its serial port for incomming commands and afterwards control the motors according to the command that it received. I made sure I had a second Arduino board available and by using XBee modules I could now send commands from my pc wireless over the ZigBee network to my remote Arduino controlling the DC motors.

Next I found myself a XBOX 360 controller and because it has dual joysticks it can control both DC motors, one joystick for each motor. This one I hooked up to my laptop and next I wrote a small interfacing program in Java that translates the XBOX360 code into commands that are being accepted by my Arduino program controlling the motors.

The result:

 

DSC05979Sketch:

sketch_final

DC motor control (reverse engineering that old toy pt.1)

Since my return home I’ve been doing some paperwork and other ridiculous stuff, catching up the last 6 months and off course going to the 10 day festival that is yearly organised in my Belgian home town. But then I stumbled upon one of my first electronic kid toys ever, a Raccoon RC car that was in really bad condition. It has 6 tires/wheels of which only 4 are left over and off course the remote control is missing too. So no fun, unless… And so I decided to revive this toy, not because I like RC cars that much, just because off having something to do during the day-hours of the festival (and to recover from parties the day before).

Because of the remote control missing I had to reverse engineer the current circuit board inside the car. Unfortunately, the toy is like 30 years old and so off course the toy is based upon analogic components instead of digital ones, and off course with the datasheets of some components are missing. Great! Though it did not hold me back to start measuring around and understanding what kind of voltage and current levels are involved in driving the motors, because when you get that there is not much more holding you back from throwing in an Arduino or Raspberry Pi for example to do the rest of the task.

The car architecture is as following: the car has/had 6 wheels, 3 on each side and each side of wheels is driven by one DC motor, so there are 2 motors in total. The car has no wheel that can turn so the only way of making corners is by having different speed on the wheels for each side. If the left wheels are turning slower than those on the right, the car will turn left. Off course!

DSC05950

From my measurements I found the motor control circuit to look something like this:

h-bridge_schematics_old
(click to enlarge)

The two horizontal resistors central in the picture are the motors M1 and M2. From my first drawing things looked way too complicated, but after reading up a bit about DC motor control through H-bridge NPN and PNP transistor configurations I noticed they did exactly the same thing in this circuit. If you’re not common with H-bridge configurations read up a bit:
http://www.instructables.com/id/H-Bridge-on-a-Breadboard/step2/H-Bridge-Theory/

What is so different here to most schematics is that 2 motors are driven from the same circuit. For one motor you need 4 NPN transistors (or 2 NPN + 2 PNP transisotors: http://letsmakerobots.com/node/9450) and probable you would repeat the same configuration for adding a second motor. But the above on is also working, but you must keep in mind two things:
1) both of your motors should always go into the same direction. You can’t make M1 turn your left wheels to the front and make M2 drive your right wheels in the opposite direction because then both transistor in the middle of the schematic (Q7 and Q10) will be made conductive and so you will create a short between Vcc and ground resulting in white smoke and popped transistors!
2) The transistors in the middle need to conduct both the current from M1 and M2 when both motors are used, make sure that the transistors are rated for the expected amount of current. So far example, if you want to drive forward one should make Q6 and Q8 conducting and also Q10 in the middle. While Q6 and Q8 handle the current for their motor only, the current comes together at returns leads from each motor and is than flowing into Q10 which should so be able to handle both currents together.

As far as 1) goes, that is something I can handle in software (Arduino). For 2) I made sure to reuse the original design in some way but adapt it to my own needs. The transistors were rated good enough for the old circuit so they should be good enough now too. Also note in the above schematic the potentiometer on top which allows one to correct the differences in motors speed as one motor will never be exactly the same as the other one.

h-bridge_schematics_new
(click to enlarge)

The main setup didn’t change much, overall the NPN transistor H-bridge remained but now the transistor are controlled by Arduino pins. For each pin I first had 22k resistors connected to the transistor base but later I swapped these to 1k resistors as the transistors that I have never came to conduct. A breadboard sketch would look like this:

sketch

I however soldered mine because my breadboard is still in use for some other project. Note that in the image above the transistor has the base as the center pin. This is however different to the C3279 transistors I’m using where pin 2 is the collector. Also note that the Fritzing drawing tool does not support a socket for 3 batteries so that’s why there are 4 here. In real life 4 batteries would however result in 5,33~6 Volts depending on the batteries you choose resulting in more power from the motors (and more current through the transistors).

Some movement

I won’t quit the blog, it’s a nice and easy to use portal and it might someday contain usefull information (working on that!!). However as I’m no longer student in Porto (which was tremendously fun!!) I see no longer the need keep the Erasmusitis in Porto blog name and so that’s why I decided to change the blog into the current on, No Fab Lab, which is exactly what I am: not a fab lab. I will however continue to mess around with small electronics, embedded devices and programming, so stay tuned for more.

Oh, and life is not so bad back at home, I love Belgium too, not only Portugal 😉

Java benchmarking

Raspberry-Pi is compact and has aside of that other benefits which makes it a really cool tool to play around with. Unfortunately the processing power is limited compared to current day computers and so I hit the performance limit pretty early. But it seems now that Oracle has released a pre-release test version of Java 8 which comes with ARM performance tweaks. And so I was very curious to check out the differences between all Java versions I’ve been using past few months. I used Hwbot Prime to test the difference in computational power between OpenJDK6, OpenJDK7 and Oracle’s JDK8 (pre-release). Here are the results:

java benchmarking

As you can see from the above chart, there is nearly no difference in using OpenJDK 6 or 7, but because of the ARM tweaks found in JDK 8 from Oracle we see a huge performance boost there, roughly 2,5 times higher performance. Off course these results should be taken with a grain of salt. This is a pure computational test, this will not say anything about process threading, MySQL performance or IO performance.. But it’s a nice indication that things are getting better.

not the end…

And so I finished my education, I passed the project with a very good mark and soon I’ll be looking for jobs, but first I need a little bit more vacation. Actually I have been travelling for almost a month already now, in Portugal and France… In Portugal we had some good bye parties, we visit the places in Porto we liked the most, had dinner all together… Next I made a trip with tents together with who’s left in our house. We went all the way to the first Alentejo beaches south of Lisboa. Alentejo is the area in between Lisboa and Faro which is in the south of Portugal. Alentejo is known for its wine grapes, it also has some nice less known beaches and off course it can get very hot there (we had up to 43°C !! ). Next I had to leave my room as the contract was expired but already the next day we left again to the beautiful island of Madeira. Madeira is an island south of Portugal, more or less as south as Casablanca (Morocco) is, but still part of the country Portugal. Madeira is an volcanic island but its volcanic activity has stopped for centuries now. The island is actually only the top of the island, the volcanic ‘cone’ continues 6km under sea level until it reaches the ocean bottom. Madeira is very different in landscape. Even with its small surface area its highest point is 1.8km high, and the steep mountains that characterize the island creates unique environments and micro climates. In the north you’ll see some tropic forest, in the middle of the island there is the volcanic mountains which have needle trees on the way to the top. The south of the island is more like inland Portugal while some places east of the island are really dry and have nearly no trees or vegetation at all. Madeira is really beautiful to do some hiking, it also comes with some natural swimming pools for whoever wants to chill down a little bit after hiking, and in some places once can go surfing or scuba diving or make a boat trip to the next island nearby (that has a really nice beach so I have been told). Madeira also has some typical food and drinks, for example Madeira wine and the Lapas seafood. I really enjoyed this place and arriving at the Pico do Arieiro (the top of the island) the last day of this trip was really a perfect way to end the Erasmus.

This however means not that this is the end of this blog. I’ll try to experiment more with the current code and post my findings here, however don’t expect the same update rate from the past few months as development is now pushed to my free time…

Before I go, a nice shot taken on the Madeira island (not by me):