Spark Logic

[SOLVED] generic blue pill clone as USB keyboard

taxibunny Wed Apr 25, 2018 6:29 pm

Hiya, had a search around the forum, and it seems like some have got it working, while others haven’t. Instructions seem to be scattered and maybe out of date. Please forgive me if I’m asking an already settled question.

I’d like to set up my generic blue pill clone to act as a USB HID keyboard. I’ve followed the installation instructions at https://github.com/rogerclarkmelbourne/ … stallation , flashed the bootloader with the ‘hello world’ message over serial, and got the ‘blink’ example code to upload over USB too. it’s working. However, I can’t get any HID keyboard code working. ‘simplekeyboard’ in the ‘examples for generic STM32F103C series’ example sketches uploads, but doesn’t seem to do anything – the board still shows up in USBTreeViewer as ‘COM10 Maple Mini’, other suggestions I’ve found around the forum fail to compile due to not being able to find the libraries/me not being able to install the libraries properly.

Can anyone help? I’ve done a little bit of 8-bit AVR programming in Arduino before, and some python and other interpreted languages, but I’m lost when it comes to makefiles and what seems to be a whole different ball game when using libraries for the STM32.

Andy.

Replies

arpruss Sun May 06, 2018 2:06 pm

[STMdude – Fri May 04, 2018 4:48 pm] –
To be brutally honest, the Arduino “Leonardo/Micro” clones and mini-boards that use the ATmega 32U4 do exactly what you want, and can be had for peanuts!

They’re about $2 more than the STM32 units. That makes a difference over several projects. There are projects where I wouldn’t think spending $4 is worth it, but $2 is OK.

There’s a very robust USB library for that chip.

My USBComposite library is getting robust, too. You should be able to do things like a monster HID Keyboard+Mouse+2 Gamepads device, and you might even be able to throw a mass storage device into this mix. For games on my PC, I regularly use a black-pill based box that emulates keyboard / mouse / joystick / two joysticks / xbox360 in multiple modes and lets me use some combinations of a Wii Nunchuk, GameCube controller, dance pad and/or exercise machine with a PC.

RogerClark Sun May 06, 2018 9:39 pm

[arpruss – Sun May 06, 2018 2:06 pm] –
[STMdude – Fri May 04, 2018 4:48 pm] –
To be brutally honest, the Arduino “Leonardo/Micro” clones and mini-boards that use the ATmega 32U4 do exactly what you want, and can be had for peanuts!

They’re about $2 more than the STM32 units. That makes a difference over several projects. There are projects where I wouldn’t think spending $4 is worth it, but $2 is OK.

There’s a very robust USB library for that chip.

My USBComposite library is getting robust, too. You should be able to do things like a monster HID Keyboard+Mouse+2 Gamepads device, and you might even be able to throw a mass storage device into this mix. For games on my PC, I regularly use a black-pill based box that emulates keyboard / mouse / joystick / two joysticks / xbox360 in multiple modes and lets me use some combinations of a Wii Nunchuk, GameCube controller, dance pad and/or exercise machine with a PC.

+1

I think, just because an older board can do the job, it should not mean we don’t bother to develop a newer and eventually better system.

florisla Mon May 07, 2018 7:01 am

[ag123 – Sat May 05, 2018 5:29 am] –
i’m thinking however using shift registers 74hc595, 74hc165 would still be useful as that would save lots of pins on the bp / mm leaving those pins available for other purposes

You can combine the input and output pins on a single chip by using an I2C GPIO IC. These even have integrated pull-up resistors which the shift registers don’t have.

E.g. PCF8575 is available an AliExpress as a breakout board.

Or SX1509 which even can do the matrix scanning for you.

Special-purpose keypad controllers with more than 16 IOs exist as well, e.g. LM8330 – but these are not breadboard-friendly nor easy to solder manually.

ag123 Mon May 07, 2018 8:36 am

[florisla – Mon May 07, 2018 7:01 am] –
You can combine the input and output pins on a single chip by using an I2C GPIO IC. These even have integrated pull-up resistors which the shift registers don’t have.

E.g. PCF8575 is available an AliExpress as a breakout board.

Or SX1509 which even can do the matrix scanning for you.

Special-purpose keypad controllers with more than 16 IOs exist as well, e.g. LM8330 – but these are not breadboard-friendly nor easy to solder manually.

this thread is pretty motivating in the sense that i used to think making an own custom keyboard is ‘impossible’, but the availability of keyboard switches being separately sold as retail items and lots of info from around the web (e.g. as like few post above) and stm32duino (etc) has made all these a reality, i’m thinking this thread could be moved eventually under ‘projects’ as stm32duino keyboards may grow out of it :D

i’ve some pieces of PCF8575 but i tend to use them for keypads as it takes a single chip to run a 4×4 keypad vs the shift registers. However, if one decides to do a 104-110 keys keyboard (you can never have enough keys, and keys are always in the ‘wrong’ places :lol:) the incentive completely change and shift registers make sense as each of 74hc595 and 74hc165 address 8 pins, hence 2x74hc595 + 74hc165 makes for a 16 x 8 ~ 128 keys keyboard matrix and they are cheap too
i’d imagine throw more 74hc595 at it you could even run the rgb leds independently :D
and using shift registers and or io expander or ‘helper’ ICs would save lots of pins on a blue pill / maple mini, those pins can be pulled out to headers say at the keyboard enclosure so that additional uses such as sd cards and /or even usb-serial/spi/ic2c/adc can be made from a single ‘keyboard’, literally making it a ‘multi-use’ device

ag123 Fri May 18, 2018 4:02 pm

some of my current (virtual) thoughts :D
Image
imgur url: https://imgur.com/9ti3rtB

actually i’d only need 2x74hc595 + 74hc165, but i’m not sure how difficult it may be to handwire a keyboard so that it fits 16 x 8 matrix
normally keyboards has about 5-6 rows of keys, throwing in an extra 74hc595 may make it easier to handwire the keyboard, in effect i’m ‘wasting’ 2 pins on the 74hc165 and wasting a few pins on the 3rd 74hc595

florisla Fri May 18, 2018 6:52 pm

I’ve done some experiments on a 20-key keyboard, and optimizing the matrix to save some pins is *very* tedious.

It’s worth it if you’re designing a pcb, but for handwiring it’s definitely better to stick to ‘columns are vertical, rows are horizontal’.

That also allows good build quality (nice looking and sturdy) like here https://geekhack.org/index.php?topic=87689.0 .

ag123 Sat May 19, 2018 4:12 pm

thanks florisla, i’d pretty likely explore this rabbit hole of making a custom (stm32duino) keyboard, i do agree about using an additional 74HC595, it would simplify matters. the only thing would be, would i need that pcb space for anything else? as those 4 ICs pretty much used up the 5cmx7cm perfboard. i’m happy to simply use a bigger perfboard instead.

making a custom keyboard has various (difficult) challenges not related to electronics (even for that matter stm32), among them is making the plate which has lots of considerations as the snap-in groove that cherry mx (and clones) switches allows is only 1.5mm, this give a big problem if one intends to use thick (3-5mm) acrylic plates rather than aluminium plates, then there is handwire vs pcb etc. i’d most likely start a thread on deskority forum for the fabrication parts of it and make a ref-link from here (perhaps cross posting the most interesting parts of it here if it help to complete the picture)

there is apparently quite a lot of interest in making (custom) mechanical keyboards, one of those switches i’ve recently found on aliexpress is from kailh ( a manufacturer based in china)
https://www.aliexpress.com/wholesale?Se … ilh+switch
https://www.aliexpress.com/item/kbdfans … 79716.html
http://www.kailh.com/en/Products/Ks/BOXS/
http://www.kailhswitch.com/mechanical-k … -switches/
there are various youtube videos featuring them, searching for kailh would find them
i noted that recently after checking the prices, the prices actually went up on aliexpress. i’d guess this in part due to demand from buyers wanting to make custom keyboards and based on my google searches, quite a number of commercially sold mechanical keyboards uses kailh switches, i’d guess the parallel demand chased up prices

i think in the early days keyboards is simply ‘a bunch of switches’, the electronics are probably some ‘simple’ logics rather than mcu driven. since the advent of mcus, usb and hid use in keyboards. it become pretty much a necessity to use mcus as keyboards shift to using usb. the good thing is hid is merely a usb protocol and now with better mcus like stm32 f1xx,f4xx, the mcu (stm32) makes that keyboard more than simply a ‘keyboard’

the other thing is with this notion of custom (mechanical) keyboards, keyboard layouts become ‘fluid’, one can re-arrange all the keys to one’s desire e.g. if 1 dislike a qwerty keyboard one could have them lined a-z instead. :lol: the trouble is that the moment one makes a detour away from ‘standard’ keyboards, all the pcb kits that one can find to build ‘custom’ mechanical keyboards simply ‘disappear’, u’d either have to decide on making your own pcb or hand-wire it and the plate becomes the keyboard. the plate can be laser cut on acrylic or preferably aluminium. laser cutting allows literally every keyboard to be different customised to one’s desire

ag123 Fri Jun 01, 2018 3:42 pm

ok i’ve got a better idea, and a *much cheaper* solution
https://makezine.com/2017/07/12/making- … -keyboard/
i won’t need a big keyboard, a ‘shortcut’ keyboard that supplements the main keyboard would solve most of my problems and satisfies my fancies
now i’d think a blue pill or maple mini is pretty much adequate to drive that ‘shortcut’ keyboard
:lol:

freynder Mon Jun 25, 2018 3:30 pm

Too bad, it would have been interesting to see an STM32 keyboard.

I’m a bit intrigued by the subject and am thinking of modifying my existing mechanical keyboard with an STM32 chip. The keyboard is a Tesoro Durandal G1N.

I noticed there is a separate small PCB to expose the leds to the top of the keyboard and ports to the back (unused for the model I am using). See images below:
Image

Image

I’m thinking of creating a replacement PCB with an STM32F103RBT6 on it (51 IO pins) and connecting the keyboard matrix to that chip. I already (painstakingly) mapped the whole keyboard, there are 8 rows and 18 columns, so 26 pins needed.

Concerns so far are that the actual keyboard PCB looks rather fragile. I already needed to retouch the solder points connecting the usb cable to the board and those traces came lose. So great care will need to be taken to remove the original controller and connect the traces to the new PCB.

Sign in to reply