Skip to content

Instantly share code, notes, and snippets.

@mrmabs
Created November 22, 2022 13:42
Show Gist options
  • Select an option

  • Save mrmabs/3ca131b723aa0fea9a002bc0ca27ed95 to your computer and use it in GitHub Desktop.

Select an option

Save mrmabs/3ca131b723aa0fea9a002bc0ca27ed95 to your computer and use it in GitHub Desktop.
Demo of BBQ20KBD on Pi Pico and Micropython
# After not being able to find any code for Micropython on the
# Pi Pico that I could use to operate my newly acquired BBQ20KBD
# from Solder Party on Tindie, I started experimenting and have
# this rough piece of code to prove that it is possible to
# communicate with the BBQ20KBD.
#
# My contributions are MIT Licenced, but understand that much of
# this code was pulled from multiple sources online, many without
# discernable licences.
#
# I will work on this over time, using the below code as a guide.
# https://github.com/solderparty/arturo182_CircuitPython_BBQ10Keyboard/blob/master/bbq10keyboard.py
#
# Feel free to contribute or build something from it, you may
# change the licence for my code to anything recognised by the
# OSF.
#
# This code will:
# - reset the keyboard & buffer
# - wait 10 seconds
# - check the size of the buffer
# - take each item out of the buffer and print it out
#
import machine, time
from ubinascii import unhexlify
# Create I2C object
i2c = machine.I2C(0, scl=machine.Pin(9), sda=machine.Pin(8), freq=100000)
# Print out any addresses found
devices = i2c.scan()
kbd = 0x1F # address
stat = unhexlify("04") # key status
fifo = unhexlify("09") # key fifo
ver = unhexlify("01") # version
rst = unhexlify("08") # reset
KEY_COUNT_MASK = 0x1F
#print(hex(kbd), stat)
if devices:
for d in devices:
print(hex(d))
print(i2c.writeto(kbd, rst, False))
time.sleep(10)
print(i2c.writeto(kbd, stat, False))
time.sleep(0.1)
status = i2c.readfrom(kbd, 1)
print(status, int.from_bytes(status, "big"))
buflen = int.from_bytes(status, "big") & KEY_COUNT_MASK
while buflen > 0:
print(i2c.writeto(kbd, fifo, False))
time.sleep(0.1)
status = i2c.readfrom(kbd, 2)
print(status)
buflen -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment