Author Topic: Bluetooth HHKB Help  (Read 11547 times)

0 Members and 1 Guest are viewing this topic.

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Bluetooth HHKB Help
« on: Sat, 24 May 2014, 02:16:56 »
All these recent bluetooth threads popping up has sparked my interest in making a bluetooth HHKB. I'v already installed a teensy so I figure how bad could it be. Unfortunately I could use a little bit of help - If this all works out I will turn it into another big write up / guide.

Hasu did a bluetooth mod for the HHKB Pro 1 (http://geekhack.org/index.php?topic=20851.0) but it was for an old version of the tmk software and is mostly outdated. In his new alternative controller prototypes (http://geekhack.org/index.php?topic=12047.0) he has moved to the RN-42-HID chip. The chip supports raw hid reports and the documentation describes the configuration so I think I could get the software in a working state. I'm sure Hasu will come along and iron out all the bugs as he continues his prototyping work.

My issue is the fact that I am primarily a software guy and thus don't know as much about the hardware side of things. The non-SMD version of the RN-42-HID (https://www.sparkfun.com/products/10938) comes with built in voltage regulators and level shifting so it can simply be connected to the Teensy's Vcc/Gnd/Rx/Tx pins. Unfortunately the HHKB internals should be ran at 5V (according to Hasu) so a 3.7V LiPo battery would need to have a step-up/booster inserted. Everything should then be able to run off the 5V power source.

The part I need help with is figuring out how to correctly wire in the battery/charger/step-up/etc. When disconnected the device should run off of battery power and transmit over bluetooth. When plugged in over usb the battery should charge while still running the hardware and retaining the data pins for communication over usb. Pjrc's website (http://www.pjrc.com/teensy/external_power.html) describes using an external power source, however they use traditional batteries. Most LiPo usb LiPo chargers I have found let you attach a battery and load but provide no way of carrying over the data pins. Maybe I should buy a usb breakout board and then wire the D+,D- to the teensy and Vcc,Gnd to the charger which is then wired up to the battery and teensy load (with the matrix and bluetooth module also sharing the Vcc line). I really don't know.

If it is any help here is Hasu's old circuit diagram.
https://raw.githubusercontent.com/tmk/tmk_keyboard/master/keyboard/hhkb/doc/Bluetooth_img/BT_circuit.jpg
https://i.imgur.com/4YXc8SF.jpg

Thanks in advance.



Edit: Here is my currently planned circuit. I believe it should work as follows.


USB Detached, Switch Down - Battery connected, providing power
USB Detached, Switch Up - Battery disconnected, powered off

USB Attached, Switch Up - usb powers circuit and also charges battery (lipo is disconnected to not discharge)
USB Attached, Switch Down - BAD? (both usb and lipo attempt to provide power)

Does anyone see any other possible issues or have suggestions for improvement?

« Last Edit: Sat, 24 May 2014, 15:12:03 by Smasher816 »

Offline engicoder

  • Posts: 721
  • Location: North Carolina
Re: Bluetooth HHKB Help
« Reply #1 on: Sat, 24 May 2014, 20:55:33 »
The diagram Hasu provided is pretty complete (at that time he was using the 168P instead of the now ubiquitous 32U4). If you look at the bottom, he has implemented his own DC/DC boost converter to step up the battery to 5V which is then fed through a manual switch to a simple 5V to 3.3V converter using a linear voltage regulator to provide voltage for the Bluetooth module.
You could use a premade boost converter such as this sparkfun one https://www.sparkfun.com/products/8290

The data lines are completely independent of the supply voltage, so you will have to break them out as you have mentioned. Most of the prebuilt li-po chargers such as the ones from Sparkfun use a USB connector for convenience.

   

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #2 on: Sat, 24 May 2014, 21:38:49 »
Thanks for the info. Most of that I had figured out by now.

I was planning on using the combined lipo charger and booster from sparkfun https://www.sparkfun.com/products/11231. A SPDT switch can then choose between the USB or battery to provide power. 5V should work for everything because the RN-42 comes with a built in level shifter.

I think that should cover everything power related. Luckily sparkfuns parts seem to handle most of the voltage regulation for me so I don't have to built them myself like Hasu did with his custom pcb - simplifying everything.

Any comments on my circuit diagram? I think it should be ok. The only thing I'm not sure about right now is the "USB Attached, Switch Down" state. What happens if both the USB and lipo are connected to the vcc line at the same time, and will it be bad?
« Last Edit: Sat, 24 May 2014, 21:45:54 by Smasher816 »

Offline hasu

  • Posts: 3247
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Bluetooth HHKB Help
« Reply #3 on: Sun, 25 May 2014, 08:48:08 »
This is brief diagram of my old and new BT controller.


And schematic of new controller.
https://github.com/tmk/HHKB_controller/raw/master/HHKB_controller_B140314.pdf

My old controller had some problems.
1) after Lipo is completely exhausted(over discharged?) keyboard doesn't work at all even with plugged into USB until battery is charged at some voltage level.
The controller is supplied power through Lipo battery even if it is pluged in USB.
2) Switching between USB and BT is not done atutomatically. It can't detect cable plug due to limitation of hardware.
3) Pairing/disconnect process is very primitive. Better management of pairing including switching hosts is desirable.

New controller has MOSFET power selector to solve 1). This can supplies USB power directly to system instead of Lipo whenever pluged in. And VBUS pin of ATMega32U4 solves problem 2). With VBUS we can know whether it is plugged in USB or not. 3) depends on mainly firmware development.
I have not completed new controller firmware, so I don't know whether it works.

Looks like your controller has no above hardware problems I have experieced and you can start working on your soldering job now :)


Quote
The only thing I'm not sure about right now is the "USB Attached, Switch Down" state. What happens if both the USB and lipo are connected to the vcc line at the same time, and will it be bad?
Your concern is  a case that UVCC is connected to VBUS(USB power line) while VCC to booster output? I don't think this is harmful, but not sure.
Do you want to connect UVCC to VCC? It is OK, but Teensy connects UVCC and VBUS internally and its will be difficult to cut its trace.
TMK products:HHKB Alt  ⌨ConvertersAlps64FC660C AltFC980C Alt

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #4 on: Sun, 25 May 2014, 11:00:20 »
Thanks for the pictures. I'm glad you think my design is good enough to start testing.

I don't plan on connecting both UVCC and VBUS if there is already a trace. I was just adapating the example scetch you sent in pm. I really need to look at the teensy wiring.

How do would I connect in the D+, D- and other lines. I am thinking about wiring in a mini usb port to plug into the teensy.

Edit: Here is my current BOM. The left column is the SKU's which I'm sure others could use to look up the parts if they want to.
« Last Edit: Sun, 25 May 2014, 16:03:44 by Smasher816 »

Offline bcg

  • Posts: 112
Re: Bluetooth HHKB Help
« Reply #5 on: Sun, 25 May 2014, 19:02:37 »
FYI - IIRC, the TMK host implementation for Bluefruit uses the same protocol over UART as the RN-42 HID... setup & config might be a bit different but the protocol should be the same:

https://github.com/tmk/tmk_keyboard/blob/master/protocol/bluefruit/bluefruit.c

Not sure what you're planning to use for your booster but I saw this the other day and it looks pretty sweet:

http://jiananli.wordpress.com/2014/05/15/lipo-booster
:wq!

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #6 on: Sun, 25 May 2014, 23:43:24 »
Thanks bcg,

The RN-42-HID can use raw reports (of any length?) and also supports consumer keys (including mute, email, etc which were missing on the EZ-Key). See pages 8 and 12 of https://dlnmh9ip6v2uc.cloudfront.net/datasheets/Wireless/Bluetooth/RN-HID-User%20Guide-1.1r.pdf

I didn't realize the tmk firmware already supported the bluefruit protocol (I thought you wrote it yourself when creating the arduino library). If it does not work out of the box it should be fairly simple to adapt.

Regarding the booster I posted mine in my last post. It is a combined lipo charger and booster in one board which is pretty nice. The one you linked me is nice but I would have to find a place to purchase the BOM and then put it together myself. I really don't need breadboard compatibility so it simply doesn't seem like it is worth the hassle  to me. Thanks for the suggestion though :)

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #7 on: Sat, 31 May 2014, 23:31:28 »
Just a little update. All my parts arrived from sparkfun today :D

After a lot of soldering and some testing it appears like my circuit diagram does infact work. When plugged in the teensy+bluesmirf can run off usb power while charging the battery. When unplugged they can still run off the batter successfully.

I just whipped up a quick c program to test the RN-42 out. It correctly sends keys to my android phone which is great. I will have to test it out with TMK using the Ez-Key protocol. Unfortunately the RN-42 will accept a raw HID report with more than 6 keys, but only the first 6 will be sent.

Hopefully I can get a guide created for this after I get everything ironed out and find some time for writing.

Offline hasu

  • Posts: 3247
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: Bluetooth HHKB Help
« Reply #8 on: Sun, 01 June 2014, 00:04:10 »
Nice work.

Yeah, I don't think RN-42HID supports NKRO. It supports standard keyboard, mouse, joystick and consumer reports, but not user defined custom report. I think you have to work with low level API like HCI to achive it.

With Bluegiga iWRAP5 you can define your own report descriptor, IIRC. You will be able to support NKRO without low level work if my memory is correct.
TMK products:HHKB Alt  ⌨ConvertersAlps64FC660C AltFC980C Alt

Offline RESPRiT

  • Posts: 414
  • Location: Seattle
  • HHKB = ❤
Re: Bluetooth HHKB Help
« Reply #9 on: Mon, 02 June 2014, 02:32:55 »
Smasher, your work work is absolutely amazing! Out of curiosity, would you ever sell mod services for those who don't have access to certain resources?
;)

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #10 on: Mon, 02 June 2014, 08:30:12 »
Hasu,
That's what I expected. As far as I know there are no (or very few) NKRO consumer Bluetooth modules. It would be a nice feature but it no deal breaker - 6 keys are fine. I. Pretty sure the stock HHKB controller only sends 6 hey reports.

RESPRiT,
Thanks so much for the kind words. It is always always nice to wake up to :)

Really though nothing is too amazing. Most of this information I have digested from Hasu along with a few other websites. I just did a good job finding and consolidating it into a usuable form. I plan on doing another write up for this Bluetooth mod (just like the Teensy mod) once I get it all working. It should feature a full wiring diagram that should be fairly simple to understand.

As far as the mod services go - I am humbled that you would ask for them. However, I'm only 18 so college will be starting soon and I don't know if I will have the time or resources for it. Also, I learned to solder just for these mods so my soldering skills really aren't that great. You would probably be better off finding someone with some actual skills and pointing them to the circuit diagram and parts list. Luckily everything can be made and tested outside the HHKB - you just plug it in once your done.

Offline RESPRiT

  • Posts: 414
  • Location: Seattle
  • HHKB = ❤
Re: Bluetooth HHKB Help
« Reply #11 on: Mon, 02 June 2014, 11:33:41 »
I'll look forward to the next guide then! I have a few friends who work with robotics and may have ways for me to access soldering equipment and the likes, so maybe I'll look into that. Btw, college might actually allow you more free time than you're expecting, unless you're taking like 5 or more classes next semester :P
;)

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #12 on: Fri, 06 June 2014, 22:44:25 »
Quick status update, written from my HHKB with no wires attached. Yup, that is right I got the bluetooth mod working :cool:

After fixing the serial_uart.c file to work with the atmega32u4 everything went smoothly. The bluefruit code was very similar but required a few small changes (extra length and descriptor bytes in report, and swaped low/high bytes for the consumer keys). I haven't tested out mouse keys yet but I will assume they also work... If I get the code cleaned up maybe Hasu will merge it.

Unfortunately I do not think I cut the 5V trace on the bottom of the teensy correctly, as sometime during setup there was a puff of smoke. Luckily everything seems to still work ok, but the teensy can nolonger be only powered by the Vcc pin and must be powered over usb. A quick hack job of trying the Vcc to the 5V usb fixed everything up. The only issue this presents is the inability to use the VUSB pin to detect if usb is connected as it will always be powered. There are still other ways to switch between bluetooth and USB but they are not as easy (ex: magic keycombo).

There are still a few more things I need to get done. I need to add code to switch between the two protocols as it is currently hardcoded to bluetooth. 'I also need to find a way to get everything laid out so that the case can close completely. I don't have too many pictures but hopefully I can use my paint skills to make a diagram that will make some sense to everyone else. Once all that is done I'll try to write up a little guide for this mod :thumb:
« Last Edit: Fri, 06 June 2014, 22:48:46 by Smasher816 »

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #13 on: Fri, 13 June 2014, 19:55:12 »
Sorry for the silence. Had a pretty busy week. Hopefully I can get the write up done this weekend. I have tested my design and it works alright. I'm sure there is room for improvement with the creative minds here.

I figured out how to use Fritzing to draw my diagram. Not all the parts match 100% because I couldn't find everything, but hopefully it should be close enough to get the point across.


I still need to talk to Hasu about getting the code merged so that all of you can use it :)

Offline byker

  • Literally Canada
  • ** Moderator Emeritus
  • Posts: 3136
  • Location: Gone fishin
Re: Bluetooth HHKB Help
« Reply #14 on: Wed, 06 August 2014, 12:26:19 »
Hey there Smasher! I am really interested in your design.. Hoping to set up my Smallfry board (once I get it) to be bluetooth (it comes with a teensy). Have you managed to do the write up yet?

Offline admiralvorian

  • Posts: 324
  • Location: United States
  • DIY
Re: Bluetooth HHKB Help
« Reply #15 on: Fri, 05 September 2014, 12:38:26 »
smasher this is awesome, keep up the good work.
Darude Status:
☐ Not Sandstorm
☑ Sandstorm                                               wts wtt wtb

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #16 on: Sat, 06 September 2014, 10:53:40 »
Everything works (as shown at keycon), however it's not perfect. For instance you can't turn off the bluetooth chip if your plugged in over usb, etc. I'm not sure how much there will be to the write up besides buy these parts and connect wires between them like in this picture. Maybe I could go into some of the reasoning behind my choices. I'v been extremely lazy on the firmware side since it "works" (but doesn't have connect/disconnect magic keycombo's etc) and because eventually Hasu will have his own code out also, which will probably be better than whatever I happened to write.

Offline admiralvorian

  • Posts: 324
  • Location: United States
  • DIY
Re: Bluetooth HHKB Help
« Reply #17 on: Sat, 06 September 2014, 11:23:48 »
You said you modified some tmk code? Could you give some details on the software setup when.you get.some time? I can definitely put these things together but have no idea how to program it all.
Darude Status:
☐ Not Sandstorm
☑ Sandstorm                                               wts wtt wtb

Offline dorkvader

  • Posts: 6284
  • Location: Boston area
  • all about the "hack" in "geekhack"
Re: Bluetooth HHKB Help
« Reply #18 on: Sun, 07 September 2014, 01:00:38 »
I'd be happy to do the hardware / soldering / testing if someone else can point me to some firmware.

Edit: I'll also need a HHKB and the parts :p

Offline admiralvorian

  • Posts: 324
  • Location: United States
  • DIY
Re: Bluetooth HHKB Help
« Reply #19 on: Wed, 10 September 2014, 00:55:39 »
Saw someone using the bluefruit and TMK, does anyone know if tmk outputs keystrokes on tx/rx when using it on a teensy 2.0? All I would need is to connect it to a bluefruit, then.
Darude Status:
☐ Not Sandstorm
☑ Sandstorm                                               wts wtt wtb

Offline Smasher816

  • HHKB Master
  • Thread Starter
  • Posts: 538
  • Location: return STATE_MISSOURI;
Re: Bluetooth HHKB Help
« Reply #20 on: Wed, 10 September 2014, 01:06:56 »
It depends on what protocol you build with. I'm using a very slightly modified blue fruit one which will output the hid state over serial instead of usb. Ex: see here https://github.com/tmk/tmk_keyboard/tree/master/protocol/bluefruit

Offline admiralvorian

  • Posts: 324
  • Location: United States
  • DIY
Re: Bluetooth HHKB Help
« Reply #21 on: Wed, 10 September 2014, 07:23:12 »
Thanks smasher. So, I can compile the hex for my teensy using this instead of the default tmk code, wire up the correct pins to a bluefruit, and bingo?
Darude Status:
☐ Not Sandstorm
☑ Sandstorm                                               wts wtt wtb

Offline Sirric

  • Posts: 10
Re: Bluetooth HHKB Help
« Reply #22 on: Sun, 08 February 2015, 14:59:14 »
Hey Smasher,

I was wondering if you made any more progress on this, or if the code ever made it to the TMK hub or somewhere else? I have a bluesmirf and a teensy 2.0, I am having trouble integrating it into the TMK flow, not sure exactly what needs changing.

Thanks,
Sirric