Cannot Program MightyHat with Pi powered ON [solved]

Started by G550_Pilot, May 30, 2016, 01:29:13 PM

G550_Pilot

I am integrating my first MightyHat into a project and have it connected to my Pi3. Everything seems to work well until I go to program the MightyHat.

If the Pi is powered up, I cannot program it. I get the following errors:

Sketch uses 27,452 bytes (86%) of program storage space. Maximum is 31,744 bytes.
Global variables use 1,050 bytes (51%) of dynamic memory, leaving 998 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x4c
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x69
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x73
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x74
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x65
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x6e
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x69
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x6e
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x67
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20



If the Pi is powered off, I have no problems at all reprogramming the MightyHat. I have followed the instructions
to disable the BT on the Pi and the Pi is communicating with the Hat on serial OK (I can control the LCD on the HAT
from the Pi via serial commands).

When I plug in the FTDI adaptor the Hat reboots immediately, the Pi stays running but I cannot get beyond that point
until I halt the Pi.

Any attempt to program it gives the above errors and immediately reboots the Hat again.

Thanks


Felix

The serial port has to be freed from the Pi end if anything uses it or it will give errors like that. That is one big thing to watch for.
I think natively the Pi3 has the GPIO serial port already assigned to the BT. I describe how to free it up on this page.

Once the serial is freed, it should work either via FTDI or from the Pi via the avrdude method on the hat page.

G550_Pilot

I already followed the instructions to free the serial port form the BT and I am able to control the LCD from the Pi to the MightyHat. I have this at the bottom my /boot/config.txt:

dtparam=spi=on
dtparam=i2c_arm=off
dtoverlay=pi3-disable-bt

and I ran:

   
sudo systemctl disable hciuart


and rebooted.


Felix

Deallocating it from BT is one part.
To use the serial to program the HAT requires the second part, of stopping any app that uses that GPIO serial port, in our case whatever app (the LPL Gateway?) you run to control the MightyHAT.
That's not obvious from the avrdude errors at all, just a gotcha you have to remember when doing this.
Or ... just pull the Hat from the GPIO if nothing works, i know this is emergency/last resort, thought i'd mention it.

G550_Pilot

I am not running any gateway application on the Pi, just my pool control software. I'll shut that down and give the programming a try without it running and let you know what I find!

jhoward88

I'm having the same problem.  I did the steps to disable bluetooth, but still can't use avrdude to upload .hex files.   
I loaded a sketch on the MH via the FTDI board and that works fine, but once I disconnect the FTDI and power the pi back on, I can't access /tty/AMA0  from a python program, for example.  If I try minicom, I mostly see garbage, or nothing, but once today amid the garbage I saw a string that I could tell was coming from the sketch I had loaded via FTDI.  I should see very consistent lines of text from that sketch if all is well.  I had the sketch use 19200 baud and set minicom the same way. I've also tried other baud rates in both minicom and the python program.   So something still seems wrong with the /tty/AMA0 connection.




Felix

jhoward88,
Please ensure your GPIO serial port is not used by anything. It sounds like yours is tied up by something else. Are you using the LowPowerLab Gateway software?
That will cause avrdude programming to fail, unless you stop it or stop whatever is using the serial port.
Also your avrdude has to be patched as described in the guide so it resets the MH before attempting programming (to put it in bootloader).

jhoward88

The problem I had was default permissions on /dev/ttyAMA0   .  After a reboot you would see this:
ls -l /dev/ttyAMA0
crw--w---- 1 root tty 204, 64 Jun  1 21:10 /dev/ttyAMA0

I tried adding pi to the tty group and doing chmods but that didn't help. This is what fixed it:
sudo systemctl mask [email protected]
Then reboot.
that gives the right permissions and lets you access the MightyHat from python and also I am now able to use avrdude to upload .hex files.  Everything seems to be working now.
I found the above tip in this thread on stackExchange:
http://raspberrypi.stackexchange.com/questions/48211/set-permission-for-dev-ttyama0-on-boot

Felix

Thanks for the update, good to know.

Weird though , I never had to do this, I used wheezy and jessie.
What distro is this? Jessie?

jhoward88


Felix

Man it's hard to keep up to date with all the changes they make. From your feedback it sounds like this is for user Pi.
Why did they mess around with the ttyAMA0, why did they have to change the read rights now and never before...
Maybe they want to throw a wrench for folks who use the gpio serial port.
I wonder what's next.  ::)
Thanks again for bringing this up!