Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Friday, 2 May 2014

#SniffBot Part 1

Blame Tom for the name - he called it SniffBot, when he posted a pic of it on twitter next to his PiBot.

Now we've got that out of the way - lets build a robot!

SniffBot starts out as an insanely cheap chassis kit - bought from China via Ebay ( Seriously £16 for chasis, motors and wheels. You can barely get a good set of wheels for that price! The only negative I can say is that while it comes with shaft encoder disks it doesn't come with the IR sensors to use them - OK that would make it more expensive, but presumably the chassis is sized and cut to fit a specific sensor, but we don't know which one! It's got for separate motors, for independent 4 wheel drive which is a nice option even though I've not done anything with it specifically. There are cheaper two wheel versions, but its nice to have a good solid platform to work on, and this thing doesn't get stuck easily!

While a lot of people seem stuck on Raspberry Pi robots, its really not the way to go! Arduino is a fraction of the price, but it also does a better job. The Pi's designed to be driven from mains, so you need to rig a power supply, and it better be a big one to supply around 1A to the Pi. The Arduino has a built in regulator (so you can plug a battery straight in) and uses a fraction of the power, so we can use smaller batteries and/or get better performance. The Arduino also has more I/O so we can control more stuff, and its going to be able to handle the timing requirements we need.

Step one is to build the chassis (adults may need assistance from a small child with a lego obsession to follow the instructions, and handle the small screws!), and then we can drop an Arduino on top. I ditched the supplied AA batter box in favour of a NiCad pack I had. To drive the motors we need a Motor Shield, which you can pick up for about £3 (on Ebay again  - search for L293D motor shield).

These are based on a design originally by AdaFruit, but they've replaced them with a better (more expensive!) design. Sniff supports this old one, which can drive four motors independently. I wired the left wheels to channels 1 and 2, and the right to 3 and 4. We actually only need a two channel board, as we could easily hook two motors up to each channel, but as we have the hardware, we might as well use it - one day we might add traction control! 

There's a (in this case Yellow!) jumper on the board which controls power. I connected the batter back to the power terminals on the motor shield, and left the jumper on, so that the shield is also powering the Arduino. This also means that when you connect USB, the USB will try and power the motors, which isn't such a great idea, but is OK for these little motors. If you're using more powerful motors, which use more than the 5(ish)V that I get from my small batter pack, then you should remove the jumper, and connect a separate battery pack to the Arduino directly.  Then you can safely connect a larger (and/or higher voltage) battery pack to the shield. Having separate power systems also helps with interference - CPU's don't like motors near then, but in this case I've had no problems.

Once that's hooked up we can make this thing move!

make motorController device
make motor1 number
make motor2 number
make motor3 number

make motor4 number

when start
.set motor1 to 1
..tell motorController to "update"

To drive a motor, just make a motorController device, and four variables to control each motors speed.  Set each variable to a value between -1 and 1, and tell the controller to update. At this stage you'll probably want to go through and turn on each motor in turn, checking that they're connected as you think they are, and that 1 is forwards and -1 backwards (switching the red and black wires as appropriate).

Once that's sorted out, we can write a script to drive each of the pairs of motors at once:
make leftDrive number
make rightDrive number
when updateMotors
.set motor1 to leftDrive
.set motor2 to leftDrive
.set motor3 to rightDrive
.set motor4 to rightDrive
.tell motorController to "update"

To make the SniffBot do the "PiBot Dance":

when start
..set leftDrive to  sin of (timer * 100)
..set rightDrive to  cos of (timer * 100)
..broadcast updateMotors and wait

You've now for a working SniffBot for under £30, including Arduino, Chasis, Motors/wheels, Batteries and Motor Controller. It does everything PiBot can do, and as I'll show in the next post we can use it as a platform for even more fun...

1 comment:

  1. This comment has been removed by a blog administrator.