Arduino UNO r3 - ATMEGA328P-PU flashing bootloader

Hi all,

I'm new to Arduino microcontrollers and last week I bought an Arduino UNO r3 with an ATMEGA328P-PU processor.

I was able to create a simple circuit (with the related sketch) with a button and a LED that turns on.

What I would like to do is using it as an HID keyboard sending characters to the computer depending on buttons pressed.

I followed the instructions in mitchtech.net/arduino-usb-hid-keyboard/ and the first problem I encountered was that dfu-programmer (I'm using linux) didn't work for my processor; anyway I was able to flash the bootloader (Arduino-keyboard-0.3.hex) with avrdude using the following command:

avrdude -p m328p -P /dev/ttyACM0 -c arduino -U flash:w:Arduino-keyboard-0.3.hex -v

the output of the command seems nice

avrdude: Version 5.11.1, compiled on Oct 30 2011 at 10:37:28
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is "/etc/avrdude.conf"
User configuration file is "/root/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port : /dev/ttyACM0
Using Programmer : arduino
AVR Part : ATMEGA328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :

Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack


eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

Programmer Type : Arduino
Description : Arduino
Hardware Version: 3
Firmware Version: 4.4
Vtarget : 0.3 V
Varef : 0.3 V
Oscillator : 28.800 kHz
SCK period : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "Arduino-keyboard-0.3.hex"
avrdude: input file Arduino-keyboard-0.3.hex auto detected as Intel Hex
avrdude: writing flash (4022 bytes):

Writing | ################################################## | 100% 0.65s

avrdude: 4022 bytes of flash written
avrdude: verifying flash memory against Arduino-keyboard-0.3.hex:
avrdude: load data flash data from input file Arduino-keyboard-0.3.hex:
avrdude: input file Arduino-keyboard-0.3.hex auto detected as Intel Hex
avrdude: input file Arduino-keyboard-0.3.hex contains 4022 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.52s

avrdude: verifying ...
avrdude: 4022 bytes of flash verified

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done. Thank you.

but when I unplug and plug again the Arduino the command that I'm sending through the Serial.write instruction still doesn't send anything through the usb port (and I can verify through the serial console that the command is sent since if I use the ASCII code of the character (that's different respect to the HID character I have to use) I can read the character expected)

Something makes me think the bootloader has been reset to its original version since I was able to continue upload my sketches through usb and accordingly to many sites I read that shouldn't happen anymore once the new bootloader is installed.

What am I missing? Do I have to short circuit in some way the reset pin is on the board?

Sorry if the question seems stupid but as I said in the beginning I'm just a newbe..

Thanks in advance for any clue

Luca

What am I missing?

There is no way to make an Uno be an HID keyboard by loading a sketch ONLY onto the atmega328p, because the 328p does not have any usb capabilities at all; that's handled by a separate chip.

There are two ways that you MIGHT be able to do what you want:

  1. in addition to the sketch on the 328p, also burn new code into the Uno's USB processor (an ATmega16u2) that makes it behave like a USB HID instead of (or in addition to?) a serial port. I've never done this; I believe that it involves DFU and shorting some pin/pad near the 16u2 to get it into boot mode. (it has nothing to do with the 328 bootloader, though.)

  2. Use a Leonardo instead; this is a single-chip Arduino board that has built-in USB capabilities.

Thank you very much for your reply,

I had the feeling I was missing some basic concepts (the possibility of burning new code into the ATmega16u2 processor and the absence of usb capcbilities of the 328p)

I will go more in deep for 1) and if I will be stuck for too long I will switch to 2)

Thank you very much

Luca

Hi westfw,

I wanted to tell you that I was able to flash the new code (Arduino-keyboard-0.3.hex) into the 16u2 processor and now it acts as an HID USB keyboard :slight_smile:

I followed the great post in http://cjdavies.org/?tag=atmega16u2

Thanks again for pointing me out the right direction

Luca