Author Topic: Programmable USB stick with Bluetooth  (Read 7734 times)

0 Members and 1 Guest are viewing this topic.

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Programmable USB stick with Bluetooth
« on: Wed, 18 December 2013, 04:58:07 »
Hi everyone,

I'm thinking how to design my keyboard project. The keyboard will be in 2 separate pieces, one for each hand, and it needs to be connected wirelessly to the computer.

I think that I want to have a USB stick connected to the computer. It'll need to be responsible for (1) communicating with the 2 separate pieces of the keyboard using Bluetooth, (2) processing the keypresses using my custom logic that I'll program into it, and (3) present itself to the computer as standard USB HID, so there'll be no need for custom drivers.

I've never done such a project before. Does there exist a USB stick that'll allow me to do these 3 items?


Thanks,
Ram.

Offline bcg

  • Posts: 112
Re: Programmable USB stick with Bluetooth
« Reply #1 on: Wed, 18 December 2013, 22:40:37 »
I think you could use something like this:

http://www.ebay.com/itm/RS232-TTL-HC-05-Wireless-Bluetooth-Transceiver-Module-Host-Master-Slave-5-Pcs-/221317664191?pt=US_USB_Bluetooth_Adapters_Dongles&hash=item33878f8dbf

Hook one up to something like this with the USB HID firmware on it:

http://www.ebay.com/itm/200916694292?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649

Those two components would be your dongle.

Then in your keyboard you could transmit keystrokes to the dongle over the bluetooth serial

I don't see the advantage of doing that though over using an HID bluetooth component with a regular bluetooth adapter dongle plugged into the computer... although I guess you could have more than 6KRO by sending the commands over bluetooth serial and then use some sorcery like in Soarer's converter or hasu's firmware
:wq!

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #2 on: Thu, 19 December 2013, 06:58:42 »
Thanks bcg!

Problem is, the Bluetooth module you showed me supports only BT 2.0. I want to use Bluetooth 4 Low Energy.

I've googled around and found a bunch of different modules for this, but I'd really like a recommendation. I don't want to just pick one randomly because they have good sales copy on their website. I'm hoping to find someone who can tell me which one I should get.

Regarding the advantage of my approach over Bluetooth HID: I need to run my own custom logic on the keyboard before sending events to the computer. For example, I want "btw\" to be automatically deleted and changed to "by the way ". (I currently do this on the computer using AHK but I want a solution that doesn't depend on OS.)

Offline kolonelkadat

  • Posts: 180
  • Location: the vicinity of an area adjacent to a location
    • Force Project X
Re: Programmable USB stick with Bluetooth
« Reply #3 on: Thu, 19 December 2013, 08:05:28 »
use the nordic semi nRF8001 Bluetooth Smart connectivity IC and the Cortex M0 MCU for ultimate low power goodness.

http://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF8001
http://www.nxp.com/products/microcontrollers/cortex_m0_m0/

eta: youll have to roll your own circuits, but youre doing that anyways right? also i think I read wrong. I thought you wanted the keyboard halves to talk to each other and have one half with the main logic, then the main logic half could communicate to pc.

btw i guess if you dont really care about power consumption, you could always just use http://redbearlab.com/blemini/ to do the bluetoothin and whatever mcu to handle keyboard logic.
« Last Edit: Thu, 19 December 2013, 08:19:17 by kolonelkadat »
"Obviously, windows are central to Windows. But what is a window?"

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #4 on: Thu, 19 December 2013, 10:45:13 »
Thanks kolonelkadat!

But... Given that I'm an electronics newbie, I'd much prefer to have an assembled device rather than one where I need to assemble the chips. (This project is going to be very hard for me as it is.) Is there such a thing?

Also, each piece of the keyboard would have ~50 keys, so I'll need 50 I/O ports, no? The chips you showed me have less than that. How can I deal with that?


Thanks,
Ram.

Offline tufty

  • Posts: 347
  • Location: French Alps
Re: Programmable USB stick with Bluetooth
« Reply #5 on: Thu, 19 December 2013, 13:26:38 »
Let's assume you have 64 keys.  This can be encoded using a matrix of 8 rows and 8 columns, thus requiring only 16 GPIOs. 

You can get away with less, though, if you need to, by using (for example) a multiplexer or an IO expander connected using SPI or i2c.

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #6 on: Thu, 19 December 2013, 13:42:18 »
tufty, let me see whether I understand you correctly.

Do you mean that every keyswitch will short two circuits, one for column and one for row, and I'll deduce which key it was by the combination of row and column?

If so, I see two problems with that:

1. Cherry has only two pins.

2. If I press two keys simultaneously, how could the keyboard know which ones I pressed?

Offline tufty

  • Posts: 347
  • Location: French Alps
Re: Programmable USB stick with Bluetooth
« Reply #7 on: Thu, 19 December 2013, 14:02:58 »

Offline agodinhost

  • Posts: 767
  • Location: Brazil, RJ
  • Soylent green is people ...
    • Dr Ian O Xaman
Re: Programmable USB stick with Bluetooth
« Reply #8 on: Thu, 19 December 2013, 14:17:00 »
use the nordic semi nRF8001 Bluetooth Smart connectivity IC and the Cortex M0 MCU for ultimate low power goodness.

http://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF8001
http://www.nxp.com/products/microcontrollers/cortex_m0_m0/

eta: youll have to roll your own circuits, but youre doing that anyways right? also i think I read wrong. I thought you wanted the keyboard halves to talk to each other and have one half with the main logic, then the main logic half could communicate to pc.

btw i guess if you dont really care about power consumption, you could always just use http://redbearlab.com/blemini/ to do the bluetoothin and whatever mcu to handle keyboard logic.
hmmm, interisting IC dude!
The new enhanced version does have support for HID!!
I did a search on ebay and I found a few dev boards per 15 bucks! I just hope that it cames with the new "enhanced" firmware ...
awesome!!!
TY
Building one square I2C keyboard with those 1200 switches (thanks JDCarpe)
GH60 |GH60-Alps |GH60-BT |GHPad/GHPad Alps |GH60-Case |Alps TKL |EL Wire |OS Controller, Round 2 |My Custom Keyboard |WTT/WTB

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #9 on: Thu, 19 December 2013, 15:44:08 »
Read, be enlightened -> http://www.dribin.org/dave/keyboard/one_html/

Thanks, that was interesting!

But... I need more clarification on the scanning process. Which device does the scanning? In what frequency? I want to build a keyboard that does this so I need all the information I can get.

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #10 on: Thu, 19 December 2013, 16:01:17 »
eta: youll have to roll your own circuits, but youre doing that anyways right? also i think I read wrong. I thought you wanted the keyboard halves to talk to each other and have one half with the main logic, then the main logic half could communicate to pc.

btw i guess if you dont really care about power consumption, you could always just use http://redbearlab.com/blemini/ to do the bluetoothin and whatever mcu to handle keyboard logic.

Thanks kolonelkadat.

Unfortunately the RedBearLab BLE Mini is not a good fit for me because it has only 0.5 MB of non-volatile storage. I need 10 MB.

I actually don't know whether I'm rolling my own circuits or not. I'm hoping I won't have to, but it's the first time I'm building a project like this, so I have no idea.


Thanks,
Ram.

Offline tufty

  • Posts: 347
  • Location: French Alps
Re: Programmable USB stick with Bluetooth
« Reply #11 on: Fri, 20 December 2013, 04:20:10 »
Read, be enlightened -> http://www.dribin.org/dave/keyboard/one_html/

Thanks, that was interesting!

But... I need more clarification on the scanning process. Which device does the scanning? In what frequency? I want to build a keyboard that does this so I need all the information I can get.

The keyboard matrix itself is passive.  There is always* a microcontroller that does the matrix scanning and converts keypresses into some sort of event to be sent elsewhere.  If you have 2 parts that you want to connect wirelessly, you will most probably need a bluetooth-enabled microcontroller in each part.  Most people round here are using AVR microcontrollers of one sort or another (teensy's mainly), and there's a wealth of source code out there that shows how the scanning side of things works.

Frequency doesn't really matter as long as it's fast enough to catch all the keypresses.

Unfortunately the RedBearLab BLE Mini is not a good fit for me because it has only 0.5 MB of non-volatile storage. I need 10 MB.
What?  The non volatile storage on that is for firmware, not data storage.  Why on earth would you think you'd need 10MB?

I actually don't know whether I'm rolling my own circuits or not. I'm hoping I won't have to, but it's the first time I'm building a project like this, so I have no idea.
Yes you are, and no you don't. Do some reading, look into how the ergodox works (apart from the wireless side of things, it's probably the closest to what you want), you need to do a lot of reading.

Simon

* Some early machines had the CPU scan the keyboard matrix, but we'll let that pass.  These days, there's a microcontroller, and that's it.

Offline bcg

  • Posts: 112
Re: Programmable USB stick with Bluetooth
« Reply #12 on: Fri, 20 December 2013, 07:39:09 »

Problem is, the Bluetooth module you showed me supports only BT 2.0. I want to use Bluetooth 4 Low Energy.

I've googled around and found a bunch of different modules for this, but I'd really like a recommendation. I don't want to just pick one randomly because they have good sales copy on their website. I'm hoping to find someone who can tell me which one I should get.

Regarding the advantage of my approach over Bluetooth HID: I need to run my own custom logic on the keyboard before sending events to the computer. For example, I want "btw\" to be automatically deleted and changed to "by the way ". (I currently do this on the computer using AHK but I want a solution that doesn't depend on OS.)

You could still do this kind of thing with a Bluetooth HID; I hooked Adafruit's Bluefruit up to an atmega 32u4 running hasu's firmware and it works fine.  hasu's work is super customizable and I'm sure you could make some really advanced macros and handle all of the processing irrespective of the bluetooth module

Bluefruit uses ~25mA - not sure about what bluetooth low energy is so I can't really compare

hasu's tmk firmware has all of the code you need for matrix scanning, macros, etc. so I would suggest using that as a starting point.  The architecture is very nice and allows you to easily switch out implementations for your matrix, protocol, etc.  If you look in converters/terminal_bluefruit and protocol/bluefruit you can see the integration that I did with Bluefruit (my code is admittedly lame but it gets the job done)

hth

:wq!

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #13 on: Fri, 20 December 2013, 14:49:19 »
Regarding the advantage of my approach over Bluetooth HID: I need to run my own custom logic on the keyboard before sending events to the computer. For example, I want "btw\" to be automatically deleted and changed to "by the way ". (I currently do this on the computer using AHK but I want a solution that doesn't depend on OS.)

You could still do this kind of thing with a Bluetooth HID; I hooked Adafruit's Bluefruit up to an atmega 32u4 running hasu's firmware and it works fine.  hasu's work is super customizable and I'm sure you could make some really advanced macros and handle all of the processing irrespective of the bluetooth module

bcg, I'm not sure how that would work. Where do you propose to put the Bluefruit? As I said, my keyboard will come in two pieces. The logic that I need will process events from both pieces, and decide based on that which keys to actually send to the computer. (To do abbreviation expansion etc.) Then where could the Bluefruit be? It connects to the computer via Bluetooth as a HID, so I presume you suggest to put it on one of the keyboard pieces? Then how would it get data from the second piece of the keyboard to do its logic? Another Bluetooth connection from piece 1 to piece 2? Then we have the problem of double latency.

This is why I wanted both pieces to have Bluetooth board that communicate with a USB dongle on the computer that has (a) custom logic and (B) Bluetooth communication. So I don't see how Bluefruit can be used here.

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #14 on: Fri, 20 December 2013, 15:08:49 »
Thanks for your help Simon. I have a few questions.

The keyboard matrix itself is passive.  There is always* a microcontroller that does the matrix scanning and converts keypresses into some sort of event to be sent elsewhere.  If you have 2 parts that you want to connect wirelessly, you will most probably need a bluetooth-enabled microcontroller in each part.  Most people round here are using AVR microcontrollers of one sort or another (teensy's mainly), and there's a wealth of source code out there that shows how the scanning side of things works.

Frequency doesn't really matter as long as it's fast enough to catch all the keypresses.

Let me see whether I understand you correctly: For each of the two pieces of the keyboard, I need to get a Teensy board, connect it to a Bluetooth chip like nRF8001 (it can be on a breadboard right?), connect the keyswitches to the Teensy inputs in a matrix (with diodes in the correct places for each keyswitch), and then put code on the Teensy that'll (1) get key events by scanning the matrix and (2) transmit those keys using the nRF8001 to the USB dongle connected to the computer. I'll also need a battery to be powering both the Teensy and the nRF8001.

Did I get this right? Did I leave any component out? And is there ready-made software for the Teensy that'll do the matrix scanning?

Unfortunately the RedBearLab BLE Mini is not a good fit for me because it has only 0.5 MB of non-volatile storage. I need 10 MB.
What?  The non volatile storage on that is for firmware, not data storage.  Why on earth would you think you'd need 10MB?

The reason I need 10 MB is for all the abbreviations to be expanded, and possibly other data. Currently my abbreviation scripts weigh about 0.5 MB, and they include all my abbreviations. I want to have enough space to not have to worry about having too many abbreviations.

So you're saying that this data belongs on "data storage" rather than "firmware"? What do I use for data storage?

I actually don't know whether I'm rolling my own circuits or not. I'm hoping I won't have to, but it's the first time I'm building a project like this, so I have no idea.
Yes you are, and no you don't. Do some reading, look into how the ergodox works (apart from the wireless side of things, it's probably the closest to what you want), you need to do a lot of reading.

Gladly, but what should I read? I looked at the Ergodox thread but it's ~100 pages. I read the first 4 pages but it's all stuff that isn't relevant to me. Should I plow through all of it? Or is there something more specific?


Thanks for all your help,
Ram.

Offline tufty

  • Posts: 347
  • Location: French Alps
Re: Programmable USB stick with Bluetooth
« Reply #15 on: Fri, 20 December 2013, 15:47:06 »
Let me see whether I understand you correctly: For each of the two pieces of the keyboard, I need to get a Teensy board, connect it to a Bluetooth chip like nRF8001 (it can be on a breadboard right?), connect the keyswitches to the Teensy inputs in a matrix (with diodes in the correct places for each keyswitch), and then put code on the Teensy that'll (1) get key events by scanning the matrix and (2) transmit those keys using the nRF8001 to the USB dongle connected to the computer. I'll also need a battery to be powering both the Teensy and the nRF8001.
Bang on.  Doesn't need to be a teensy, of course, but that's pretty much the gist of it, yes.  Software-wise, for the "keyboard" half, you should be able to use Hasu's tmk firmware to do most or all of this with little modification.

For the "computer" side of things, the easiest way to do things would be to use the machine's standard bluetooth (or an add-on, off-the-shelf, dongle) and some custom userland driver software that takes events from the 2 boards and converts them into something understandable.  That's where your X MB of storage comes in - all on your computer.  If you're using windows, I have no idea how you'd do this.

It would be a bloody sight easier, though, to tether the two bits of board together and use a uC with a bit more "oomph" to do the scanning, lookup, and bluetooth, presenting itself to the computer as a standard bluetooth HID device.  Downside is that it would need a bigger battery and a uC with "real time" access to a lot of storage.  That's a (relatively) tough one to find, but bare metal coding on something like the Raspberry Pi, or one of the Xmos boards could probably do it.  No "base" software to work from, though, the whole lot would have to be bespoke.  Or you could stick with the teensy (but only one of them, handling both halves of the board via a wired connection) and use, again, client-side software on the computer to do the expansion.

What you are trying to do is hard.

Read the tmk firmware thread, with the code to hand, and work out what's going on in it.  Build it a few times, with different options.  That should get you started on understanding how to do the scanning and bluetooth HID stuff.

Offline bcg

  • Posts: 112
Re: Programmable USB stick with Bluetooth
« Reply #16 on: Fri, 20 December 2013, 21:47:58 »

bcg, I'm not sure how that would work. Where do you propose to put the Bluefruit? As I said, my keyboard will come in two pieces. The logic that I need will process events from both pieces, and decide based on that which keys to actually send to the computer. (To do abbreviation expansion etc.) Then where could the Bluefruit be? It connects to the computer via Bluetooth as a HID, so I presume you suggest to put it on one of the keyboard pieces? Then how would it get data from the second piece of the keyboard to do its logic? Another Bluetooth connection from piece 1 to piece 2? Then we have the problem of double latency.

This is why I wanted both pieces to have Bluetooth board that communicate with a USB dongle on the computer that has (a) custom logic and (B) Bluetooth communication. So I don't see how Bluefruit can be used here.

Sorry I forgot you said you wanted 2 pieces

Might still only want 1 bluetooth module though, using a HID breakout like Bluefruit or RN-42 or Bluegiga with iWrap.  As far as I know bluetooth pairing is 1 to 1, so either your dongle would need 2 bluetooth transceivers or one of the pieces of the keyboard would need 2 transceivers.  You could have the two halves communicate with a different (probably cheaper) device; for that matter you could have both halves communicate with the dongle without bluetooth also.  Something like these maybe:

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

If you can ditch the requirement for both peices to be wireless then you would save yourself a lot of headaches.  Two pieces means you need 2 battery/charging circuits (that could get really annoying) plus wireless with the two halves could be tricky (what if one half has latency or gets disconnected and only half of your key combo is sent?).  At least if you do have 2 wireless halves, I would recommend having them communicate with each other and then have 1 talk to the computer (or dongle).

The suggestion to have your macros run on the host side is good... although if you require a solution that could be used on multiple machines or machines where you can't install a driver I could totally see why you would want that to happen in the keyboard itself.  Might be really useful if you're using a server room kvm or something like that

If you need storage in your keyboard this could probably work:

http://www.digikey.com/product-detail/en/W25Q80BVDAIG/W25Q80BVDAIG-ND/2208452

DIP package, SPI interface, and $.50 - its only 8MB not 10 but sounds like that would still be enough for you.

Finally you don't need a teensy in both halves... they are kind of expensive, and probably one or both of your halves really only needs to scan the matrix and forward the status to the microcontroller.  You could use something much less powerful (and expensive) than a teensy for that.  Also if you're running off of battery power you might want a lower voltage than 5V... you can run teensy at 3.3V but you have to solder on a different regulator I think

The more I think about this project, you might just want to start with the ergodox design and build out your extra features/layout on top of that platform.  That would be a much less forboding project to start with, and the benefit of starting with a working platform means that you could hack around with a lot of this stuff on a breadboard and see what works best

Good luck with your project!  Sounds like a cool one
:wq!

Offline cool-RR

  • Thread Starter
  • Posts: 53
  • Location: Tel-Aviv, Israel
Re: Programmable USB stick with Bluetooth
« Reply #17 on: Sat, 21 December 2013, 16:21:57 »
Thanks everyone for your help!

Offline sheikhshuhad

  • Posts: 1
  • Location: stockholm
    • bleuIO - Bluetooth low energy adapter
Re: Programmable USB stick with Bluetooth
« Reply #18 on: Fri, 25 September 2020, 02:37:47 »
I think you could use something like this:
https://www.bleuio.com/
Its a bluetooth low energy adapter. You can develop bluetooth low energy application with it. you can use their firmware or flash your own firmware into it and start coding. i turned my raspberry pi into iBeacon with it. it worked.
You can also have a look at getting started guide
https://smart-sensor-devices-ab.github.io/ssd005-manual/