Tuesday, May 7, 2019

Some tips on using the Smart 2 Wheel Arduino Robot chassis

I'm a big fan of these basic 2 wheel chassis.  They're cheap to buy.  I've seen them on eBay for less than £6.00 without the batter holder.  There is enough space on them an Arduino or PiZero with a motor controller alongside the battery pack.
2 wheel smart robot chassis
They're usually listed as "2 Wheel Smart Robot" with the word Arduino added in there somewhere even thought they are not Arduino specific.  I think it's there to improve SEO for all the people making their first robot using an Arduinio.  Also, they are not smart, there is no intelligence provided.  They usually come with  tachometer encoders for the wheels, but you need extra electronics to read them.

I've used these chassis a few times and these are some gotchas that I'd to figure out.

1. The perspex is clear
If the perspex is opaque or brown in colour then this is a layer that can be pealed off.  It's there to protect the perspex.  You can leave it on but it's supposed to come off.

2.  The caster goes to the back.
Even though most of the pictures you see show the caster wheel at the front this is really a drag wheel and should be at the back of the bot.
The fact the caster spins means if it is put at the front then you're pushing against the caster when turning.  It's like having a wobbly shopping trolley.  Easier to pull behind you than push in front. Also, you can see from the image the (correct) front has more mounting options for sensors which makes sense.

3.  The battery box can be screwed on the underside
All pictures I've seen always have the AA battery box on the top.  Makes sense as gravity will keep the batteries in.  But, if needed the battery box can be screwed to the underside of the deck giving more real estate on the top for other components.

4.  The connections on the motors are very fragile
Where you solder the wires to the motors is very fragile and prone to snapping off if put under any strain.  So, it's best to put in place some strain relief.
The easiest and without needing any additional hardware is to knot the two wires around the plastic fastener holding the motor in place.  In this way if someone pulls on a wire or it gets snagged it doesn't put any pressure on the actual connection on the motor.

Strain relief on the motor wiring

Some final thoughts

I've used these motors with L298N as well as L9110s motor controllers.  Both work great.  The L298N is bigger and really over specced for these little motors so the L9110s is more than capable of driving them.
The cheap L9110s board only has one GND connection and assuming using a different power supply for the motors and the controller (Pi/Arduino) you'll need to tie the GND from the different power supplies, the controller and the L9110s together.  I usually use one of the additional GND pins on the controller.  Arduino Uno has three GND pins, the Arduino Nano has 2 and the Raspberry Pi has 8.

L9110s - only one GND connection

I've heard reports that as the gears are plastic they can be shredded.  A lot of fast reversing with a decent power supply can put the cogs under a lot of strain.  This is one of the main compromises for the price.  So, either limit the speed at which the motors can change direction or be ready to replace the motors.

These little yellow motors look like they're all the same, but the gearing inside them can be different.  If you do need a replacement motor you may not get the same gearing ratio which would affect the ability of your robot to go in a straight line or just move consistently.

Even with all this I think these kits are a great start.  They're easy to put together.  Reliable (enough), powerful (enough) and cheap so a great place to start.
Add an Arduino Nano and an L9110s with a small breadboard to connect everything together and you have a capable platform to develop from for less than £10.00.
You can then add ultra-sonic sensors, line following sensors, infra-red remote control, Bluetooth interface, or even the tachometers to measure speed and lots more...
Giving an easy and cost effective introduction to robots.
This may not be the chassis you finish with but it's definitely a good place to start.
And if you're already thinking of upgrades there is a 4 wheeled version as well for not much more.

4 Wheel Smart Chassis

Happy roboting.

Thursday, February 28, 2019

Arduino - avrdude: stk500_getsync() not in sync - How to fix

This is  reminder for me and hopefully useful for others either new to Arduino or using different boards.

Sometimes on uploading you can get an error message

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00

Of course the attempt number changes as it tries 10 times.

There are a few relatively obvious things that can help stop this error message.

Select the right board.  If you're using an Uno, select Uno. If you're using a Leonardo, select Leonardo.

Select the correct processor: ATMega328 is the Uno one and the default

Make sure your USB port is selected.

Even after doing both of these and it all looking right you might still be getting the error message.

This is where we get into a discussion about Arduino compatible boards.  The Arduino is an Open Source design and so it is perfectly legal and acceptable for anyone to copy the design and make their own boards and sell them (but they cannot call it an Arduino, topic for another day)

Some of these compatible boards use a different USB chip (CH340) and the ATMega328 could have a different bootloader to the actual Arduino.

if you are using a compatible board that has a CH340 make sure to install the driver for the chip otherwise you may not even be able to see the board in the IDE.

Then for the bootloader there is an alternative option under the Processor called "ATMega328P (Old Bootloader)"  Not where I expect to see an alternative bootloader option but there it is.

ATMega328p (Old Bootloader)

This is the one I have to use for compatible boards.

So, once the correct board, processor, and port are selected you should be able to program your Arduino with ease.

Finally, finally. If you're running Linux and not Windows there is one more thing to take into account and that's permissions.  By default a regular user account does not have permission to read/write to USB serial ports so you have to add your user to the group with access. 

The command you need is as follows where [USERNAME] is replaced with your username.

sudo usermod -a -G dialout [USERNAME]

WARNING: This command is run using sudo and so has root access.  It's always the right thing when finding commands online that use sudo to do your own research before blindly using the command.
So, here's where I got the command from https://www.arduino.cc/en/Guide/Linux/

Hope you find this useful as I expect I'll be back here again when I set up my next computer or buy some new compatible boards.

Arduino and NRF24L01 - test code

A while back I made a game using some Arduino Nano and NRF24l01 called ButtonFlash (https://www.winkleink.com/2016/08/buttonflash-game-made-with-raspberry-pi.html)

Mnadatory video showing it being played.

It was good fun to make and people seemed to enjoy it but it wasn't in a state for someone else to make easily and wasn't robust so running repairs were needed.

But I really liked it and wanted to do a version that others could make easily.
At the same time EasyEDA was starting to be advertised as a simple web based PCB design tool with integration to a PCB fabrication facility so getting the boards manufactured would be super easy.  So, I took the plunge and designed a PCB and had 10 of them manufactured.

Soldered up

I soldered a pair and started running  code to test them and it kept failing.  I tried different libraries and different setups and every time I couldn't get it to work reliably.  This is part of the pleasure of using code and electronic components created by others.

Today I figured out one of the NRF24l01 that I used can transmit but not receive.  Maybe I damaged it as had power caps in the wrong way around when testing early on.

I soldered up a 3rd but without the switch and LED and ignoring the bad one the pair I used were reliable today.

Now as I tried lots of sample code and had different results with them I have prepared my own tester code.
This code uses the Arduino, NRF24l01, LED attached to Pin2 (through current limiting resistor) and switch on Pin3 using internal pull up.

When uploaded the Arduinos start in transmit mode.
Press the switch on one and it transmits and switches to receive mode.
Now you have one in transmit and one in receive mode.

Pressing the switch on the transmit one and it's LED will flash 5 times and change to receive mode and the receive one will turn it's LED on full and change to transmit mode.

It's amazing how much fun it is to press the switch. See the change. Then press the switch on the other one and see them swap roles.

So, if you are messing with Arduino and NRF24l01 then maybe this code will be useful to help you.

Code is available on GitHub 

Now to actually make ButtonFlash 2.0.