Author Topic: M0110 to Bluetooth Project  (Read 9937 times)

0 Members and 1 Guest are viewing this topic.

Offline AEChadwick

  • Thread Starter
  • Posts: 6
M0110 to Bluetooth Project
« on: Sun, 28 December 2014, 14:10:44 »
I have adapted several keyboards with the M0110-to-USB via Teensy2.0 https://github.com/tmk/tmk_keyboard/blob/master/converter/m0110_usb/README.md, they always work perfectly (thanks, hasu!).

I want to take it to the next level and make a Bluetooth M0110, ala the Bluefruit-Model-M conversion. https://learn.adafruit.com/convert-your-model-m-keyboard-to-bluetooth-with-bluefruit-ez-key-hid/overview

I would like continue using the Teensy2.0, as it is a known & reliable.

To my (limited) understanding, this is simply matter of sending the keyboard output through serial TX (default D3 on the Teensy2.0) https://www.pjrc.com/teensy/pinout.html

is enabling the TX output as straightforward as: add this code block to m0110_usb/config.h ???

Code: [Select]
/* USART configuration
 *     asynchronous, 9600baud, 8-data bit, non parity, 1-stop bit, no flow control
 */
#ifdef __AVR_ATmega32U4__
    #define SERIAL_UART_BAUD       9600
    #define SERIAL_UART_DATA       UDR1
    #define SERIAL_UART_UBRR       ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
    #define SERIAL_UART_RXD_VECT   USART1_RX_vect
    #define SERIAL_UART_TXD_READY  (UCSR1A&(1<<UDRE1))
    #define SERIAL_UART_INIT()     do { \
        UBRR1L = (uint8_t) SERIAL_UART_UBRR;       /* baud rate */ \
        UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8);  /* baud rate */ \
        UCSR1B = (1<<TXEN1);                /* TX: enable */ \
        UCSR1C = (0<<UPM11) | (0<<UPM10) | /* parity: none(00), even(01), odd(11) */ \
                 (0<<UCSZ12) | (1<<UCSZ11) | (1<<UCSZ10); /* data-8bit(011) */ \
        sei(); \
    } while(0)
#else
#   error "USART configuration is needed."
#endif

*i do not require further/software control of the bluefruit—I just need it to broadcast the keypresses—so it does not seem necessary to add the bluefruit-specific protocol, like include $(TOP_DIR)/protocol/bluefruit.mk to m0110_usb/Makefile

I have roughed together a hardware layout like this.



before I get soldering, i’d sure appreciate a review by folks that know more than me.

I will update with success (or failure) as it happens.

—Æ

Offline hydrospell

  • * Destiny Supporter
  • Posts: 272
  • Location: Singapore
  • some keyboard thing
    • octobrain
Re: M0110 to Bluetooth Project
« Reply #1 on: Thu, 01 January 2015, 17:32:50 »
Very interesting, and your first post too! Welcome!
I subscribed to this thread.
⌨ Filco MJ2 MX Blues / M0116 Orange Alps / Homemade 60% MX Reds / M0110

Cherry MX art prints 20/50 still available!

Offline 0100010

  • Posts: 1127
  • Location: DFW, TX, US
  • Not Sure
Re: M0110 to Bluetooth Project
« Reply #2 on: Thu, 01 January 2015, 23:17:11 »
Why does it have resisted power going to the same pins as clock and data on the teensy?
  Quoting me causes a posting error that you need to ignore.

Offline hasu

  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: M0110 to Bluetooth Project
« Reply #3 on: Fri, 02 January 2015, 00:30:19 »
Why does it have resisted power going to the same pins as clock and data on the teensy?
Those are pull-up resistors, without them controller can miss keyboard signal or can't read it at all.


AEChadwick,
It seems to me its wiring is good, just don't connect battery and USB at the same time :D.
I don't have any experience with Bluefruit, though.
keep us updated!

Quote
*i do not require further/software control of the bluefruit—I just need it to broadcast the keypresses—so it does not seem necessary to add the bluefruit-specific protocol, like include $(TOP_DIR)/protocol/bluefruit.mk to m0110_usb/Makefile
Not sure I can understand you correctly, tmk firmware doesn't send any data with USART by default and I think you have to include bluefruit protocol to send data to the bluetooth module.

Offline AEChadwick

  • Thread Starter
  • Posts: 6
Re: M0110 to Bluetooth Project
« Reply #4 on: Fri, 02 January 2015, 16:46:05 »
Here is the hardware in progress—the protoboard is wired up, with a little input panel off to the side (i added buttons for reset and pairing, and feedback LEDs, just to keep track--but hidden on the rear of the case, so no distractions from typing!) The charger’s USB port fit nicely into the keyboard-lock slot (with just a little help from a the dremyl).

The convertor works fine, and the bluefruit pairs perfectly—they just don't talk to each other yet! I am pushing through the repository, trying to understand how to incorporate the protocols correctly. I’m open to any guidance, honestly.

hasu, thank you for the reply! my “i don’t require” comment was me Not-Understanding how the tmk firmware works. I tend to have more enthusiasm than ability...

(I will post any additions I make to code for everyone’s perusal.)

Thanks for checking it out!

—Æ

Offline AEChadwick

  • Thread Starter
  • Posts: 6
Re: M0110 to Bluetooth Project
« Reply #5 on: Fri, 02 January 2015, 17:12:54 »
I am attempting to modify /tmk_keyboard-master/converter/m0110_usb to get the teensy to talk to the bluefruit EZ-Key.

this pass is based on studying tmk_keyboard-master/converter/terminal_bluefruit which seems identical in scope to the project.

I added this block to /tmk_keyboard-master/converter/m0110_usb_bluefruit/config.h

@line 40
Code: [Select]
/* USART configuration
 *     asynchronous, 9600baud, 8-data bit, non parity, 1-stop bit, no flow control
 */
#ifdef __AVR_ATmega32U4__
    #define SERIAL_UART_BAUD       9600
    #define SERIAL_UART_DATA       UDR1
    #define SERIAL_UART_UBRR       ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
    #define SERIAL_UART_RXD_VECT   USART1_RX_vect
    #define SERIAL_UART_TXD_READY  (UCSR1A&(1<<UDRE1))
    #define SERIAL_UART_INIT()     do { \
        UBRR1L = (uint8_t) SERIAL_UART_UBRR;       /* baud rate */ \
        UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8);  /* baud rate */ \
        UCSR1B = (1<<TXEN1);                /* TX: enable */ \
        UCSR1C = (0<<UPM11) | (0<<UPM10) | /* parity: none(00), even(01), odd(11) */ \
                 (0<<UCSZ12) | (1<<UCSZ11) | (1<<UCSZ10); /* data-8bit(011) */ \
        sei(); \
    } while(0)
#else
#   error "USART configuration is needed."
#endif

and these blocks to /tmk_keyboard-master/converter/m0110_usb_bluefruit/Makefile

@line 25 , after CONFIG_H = config.h
Code: [Select]
BLUEFRUIT_TRACE_SERIAL=true

@line 96 , before include $(TOP_DIR)/protocol/lufa.mk
Code: [Select]
include $(TOP_DIR)/protocol/bluefruit.mk
this results in a Make error:

Code: [Select]
Compiling C: ../../protocol/bluefruit/main.c
avr-gcc -c -mmcu=atmega32u4        -gdwarf-2 -DF_CPU=16000000UL -DINTERRUPT_CONTROL_ENDPOINT -DBOOTLOADER_SIZE=4096 -DPROTOCOL_BLUEFRUIT -DPROTOCOL_PJRC -DMOUSEKEY_ENABLE -DMOUSE_ENABLE -DEXTRAKEY_ENABLE -DCONSOLE_ENABLE -DCOMMAND_ENABLE -DVERSION=unknown -Os -funsigned-char -funsigned-bitfields -ffunction-sections -fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Wstrict-prototypes -Wa,-adhlns=obj_m0110_lufa/protocol/bluefruit/main.lst -I. -I../.. -I../../protocol/bluefruit -I../../protocol/pjrc -I../../protocol -I../../common -std=gnu99 -include config.h -MMD -MP -MF .dep/obj_m0110_lufa_protocol_bluefruit_main.o.d  ../../protocol/bluefruit/main.c -o obj_m0110_lufa/protocol/bluefruit/main.o
../../protocol/bluefruit/main.c: In function 'main':
../../protocol/bluefruit/main.c:107:17: error: too few arguments to function 'suspend_power_down'
                 suspend_power_down();
                 ^
In file included from ../../protocol/bluefruit/main.c:33:0:
../../common/suspend.h:9:6: note: declared here
 void suspend_power_down(uint8_t timeout);
      ^
make: *** [obj_m0110_lufa/protocol/bluefruit/main.o] Error 1
So. i will keep exploring.

—Æ

Offline ezrahilyer

  • Posts: 110
Re: M0110 to Bluetooth Project
« Reply #6 on: Fri, 02 January 2015, 17:55:13 »
I am doing this mod myself right now. (I have the parts ordered from Adafruit)

I had converted a M0110 to USB, and was selling it, but then had it commissioned by a DT member to convert it to Bluetooth. Maybe we can compare notes.
-Ezra

Offline hasu

  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: M0110 to Bluetooth Project
« Reply #7 on: Fri, 02 January 2015, 21:16:33 »
I updated core API some ago but forgot to fix some codes using the old API. This causes that compile error.

I committed fix to my github repository, try the latest code.
https://github.com/tmk/tmk_keyboard/commit/06527bde4f873ffc6eb8e359fb3b150e880b89ba

Offline AEChadwick

  • Thread Starter
  • Posts: 6
Re: M0110 to Bluetooth Project
« Reply #8 on: Sat, 03 January 2015, 00:32:57 »
holy smokes, done & done & thank you hasu!

final tally is...

add to config.h:
Code: [Select]
/* USART configuration
 *     asynchronous, 9600baud, 8-data bit, non parity, 1-stop bit, no flow control
 */
#ifdef __AVR_ATmega32U4__
    #define SERIAL_UART_BAUD       9600
    #define SERIAL_UART_DATA       UDR1
    #define SERIAL_UART_UBRR       ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
    #define SERIAL_UART_RXD_VECT   USART1_RX_vect
    #define SERIAL_UART_TXD_READY  (UCSR1A&(1<<UDRE1))
    #define SERIAL_UART_INIT()     do { \
        UBRR1L = (uint8_t) SERIAL_UART_UBRR;       /* baud rate */ \
        UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8);  /* baud rate */ \
        UCSR1B = (1<<TXEN1);                /* TX: enable */ \
        UCSR1C = (0<<UPM11) | (0<<UPM10) | /* parity: none(00), even(01), odd(11) */ \
                 (0<<UCSZ12) | (1<<UCSZ11) | (1<<UCSZ10); /* data-8bit(011) */ \
        sei(); \
    } while(0)
#else
#   error "USART configuration is needed."
#endif

add to Makefile:
Code: [Select]
BLUEFRUIT_TRACE_SERIAL=true

also in makefile, replace
Code: [Select]
include $([/b]TOP_DIR)/protocol/lufa.mk
with
Code: [Select]
include $(TOP_DIR)/protocol.mk
include $(TOP_DIR)/protocol/bluefruit.mk

(and I changed the target file name to TARGET = m0110_bluefruit just to be clear and complete.)

my tiny little changes are published here for reference...

https://github.com/AEChadwick/m0110_usb_bluefruit

Here's a few pictures...

Establishing shot to show "look ma no wires."
Close-up of my attempt at a discrete panel. (next version: make a pretty on-off button, and figure out how to make the "keypress" LED actually do something...)
Detail of battery-charger's mini-USB port in the keyboard lock slot. (I had some reason for removing the RJ44, but i don�t recall...)
And a view of the charger plugged in.

thank you geekhack for the inspiration and thank you hasu & company for all the actual work. I stood on the shoulders of giants, and now I have a Bluetooth Original Mac Keyboard. It's really great. I'm going to make another.

*and godspeed ezrahilyer, show us what you do!
« Last Edit: Sat, 03 January 2015, 00:37:29 by AEChadwick »

Offline 0100010

  • Posts: 1127
  • Location: DFW, TX, US
  • Not Sure
Re: M0110 to Bluetooth Project
« Reply #9 on: Sat, 03 January 2015, 11:06:37 »
Great job!  Looks amazing.
  Quoting me causes a posting error that you need to ignore.

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: M0110 to Bluetooth Project
« Reply #10 on: Sat, 03 January 2015, 13:39:43 »
Not the prettiest looking keyboard but I guess it's good to type on or you wouldn't be doing this.  Nice of them to put a big cavity in the base for your electronics too..

A very tidy mod inside and out, well done :)
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline nandop

  • Posts: 87
  • Location: USA
  • May your keystrokes always be true.
Re: M0110 to Bluetooth Project
« Reply #11 on: Sun, 04 January 2015, 20:16:53 »
I want to do this to a matrix I made. Do I use your config modification and steps? Would I need to have to assign the D3 D4 pins as RX TX or can I just connect the RX TX to each of the boards and load the TMK firmware like normal, and it would just work?
Sprit 60%, White MX 78g Au | Planck Ortholinear 40% Clear MX | Phantom TKL Browns 110g Au

Offline AEChadwick

  • Thread Starter
  • Posts: 6
Re: M0110 to Bluetooth Project
« Reply #12 on: Mon, 05 January 2015, 00:05:44 »
hello nandop!

the config & makefile modifications that I inserted tell the teensy to send info to the bluefruit by enabling the teensy's RX/TX on the default pins of D2/D3. without these code insertions, the teensy does not send anything to TX. In this modification, the tmk firmware still does all the work (converting the keyboard information), and the bluefruit is already set-up to send the information to the paired computer. these code insertions were mostly taken from tmk_keyboard/converter/terminal_bluefruit, and they should work with any other converter or keyboard in the tmk project. I hope that makes sense!!!

—AE
« Last Edit: Mon, 05 January 2015, 00:07:35 by AEChadwick »

Offline nandop

  • Posts: 87
  • Location: USA
  • May your keystrokes always be true.
Re: M0110 to Bluetooth Project
« Reply #13 on: Mon, 05 January 2015, 07:01:24 »
hello nandop!

the config & makefile modifications that I inserted tell the teensy to send info to the bluefruit by enabling the teensy's RX/TX on the default pins of D2/D3. without these code insertions, the teensy does not send anything to TX. In this modification, the tmk firmware still does all the work (converting the keyboard information), and the bluefruit is already set-up to send the information to the paired computer. these code insertions were mostly taken from tmk_keyboard/converter/terminal_bluefruit, and they should work with any other converter or keyboard in the tmk project. I hope that makes sense!!!

—AE

Thank you so much! It does clarify what I had in mind. Are you using 2500 mAH for battery? I saw that they are getting around 24hours of usage from adafruit's website. Have you had similar results?
Sprit 60%, White MX 78g Au | Planck Ortholinear 40% Clear MX | Phantom TKL Browns 110g Au

Offline AEChadwick

  • Thread Starter
  • Posts: 6
Re: M0110 to Bluetooth Project
« Reply #14 on: Mon, 05 January 2015, 09:18:50 »

Thank you so much! It does clarify what I had in mind. Are you using 2500 mAH for battery? I saw that they are getting around 24hours of usage from adafruit's website. Have you had similar results?

heavens, man! I’ve barely had it finished for 24-hours, let alone used it that much time! :) The keyboard has come to work with my today; I’ll let you know how the battery does.

—AE

Offline nandop

  • Posts: 87
  • Location: USA
  • May your keystrokes always be true.
Re: M0110 to Bluetooth Project
« Reply #15 on: Mon, 05 January 2015, 09:30:41 »

Thank you so much! It does clarify what I had in mind. Are you using 2500 mAH for battery? I saw that they are getting around 24hours of usage from adafruit's website. Have you had similar results?

heavens, man! I’ve barely had it finished for 24-hours, let alone used it that much time! :) The keyboard has come to work with my today; I’ll let you know how the battery does.

—AE

My apologies! I didn't realize that :P I'm glad you got it working! That's awesome!!
Sprit 60%, White MX 78g Au | Planck Ortholinear 40% Clear MX | Phantom TKL Browns 110g Au

Offline ezrahilyer

  • Posts: 110
Re: M0110 to Bluetooth Project
« Reply #16 on: Sat, 10 January 2015, 11:11:48 »
I am deep into a very very similar mod that was commissioned by a DH member, and I am having trouble getting the Pro micro (in my case) and the blue fruit to communicate. I am using the updated code published here. After a while (2 or3 minutes) the green TX light will light on the pro micro, but no keypresses seem to be registering on the blue fruit.

I have compiled, and re-compiled, and tried minor code tweaks thinking it might be a pin assignment problem, but my code skills are let us say B.A.S.I.C , so I am at a bit of a loss as to why this isn't working for me when I am using essentially the same schematic.

the only real difference is that the board I am using is a pro micro which has the 32u4 chip just like the teensy, and the TX0 pin is the same as PD3 (goes to the same physical pin on the 32u4 chip) so unless there is some naming convention I am missing, I am confounded what in the heck is going on.

Any input would be appreciated, next I am going to set up a dummy serial output to test the RX of the blue fruit in the off chance the blue fruit isn't listening.

This is the hardware progress so far. (doesn't show the pro micro)



Offline Sirric

  • Posts: 10
Re: M0110 to Bluetooth Project
« Reply #17 on: Sun, 08 February 2015, 16:42:07 »
I am using the bluesmirf module, i tried making your edits to the very simple onekey keyboard project. No luck though, no output through bluetooth. It pairs and i see it connected, but cant register a keypress. I am wondering if anyone has any ideas what i would need to modify to get it working. Its the same RN 42, so i thought it would be a direct port, i guess there is more to it than that?

https://www.sparkfun.com/products/10938

Offline Sirric

  • Posts: 10
Re: M0110 to Bluetooth Project
« Reply #18 on: Mon, 09 February 2015, 14:37:28 »
Interesting error i came across. I must say that i am not a coding expert, or even very good at it. I made the changes to the makefile, for both makefile and makefile.pjrc. If i run "make -f makefile" i get the error below.

 ... multiple definition of '_vector_10' ... it list a file usbinterrupt_AVR8.c ... there are multiple "multiple definition of different vectors" errors. it ends with ../rule.mk:534: recipe for target 'onekey_lufa.elf' failed made ... error 1.

I do not see this error with the make -f makefile.pjrc . However i cant get either to work with my bluesmirf module. Smasher had mentioned he had to change the bit ordering. Not 100% sure where/what to change. I can get the teensy to communicate through the bluesmirf module by using some passthrough code on the teensy, typing in a console that outputs through the teensy to the bluetooth module, which sends the characters to another computer through bluetooth. So i know that it works, I think its just a matter of bit ordering and formatting.

Like i mentioned im terrible at coding, its probably something stupidly simple.

Offline kanzakisol

  • Posts: 5
Re: M0110 to Bluetooth Project
« Reply #19 on: Fri, 13 May 2016, 15:13:21 »
Sorry to revive something so old, but I tried to use this method with a custom 5 key keyboard I'm making. I added the lines to the config.h and Makefile, however, I'm getting an error when compiling. The first error is in reference to the config.h file, and if I'm able to bypass that (by commenting it out) I'm getting a bunch of additional errors from the bluefruit.c file. Any help or direction would be awesome.

Edit: forgot to mention, I'm using Teensy ++2.0
« Last Edit: Fri, 13 May 2016, 15:15:09 by kanzakisol »

Offline hasu

  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: M0110 to Bluetooth Project
« Reply #20 on: Fri, 13 May 2016, 15:54:52 »
In some ago I changed AL_* macro names in tmk_core/common/report.h. You'll have to your bluefruit.c.
https://github.com/tmk/tmk_keyboard/commit/5e9b21d77d71bede3fbcbefd7567af22f3b0d153#diff-a0491e81b807e56c2e81927007dea485L49

And you have to have USART setting for your controller(AT90USB1286, iirc) in config.h. Read datasheet of the controller, I think it is not so different from ATMega32u4.

Offline kanzakisol

  • Posts: 5
Re: M0110 to Bluetooth Project
« Reply #21 on: Thu, 19 May 2016, 10:11:48 »
Thanks a bunch Hasu, hadn't known about the change in AL_* macro changes. I actually ended up not needing the consumer keys and commented them out of my file. The issue with the config.h ended up being a simple issue of me not capitalizing the USB in the #ifdef line lol. I had to do some more minor changes in regards to references made in some of the header files, however, the errors explained those a bit more clearly and where fairly straight forward changes. Thanks again both for the help and the great firmware!

Offline TicTocTom

  • Posts: 3
  • Location: Montreal
Re: M0110 to Bluetooth Project
« Reply #22 on: Mon, 04 May 2020, 18:42:05 »
I wish I were smart enough to follow you here. I stand in awe of your projects.