Author Topic: Arduino Uno and TMK  (Read 5870 times)

0 Members and 1 Guest are viewing this topic.

Offline Henk

  • Thread Starter
  • Posts: 13
Arduino Uno and TMK
« on: Thu, 18 June 2015, 06:35:33 »
Hello, I have an Arduino Uno that I would like to load TMK on but I am a total newbie when it comes to AVR and I cant find anything that will help me.

I have two ATmega328p chips which is supported by TMK according to the wiki and one uno board but no programmers
there is http://www.arduino.cc/en/Tutorial/ArduinoISP this but i don't understand how to use this to load TMK

What I want to do in the future is a complete keyboard pcb.
I don't really care if its an ATmega328p so feel free to point me to any direction that lets me load TMK to a bare chip.
I've looked around a bit and the McHck seems interesting but its not in the list of supported TMK chips so Im not sure it would work.

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: Arduino Uno and TMK
« Reply #1 on: Thu, 18 June 2015, 07:09:27 »
First of all, since you don't write what are you trying to achieve, let's make this clear: you can flash TMK firmware to an arduino uno, but Uno will not appear as a keyboard to the computer - atmega328p lacks USB connectivity, and on an Uno board it is connected to the computer via another "USB-to-serial" chip.

If you still want to proceed, compile the TMK firmware, and then you can flash the resulting hex file to arduino using avrdude. Here's a guide: https://typeunsafe.wordpress.com/2011/07/22/programming-arduino-with-avrdude/

There is a way to have an atmega328p pretend to be a USB keyboard to the computer, but it requires the bare m328p chip to be connected to USB using a different circuitry than the one that's present on an Uno. Furthermore, the USB protocol will be only bit-banged (i.e. no hardware support on m328p's side), so it will only support USB 1.1 (which means, for instance, that the mouse keys won't work in TMK). If you want to see the minimal circuit, have a look here: http://matrixstorm.com/avr/tinyusbboard/

Ad mchck: that one uses a Freescale ARM chip, a very different beast from AVR chips.

EDIT: You probably want to consider USB capable AVR chips for starters, e.g. (most commonly used for custom keyboards): atmega32u4 . That one's on Arduino leonardo, and more importantly on teensy 2.0: https://www.pjrc.com/store/teensy.html Teensy is used in custom keyboards a lot.
« Last Edit: Thu, 18 June 2015, 07:12:44 by flabbergast »

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #2 on: Thu, 18 June 2015, 07:37:18 »
thanks for the reply
What I want to achieve is a minimal circuit that i recognized by the computer as a usb keyboard and runs TMK with all features

I have a Teensy 2.0 on the way for my first build that I will handwire but I want to design my own keyboard with PCB mounted switches without the teensy and a custom acrylic case.

I will look up the atmega32u4.
I also would love bluetooth but thats something I will look up after I've done my first keyboard.\

Edit:
Whats the difference between ATMega32U4-AU and ATMega32U4RC-AU ?
this programmer should be good enough right? https://www.sparkfun.com/products/9825
« Last Edit: Thu, 18 June 2015, 08:02:04 by Henk »

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: Arduino Uno and TMK
« Reply #3 on: Thu, 18 June 2015, 08:16:49 »
The unpleasant thing about atmega32u4 is that it only comes in smt packages, there is no through-hole version.

I've not seen the 'rc' version yet, your best bet is to have a look at datasheets. Sorry.

Programmer: yes, that one from sparkfun would work. But for this purpose you can use your arduino - that's what should be explained in the link you have in your original post.

However most common scenario is to use the programmer only once, to flash a bootloader to 32u4, and then subsequent flashing can be done via USB.

Offline VinnyCordeiro

  • Posts: 432
Re: Arduino Uno and TMK
« Reply #4 on: Thu, 18 June 2015, 08:22:08 »
thanks for the reply
What I want to achieve is a minimal circuit that i recognized by the computer as a usb keyboard and runs TMK with all features

I have a Teensy 2.0 on the way for my first build that I will handwire but I want to design my own keyboard with PCB mounted switches without the teensy and a custom acrylic case.

I will look up the atmega32u4.
I also would love bluetooth but thats something I will look up after I've done my first keyboard.\

Edit:
Whats the difference between ATMega32U4-AU and ATMega32U4RC-AU ?
this programmer should be good enough right? https://www.sparkfun.com/products/9825
IIRC both are the same microcontroller, but the RC is the industrial version and have higher tolerances (like working temperature range, etc).

Btw, the ATmega32U4 is used on the Arduino Leonardo.

Offline joey

  • Posts: 2296
  • Location: UK
Re: Arduino Uno and TMK
« Reply #5 on: Thu, 18 June 2015, 09:13:34 »
You can design a PCB that uses the teensy as a through hole component.

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #6 on: Thu, 18 June 2015, 09:22:53 »
IIRC both are the same microcontroller, but the RC is the industrial version and have higher tolerances (like working temperature range, etc).
ah ok

Programmer: yes, that one from sparkfun would work. But for this purpose you can use your arduino - that's what should be explained in the link you have in your original post.

However most common scenario is to use the programmer only once, to flash a bootloader to 32u4, and then subsequent flashing can be done via USB.
I thought you could only use the ArduinoISP with the Arduino IDE, where can I find and how do I flash other bootloaders?
Currently browsing avr freaks but I still dont know what to search for

You can design a PCB that uses the teensy as a through hole component.
thats true but I want to make it as little components and as cheap as possible, I will do this if I get nowhere.

Offline Charger

  • Posts: 168
Re: Arduino Uno and TMK
« Reply #7 on: Thu, 18 June 2015, 09:48:17 »

thats true but I want to make it as little components and as cheap as possible, I will do this if I get nowhere.
If you want cheaper there is the pro micro but it doesn't have as many usable pins as the teensy.

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: Arduino Uno and TMK
« Reply #8 on: Thu, 18 June 2015, 10:16:13 »
[
Programmer: yes, that one from sparkfun would work. But for this purpose you can use your arduino - that's what should be explained in the link you have in your original post.

However most common scenario is to use the programmer only once, to flash a bootloader to 32u4, and then subsequent flashing can be done via USB.
I thought you could only use the ArduinoISP with the Arduino IDE, where can I find and how do I flash other bootloaders?
Currently browsing avr freaks but I still dont know what to search for
E.g. here: https://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduinoisp - there's lots of stuff but the point is the very short last section ("Bonus! Using with avrdude!"). Essentially you just tell avrdude that the programmer it should be using is arduino.

EDIT: BTW, I like your 45% layout. Nice work!

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: Arduino Uno and TMK
« Reply #9 on: Thu, 18 June 2015, 10:20:05 »
To come back to using atmega328p - while most of custom PCBs use atmega32u4, some koreans seem to like bit-banging with non-USB-capable AVR chips, mostly atmega32a - for instance faceU / faceW / Bface PCBs use atmega32a , VUSB library (that's the software side to bit-banging USB protocol) and a basic circuit like the one I linked above (2 3.3V zeners, 2 small resistors (usually 68R), 1 pullup resistor (usually 1.5kR)).

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #10 on: Thu, 18 June 2015, 10:39:52 »
If you want cheaper there is the pro micro but it doesn't have as many usable pins as the teensy.
true but my main priority is making a pcb with just components and no extra pcbs on it

E.g. here: https://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduinoisp - there's lots of stuff but the point is the very short last section ("Bonus! Using with avrdude!"). Essentially you just tell avrdude that the programmer it should be using is arduino.

EDIT: BTW, I like your 45% layout. Nice work!
Thanks and thanks!

Bit-banging seems to be a bit outside my reach currently (no pun intended) so I'm going to stick to the 32u4.

I've been reading the datasheet and I was wondering if all I need is 2x22 Ohm resistors and a 1µF capacitor to hook up a USB port to the 32u4?
The crystal is unnecessary right?

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: Arduino Uno and TMK
« Reply #11 on: Thu, 18 June 2015, 11:45:54 »
I've been reading the datasheet and I was wondering if all I need is 2x22 Ohm resistors and a 1µF capacitor to hook up a USB port to the 32u4?
The crystal is unnecessary right?
Depends how far outside the specs you want to go ;)

In principle all you need is that. But I would always add 0.1uF caps close to the IC for every power pin of the IC (to filter out the noise from the IC) and at least one 10uF cap to stabilise the input current (which may fluctuate).

About crystal: I've not seen a crystal-less USB board with 32u4 yet - but I haven't actually read the datasheet carefully. You might want to have a look at the USB section to see how precise clock is needed for USB, I would wager that a crystal is actually needed (although datasheets tend to go about this specification in quite an oblique way).

Another thing that's useful to include is a reset button, or at least pads that you can short manually to induce a reset. That's about it.

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #12 on: Thu, 18 June 2015, 11:57:07 »
Code: [Select]
λ avrdude -c arduino -p m328p -P com3 -U lfuse:w:0xe2:m -U hfuse:w:0xda:m -U efuse:w:0x0f:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: reading input file "0xe2"
avrdude: writing lfuse (1 bytes):

Writing |                                                    | 0% 0.00s ***failed;
Writing | ################################################## | 100% 0.07s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe2:
avrdude: load data lfuse data from input file 0xe2:
avrdude: input file 0xe2 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xe2 != 0x00
avrdude: verification error; content mismatch

avrdude: safemode: lfuse changed! Was e2, and is now 0
Would you like this fuse to be changed back? [y/n] y
avrdude: stk500_cmd(): programmer is out of sync

not sure if this is the right place to ask but i cant seem to get past step one

avrdude is alteast recognizing the arduino as an isp

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #13 on: Thu, 18 June 2015, 12:53:36 »
I've been reading the datasheet and I was wondering if all I need is 2x22 Ohm resistors and a 1µF capacitor to hook up a USB port to the 32u4?
The crystal is unnecessary right?
Depends how far outside the specs you want to go ;)

In principle all you need is that. But I would always add 0.1uF caps close to the IC for every power pin of the IC (to filter out the noise from the IC) and at least one 10uF cap to stabilise the input current (which may fluctuate).

About crystal: I've not seen a crystal-less USB board with 32u4 yet - but I haven't actually read the datasheet carefully. You might want to have a look at the USB section to see how precise clock is needed for USB, I would wager that a crystal is actually needed (although datasheets tend to go about this specification in quite an oblique way).

Another thing that's useful to include is a reset button, or at least pads that you can short manually to induce a reset. That's about it.
103740-0
this is what I've been able to make so far, is it ok?

Offline joey

  • Posts: 2296
  • Location: UK
Re: Arduino Uno and TMK
« Reply #14 on: Thu, 18 June 2015, 12:59:18 »
You want a 0.1 cap on each of the VCC pins, not one shared between them.

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #15 on: Thu, 18 June 2015, 13:05:23 »
You want a 0.1 cap on each of the VCC pins, not one shared between them.
is this good?

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: Arduino Uno and TMK
« Reply #16 on: Thu, 18 June 2015, 17:32:28 »
You want a 0.1 cap on each of the VCC pins, not one shared between them.
is this good?
VBUS should be tied to 5V from USB.

All the VCC/AVCC should be connected to 5V as well (if you want the chip to run at 5V, which is what you probably want).

RESET cannot be left floating (the chip might randomly reset then), it should be pulled up via a 10k resistor or such, and you might want to have a switch to ground, or at least pads, so that you can actually reset the chip.

When you're actually doing the circuit, make sure you check the recommended capacitance for the caps next to the crystal - some crystals want 18pF, some 22pF.

Other than that, it looks OK.

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #17 on: Fri, 19 June 2015, 12:13:24 »
103760-0
this should be good enough?

about the keymatrix, is it ok to have columns that only have 1, 2 rows or should I make it a 12x4 matrix?

Offline VinnyCordeiro

  • Posts: 432
Re: Arduino Uno and TMK
« Reply #18 on: Fri, 19 June 2015, 13:33:10 »
about the keymatrix, is it ok to have columns that only have 1, 2 rows or should I make it a 12x4 matrix?
The switch matrix is the most flexible part of a keyboard, you may design it in whatever way you want. Just note it down to have a reference when writing the firmware.

Offline Henk

  • Thread Starter
  • Posts: 13
Re: Arduino Uno and TMK
« Reply #19 on: Sat, 20 June 2015, 12:10:04 »
103852-0
This is the almost final draft of my schematic, I would love if someone could give it an ok. Should I make MISO, MOSI, SCK and Reset available for programmers? or is it unnecessary since the not RC version of 32U4 comes with an bootloader pre flashed?

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: Arduino Uno and TMK
« Reply #20 on: Sat, 20 June 2015, 14:15:04 »
Looks OK to me (no guarantees though ;)

You might want to check the datasheet to see whether you should tie AREF to something (you most likely won't use its functionality, because it's for analog functions).

About SPI pins - if there is space, I would definitely route them out at least to pads - it's always better to have them available if it turns out they're needed, then to find out halfway that I actually need them and end up soldering stuff to TQFP pins directly...

By the way - I'm not so sure that atmega32u4 comes with a bootloader from factory (I've never bought this one myself, but I know that some other chips don't (like xmegas)). Another point as far as a/the bootloader goes - check the datasheet for HWB pin. It can be used (with proper selection of fuses) to decide whether to enter the bootloader or not. However on most breakouts it's actually not used that way, and there's a logic in the bootloader itself which (for instance) checks a pin and decides whether to run the rest of the bootloader or the application. Some people (e.g. bpiphany with custom keyboard controllers) use even another logic - namely if the board is powered up, the application is run; if it's just reset, then the bootloader runs (so when you plug in the keyboard, it's a keyboard; but when you hit the reset button, it goes into bootloader).