[solved] CardKB (from M5Stack) and USBasp programmer

I have some experience with the Arduino IDE (A-IDE) and a Raspberry Pi Pico. I'm on Linux, A-IDE ver. 2.0.3. I've never owned an actual Arduino.

I'm trying to do what they do on this website. That is: I'm trying to "convert" a CardKb keyboard (from the M5Stack range of "gadgets") into a keyboard that will work with UART. See picture below, my setup looks exactly like it because I bought the very same programmer and adapter:

I have to admit that I didn't think it would be this difficult: I'm in over my head. I don't know what a programmer is. I'm confused as to where the Atmel ATMEGA328P chip is : on the programmer or on the keyboard. I have no idea what the program avrdude is.

I really, really, really tried and have been on the internet for about a day or two straight through the night but I'm pulling my hair out getting crazy. No matter what I do I can't get the Arduino IDE to "program" the CardKb keyboard.

I don't even know if I have to choose "Run bootlader" (I don't know what that is) or to simply upload the sketch.

The error that I get is somewhat the same every time (I even tried on an ancient Win 10 32 bit machine w/ Arduino IDE 1.8). The compiling of the sketch always goes well but the process hangs at the point of uploading the sketch or compiled firmware (I do not know what I'm actually doing).

I do not understand why I cannot choose a port. The internet says that the programmer does not behave like a COM port (or: tty (teletype) in Linux land) but it is another sort of USB device or class. If that's so then why can't I say to the Arduino IDE where to find it??? Sorry for the newbe questions but I really, really tried.

Error with or without (!) the programmer attached to my computer (duh!):

Failed uploading: no upload port provided

Error with the programmer (but not the keyboard attached) when I try to upload the sketch and choose /dev/ttyS0 (in Windows you'd call that COM1) as port:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

I can see that it tries to use the program avrdude (???) to upload something.

Error when I try to "Burn bootloader" (I've no idea what that is) it tries to use the program avrdude again (?):

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 "/home/my_name/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/my_name/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         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 : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Failed chip erase: uploading error: exit status 1

On the official website documentation for the CardKb is says: "The default Address is 0x5F". Should I somehow choose that as the "PollValue" instead of 0x53?

The A-IDE screen is supposed to look like this:

But mine looks like this and I therefore cannot determine, for instance, the used clock frequency:

Sometimes I get an error (that i can'r reproduce right now) about the programmer's USB particulars, which are (dmesg):

New low-speed USB device number 7 using ehci-pci
New USB device found, idVendor=16c0, idProduct=05dc, bcdDevice= 1.04
usb 1-1.1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1.1.4: Product: USBasp
 usb 1-1.1.4: Manufacturer: www.fischl.de

and (lsusb):

Bus 001 Device 007: ID 16c0:05dc Van Ooijen Technische Informatica shared ID for use with libusb

And then there's the warning from the website from which I got the sketch:

This board uses the internal oscillator. It is important that you do not accidentally choose an external oscillator, or else you won't be able to program it again unless you actually attach an external oscillator to the board. I found this out the hard way. I now have two dead keyboards.

Did I brick my CardKb?

Oh, and by the way, here's the .ino.

Tried to use a jumper to slow down the clock speed of the USBasp progammer device and ran this command which the Arduino IDE tries to run too. It should use avrdude to upload firmware to the CardKb device:

avrdude -v -c usbasp -p m328p -U flash:w:CardKB_UART.ino.hex:i

Same error as ever:

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/my-name/.avrduderc"

         Using Port                    : usb
         Using Programmer              : usbasp
         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 : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Forcing a slower speed with '-B 4' doesn't help either. I give up. Either the CardKb is bricked or I'm on the wrong track...

For the other newbies out there who might stumble upon this topic via Google.

Strange nobody noticed that I used the "wrong" core.

Atmel Mega XX 8 chips (like the atmega328P, 32 kB memory) are used on the CardKB and on Arduino boards. You must NOT install the Atmel core that comes standard in the Arduino IDE. I repeat NOT NOT NOT!!!!. That wrong core is the "Atmel AVR Xplained minis" by Atmel University France. It requires you to also install support for Arduino AVR boards (the atmega328P is a so-called AVR chip). The M5CardKB keyboard ain't no Arduino board.

The proper core is the "MiniCore" by MCUDude (link). For installation instructions see the MiniCore Github page (link). In short: enter the following URL in Additional Boards Manager URLs:

https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json

, and install MiniCore via the Board Manager.

See screenshot below for how that looks in the Arduino IDE ver. 2.0.3:

The most important setting is that you choose to NOT use an external clock source, see screenie below:


Other settings via the "Tools" menu that you set are:

  • BOD: 2.7 Volt
  • Bootloader: no bootloader
  • Clock: internal (this is important!!!!!!!) 8 MHz
  • EEPROM: retained
  • Compiler LTO: enabled (not that important I think)
  • Variant: 328P

Explanation of settings:

  • BOD = BrownOut Detector (brownout is minimum voltage required before the chip works).
  • Bootloader = seasoned Arduino users know what this is. It's needed on an Arduino to enable uploading of firmware/software via the USB serial connection (opposed to via a programmer device). Don't burn a bootloader to the CardKB. Long story "down the Rabbit Hole": to burn a bootloader the fuses inside the EEPROM chip have to be set. This can brick your atmagaXX8 device.
  • Clock = the atmega328P chip has an internal clock. If you accidentally choose the option "External 20 MHz" (for example) then your CardKB needs to be connected to a 20 MHz crystal via a (hobby) breadboard all the time. In practice this means that your CardKB is bricked (like my first one).
  • Variant: the atmega328 chip has a few variants. The CardKB comes w/ a 328P (EOL, end of life: get one while you still can!) and nowadays also with a atmega8A chip.
  • Programmer = a device to which you connect the CardKB. The Programmer device allows you to flash firmware to a Target device (the CardKB).
  • Burn bootloader = the CardKB does not need a bootloader. If you do burn a bootloader to the CardKB it might brick because you have to set the so-called "fuses" in the EEPROM for this. That might brick the atmega328P chitp. Beware!

You upload the firmware via the menu:

Sketch > Upload using programmer

That means that the Arduino IDE does not use the serial USB port as usual but the Programmer AUBasp device. Remember to NOT choose "Tools > Burn bootloader"!

!Warning!: there appears to be a "newer" and more expensive 1.1 version of the M5Stack CardKB with an atmega8A chip opposed to the atmega328P (notice the omission of the 32). I hope that MiniCore will support this variant soon.

To flash the CardKB with the firmware that converts it in to a terminal I connected the UABasp Programmer to the SPI part of the CardKB Target like so (if I recall correctly, I rewired it for this photograph):


The connections via the SPI header of the CardKB are:

  • MISO white
  • MOSI green
  • 5 Volt red
  • Ground black
  • Clock (SCK) yellow
  • Reset blue

I didn't solder the header on and removed it after successful flashing the CardKB.

To connect the CardKB you use the "Grove" cable (which was nothing more than I2C), which is now converted to UART. See picture below:


The UART connections are:

  • 5 Volt red
  • Ground black
  • Rx yellow (Rx receive on the Pi Pico, Tx transmit on the CardKB)

My new Raspberry Pi Pico "computer" looks like this (no terminal connection via a PC needed, neither do I need to convert a USB keyboard output to UART with another Pico):


Programmable via the Arduino IDE with the U8G2 libray for the Silitonics ST7565R 128x32 pixel screen (link Raspberry Pi forum).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.