Monday 17 December 2012

Mobile Pi - Part 2 Simple Motor Control

Ok, so I have my platform and I have a Raspberry Pi running remotely..Now to put them together :)
To do this I need to create a motor controller, so I can firstly protect the Pi from high currents by running the motors off their own power supply and also have some control on direction.

As I'm still waiting on a part which I'll need to be able to have speed control, I'm first gonna create a simple motor controller which uses 4 GPIO pins (2 per motor). One pin for the 'Drive' and one pin for the 'Direction'. Also, I'm not re-inventing the wheel here, I've based the circuit on one found on www.societyofrobots.com. With the only difference being I'm using an SN754410 instead of an L293D, and I'm not using PWM (for now).

Simple Motor Controller Schematic
By the way, for the schematics I'm using an application called Fritzing. It is simple, but useful especially going from breadboard to schematic to circuit board.

So that's the controller decided upon, next step.. put it together. I'm using a breadboard for this for now. I'll create a seperate board for it later. And I can use the Pi Dish which actually fits nicely to the platform. The battery for the Pi I'll just tape to the mid section.. connect the other batters for the motors and . hey presto..

Note, I'm using the new T-Cobbler from Adafruit, another great resource for these things, in tutorials and parts. Also, there are 4 motors, but the controller only works with 2, I hear you say.. well I just wire together both motors on the left, and both on the right :)


So with everything connected, time for the software. For now I'm still sticking the the same library I used for the traffic lights. Although for the next stages it won't be enough as I'll need to use I2C bus.

Anyways, I'm not going to post the whole code here, if you really want it let me know and I'll send it to you. But it is not very interesting code. All the code does is listens to the keyboard, if 'z' is pressed turn both motors on going forward, if 'q' is pressed turn both motors on left going backwards right going forwards.. etc..etc you get the idea. (Oh yeah, if you think the keys are a strange choice, I'm using a belgian keyboard). So running the program using SSH I can control the Raspberry Pi using the keyboard on my laptop. I also was able to control it using my Samsung S2 using a SSH terminal on it :)

And the final result of this is...

That will probably be it until the new year.. I'll add the speed control.. and then maybe add some sensors to auto-stop before hitting anything.. And make the software more interesting :)

Merry Xmas everyone!





No comments:

Post a Comment