Driver for M5Stack CardKB (I2C mini keyboard) on Raspberry Pi
Project description
Raspberry Pi Card Keyboard
A script for using the M5Stack CardKB with Raspberry Pi
Setting your pi to us layout
In order for buttons to return the correct symbols, the keyboard layout will need to be set to us on you pi. You can do this by running:
sudo nano /etc/default/keyboard
and changing XKBLAYOUT to us:
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
Enable i2C
The cardKB communicates over i2C, make sure this is enabled on your raspberry pi. You can find a tutorial on how to do so here.
Connect CardKB to Raspberry Pi
Connect the wires on the CardKB JST connector to the appropriate pin on the Raspberry Pi.
You may need to improvise a connection solution with breadboard wires like so:
Load the uinput module
You will need to load the uinput module to allow python-uinput to input key presses. You can check if it is loaded with:
lsmod | grep uinput
If nothing is displayed, then the module is not loaded. To load the module, run:
modprobe uinput
To load the module automatically on startup, run:
sudo nano /etc/modules
add uinput at the bottom of the file. Save and then reboot.
Install Software
Install smbus and python-uinput:
sudo apt install python3-smbus
sudo pip3 install python-uinput
clone this repository:
git clone https://github.com/ian-antking/cardkb.git
Run the script and check buttons return expected characters:
sudo python3 cardkb &
By default, the python script listens to /dev/i2c-1, you can change this by adding an argument to the start command.
sudo python3 cardkb 11 &
Running CardKB when Raspberry Pi starts
We can use systemd to run the CardKB script as a service. To do so, create a unit file:
sudo nano /lib/systemd/system/cardkb.service
Add the following:
[Unit]
Description=Service for using CardKB with Raspberry Pi
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/cardkb
[Install]
WantedBy=multi-user.target
This service file assumes that you have cloned the cardkb repo to /home/pi. If this is not the case, you will need to change the file path.
...
ExecStart=/usr/bin/python3 /home/ian/cardkb
...
Likewise, if you are running cardkb on a i2c bus other than one, then you will need to add the bus number to the end of the ExecStart line like so:
...
ExecStart=/usr/bin/python3 /home/pi/cardkb 11
...
Save the file and exit. Now run the following commands to reload the systemctl daemon, enable the cardkb service and restart the pi:
sudo systemctl daemon-reload
sudo systemctl enable cardkb.service
sudo reboot
When your Pi restarts, your cardkb should be working, allowing you to log in.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cardkb-0.1.0.tar.gz.
File metadata
- Download URL: cardkb-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b64c523c7536021e1e7299828e1a3ff7c7e078ac082be14cfd626e7839f60f2d
|
|
| MD5 |
4dbedd7d88e59465d7e7b6bf24c9cf20
|
|
| BLAKE2b-256 |
dda08f6fa501e45bc37808273bbd32d1b9730a79bb675930330d46b1fdb9bb00
|
Provenance
The following attestation bundles were made for cardkb-0.1.0.tar.gz:
Publisher:
build_and_push.yaml on ian-antking/cardkb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cardkb-0.1.0.tar.gz -
Subject digest:
b64c523c7536021e1e7299828e1a3ff7c7e078ac082be14cfd626e7839f60f2d - Sigstore transparency entry: 506871315
- Sigstore integration time:
-
Permalink:
ian-antking/cardkb@76d91f73e4517d01de566ebaecac97df6c6799ca -
Branch / Tag:
refs/tags/v0.1.0-test - Owner: https://github.com/ian-antking
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_and_push.yaml@76d91f73e4517d01de566ebaecac97df6c6799ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file cardkb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cardkb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c79144ba74bebad871082a46e2de1759b236c6fbc78126a9a740969e97a109c
|
|
| MD5 |
b7d710adbff716f1c9944c5627f05cb3
|
|
| BLAKE2b-256 |
833d518a7def4637f187ea39f98acb91bad6aa9610c281334428d9fb4ee67bfc
|
Provenance
The following attestation bundles were made for cardkb-0.1.0-py3-none-any.whl:
Publisher:
build_and_push.yaml on ian-antking/cardkb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cardkb-0.1.0-py3-none-any.whl -
Subject digest:
4c79144ba74bebad871082a46e2de1759b236c6fbc78126a9a740969e97a109c - Sigstore transparency entry: 506871327
- Sigstore integration time:
-
Permalink:
ian-antking/cardkb@76d91f73e4517d01de566ebaecac97df6c6799ca -
Branch / Tag:
refs/tags/v0.1.0-test - Owner: https://github.com/ian-antking
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_and_push.yaml@76d91f73e4517d01de566ebaecac97df6c6799ca -
Trigger Event:
push
-
Statement type: