ATmega328 serial problems


4 posts
by gdstew » Tue Jan 08, 2013 7:35 pm
I can't get the Arduino IDE running on the Raspberry Pi to see the serial port
on the ATmega328 on the Gertboard. The serial port selection is grayed out and
when I select monitor serial port I get a message saying that it could not find
/dev/ttyAMA0. I have removed or commented out all entries in cmdline.txt and
inittab that reference /dev/ttyAMA0. I changed the ~/.arduino/preferences.txt
entry for the serial port to /dev/ttyAMA0 at 9600 baud. I can loop back by
shorting the GP14 pin to the GP15 pin on the Gertboard and it works perfectly
with minicom. avrdude also seems to have no problem finding /dev/ttyAMA0 but
it does not seem to be able to communicate with the bootloader either.

Trouble shooting this has been made more complicated by a couple of hardware
factors.

1) The ATmega328 that came with the Gertboard is unprogrammed and the only one I
have programmed is from a Rev 3 Arduino Uno that runs at 16 MHz @ 5V.
2) When running at 12 MHz @ 3.3V it produces the wrong baud rate.
3) There is no automatic reset but there is a reset button I use and I have a
buffered LED connected to the PB5 I/O pin so I can see when the bootloader
blinks it.

As it turns out the first two are fixed because I am working on a project that
has required me to modified the Gertboard to allow the ATmega328 on it to run
at 12 MHz @ 3.3V or 16 MHz @ 5V (all 3V3 connections to the ATmega328 are
isolated from the 3V3 bus on the Gertboard and I have installed a socket for
the resonator). It uses two active 3.3V to 5V translators to connect to the
serial RX/TX pins at GP14 and GP15 on the Gertboard when using 5V. Using a
digital oscilloscope I have verified that the voltage translators are working
properly. I can loop back by shorting a header at the 5V logic levels and it
works with minicom as well. There is a program that was downloaded into the
ATmega328 when it was in the Arduino that sends data to the serial port
continuously and I can see that this output is correct by using minicom to
monitor it so I know that the ATmega328 is working and that the baud rate is
correct. I have monitored the serial input pin on the ATmega328 with the
oscilloscope and verified that what I type in using minicom is being received
at that pin at the correct logic level and baud rate.

At this point I am confident that I have eliminated possible hardware problems
so I suspect the Raspberry Pi port of the Arduino IDE is not able to see or use
/dev/ttyAMA0 for some reason. I am trying to avoid cloning the git repository
of the IDE and searching for it myself mainly because I am not familiar with
Java. Any suggestions would be appreciated. Thanks.
Posts: 4
Joined: Thu Sep 20, 2012 6:13 pm
by joan » Tue Jan 08, 2013 8:43 pm
The Arduino IDE does not understand names such as /dev/ttyAMA0.

One suggestion is to

sudo ln -s /dev/ttyAMA0 /dev/ttyUSB9

and restart the Arduino IDE.

This creates an alias to /dev/ttyAMA0 which the IDE may understand.
User avatar
Posts: 5996
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by gdstew » Wed Jan 09, 2013 3:58 am
Thanks Joan that was just the kind of fix I was looking for ! That got the Arduino IDE to recognize the serial port. I used /dev/ttyS0 for the link since that is the "normal" Linux serial tty device. I can now monitor the serial port but I am still having trouble getting avrdude to communicate with it from the IDE. It seems to be caused by having no automatic reset (or timing the manual reset) before avrdude attempts to sync with the bootloader. This is complicated by the upload recompiling the sketch before attempting to download it into the ATmega328. I looked for a configuration setting to turn this off but did not find one. Anyway I am going to do some more troubleshooting using the command line avrdude to see if I can sort some of this out. Thanks again.
Posts: 4
Joined: Thu Sep 20, 2012 6:13 pm
by panik » Wed Jan 09, 2013 9:19 pm
You might want to have a look at "Gordon's patched avrdude" and setup scripts. Link: https://projects.drogon.net/raspberry-pi/gertboard/
User avatar
Posts: 272
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands