I am trying to write my own keypad with Arduino.
Once I uploaded my code, the board get bricked and no more upload is possible.
I have tried three pro micro compatible boards and two genuine arduino leonardo booard and now I have five bricks...
FYI, I have tested the leonardo board with blink example before uploading my custom code and there was no problem before upload.
Also, I have tried the known method to upload blank file with double pressing reset button but all failed with all five boards.
With double pressing reset button, the bootloader device came up in device list but upload ends with fail.
Here's the full upload log with verbose option:
Sketch uses 6664 bytes (23%) of program storage space. Maximum is 28672 bytes.
Global variables use 318 bytes (12%) of dynamic memory, leaving 2242 bytes for local variables. Maximum is 2560 bytes.
Waiting for upload port...
Upload port found on COM9
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Users\sha\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
Using Port : COM9
Using Programmer : avr109
Overriding Baud Rate : 57600
"C:\Users\sha\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\sha\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega32u4 -cavr109 "-PCOM9" -b57600 -D "-Uflash:w:C:\Users\sha\AppData\Local\Temp\arduino\sketches\89A81B1A7E1699C51D7235EE5FA1BE73/tenkey.ino.hex:i"
AVR Part : ATmega32U4
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
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 9000 9000 0x00 0x00
flash 65 6 128 0 yes 32768 128 256 4500 4500 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 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 : butterfly
Description : Atmel AppNote AVR109 Boot Loader
Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.
Programmer supports the following devices:
Device code: 0x44
avrdude: devcode selected: 0x44
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading input file "C:\Users\sha\AppData\Local\Temp\arduino\sketches\89A81B1A7E1699C51D7235EE5FA1BE73/tenkey.ino.hex"
avrdude: writing flash (6664 bytes):
Writing | ################################################## | 100% 0.50s
avrdude: 6664 bytes of flash written
avrdude done. Thank you.
And, I doubt my code could ruin the hardware but who knows? here's my code:
#include <Keyboard.h>
template<size_t N>
constexpr inline auto length(int (&array)[N]) -> size_t { return N; }
constexpr int OFF = LOW;
constexpr int ON = HIGH;
int columns[] = {21, 20, 19, 18};
int rows[] = {5, 6, 7, 8, 9};
struct Key {
Key(char code = 0x0): code{code} {}
char code = 0x0;
int state = OFF;
};
Key keys[length(rows)][length(columns)] = {
{KEY_NUM_LOCK, 0x54 , 0x55, 0x56},
{},
{},
{},
};
int debounce = 10;
auto scan() noexcept -> void
{
Serial.println("start scan");
const auto nrows = length(rows);
const auto ncols = length(columns);
for (int r = 0; r < rows; ++r) {
const auto rowPin = rows[r];
digitalWrite(rowPin, ON);
for (int c = 0; c < ncols; ++c) {
auto &key = keys[r][c];
if (!key.code)
continue;
const auto state = digitalRead(columns[c]);
if (state != key.state) {
// if (key.state == OFF)
// Keyboard.release(key.code);
// else
// Keyboard.press(key.code);
Serial.println((int)key.code);
key.state = state;
}
}
digitalWrite(rowPin, OFF);
}
}
void setup() { // initialize the buttons' inputs:
for (int row : rows) {
pinMode(row, OUTPUT);
digitalWrite(row, OFF);
}
for (int column : columns)
pinMode(column, INPUT);
Serial.begin(9600);
// initialize mouse control:
Keyboard.begin();
}
void loop() {
scan();
delay(100);
}
