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.