USB Host - KB,Mouse,Gamepad etc.
This is a demo of a tiny ch559 mcu configured to work as a USB host, the actual unit I am using is designed by MatzElectronics, a good business to deal with btw.
link: https://www.tindie.com/products/matzelectronics/ch559-usb-host-breakout-board/
There is a more compact module here
link: https://www.tindie.com/products/matzelectronics/ch559-usb-host-to-uart-bridge-module/
These units require 5v for the on board 5v to 3.3v regulator, they come pre-programmed I just had to step the baudrate down a little for my demo. I used a wireless keyboard and in the code a dictionary to look up a few of the letter and number values. The minimal code could be adapted for mouse,gamepad,midi if you have a project where you think it might work or maybe for a great learning experience.
from microbit import * uart.init(baudrate=57600,tx=None, rx=pin0) key_list=[] val=0 msg='' alphabet=dict({4:'a',5:'b',6:'c',7:'d',8:'e',9:'f',10:'g',11:'h',12:'i',13:'j',14:'k',15:'l',16:'m',17:'n',18:'o',19:'p', 20:'q',21:'r',22:'s',23:'t',24:'u',25:'v',26:'w',27:'x',28:'y',29:'z',30:'1',31:'2',32:'3',33:'4',34:'5', 35:'6',36:'7',37:'8',38:'9',39:'0'}) while True: if uart.any(): key_list.append(int.from_bytes(uart.read(1),'big')) if len(key_list)>=20: val=key_list[13] if (val>3 and val<40): msg=alphabet[val] display.show(msg.upper()) key_list.clear() else: key_list.clear() else: key_list.clear()
Comments
This looks good. Any more HID examples beyond mouse, gamepad, midi, keyboard? I wonder other types of things it could be used for.
I wish there were an 'HID thumb drive' so I could use it with this, for ~200 byte files of course. (is there?)
@The_Master As yet I have not seen an example but there is probably one out there somewhere but I think it would be doubtful if it could be used with the Microbit. This usb device is based on the CH559 made by WCH-IC a Chinese company. Their website talks about a zip file that contains "CH559 FAT file system libraries" , the notes and document files are mostly in the Chinese language and the file is called CH559EVT.ZIP.