Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nezuppo/3bb938a543ab8a83786e3211c351ab57 to your computer and use it in GitHub Desktop.
Save nezuppo/3bb938a543ab8a83786e3211c351ab57 to your computer and use it in GitHub Desktop.
XIAO SAMD21 で CircuitPython でマウスジグラー
参考にしたサイト
https://qiita.com/airpocket/items/24e67922e0c0f1624ab8
https://www.tomshardware.com/how-to/diy-mouse-jiggler-raspberry-pi-pico
XIAO は以下の手順で CircuitPython をインストールした状態
https://gist.github.com/nezuppo/ba5b707daf3a425268fc855dc637626b
XIAO をラズパイに USB 接続
fdisk で確認すると sdb の Disk model が Seeeduino XIAO なのでこれみたい
$ sudo fdisk -l
... snip ...
Disk /dev/sdb: 64.5 KiB, 66048 bytes, 129 sectors
Disk model: Seeeduino XIAO
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sdb1 1 128 128 64K 1 FAT12
$ sudo mount /dev/sdb1 xiao/
$ ls -la xiao/
total 22
drwxr-xr-x 4 root root 16384 Jan 1 1970 .
drwxr-xr-x 3 pi pi 4096 May 7 18:12 ..
-rwxr-xr-x 1 root root 138 Jan 1 2000 boot_out.txt
-rwxr-xr-x 1 root root 0 Jan 1 2000 code.py
drwxr-xr-x 2 root root 512 Jan 1 2000 .fseventsd
drwxr-xr-x 2 root root 512 Jan 1 2000 lib
-rwxr-xr-x 1 root root 0 Jan 1 2000 .metadata_never_index
-rwxr-xr-x 1 root root 0 Jan 1 2000 .Trashes
ラズパイで Adafruit_CircuitPython_HID を git clone
$ git clone https://github.com/adafruit/Adafruit_CircuitPython_HID.git
$ sudo cp -r Adafruit_CircuitPython_HID/adafruit_hid xiao/lib/
code.py をバックアップ
$ sudo cp -p xiao/code.py{,.bk-$(date +%Y-%m%d-%H%M%S)}
$ cat << EOF | sudo tee xiao/code.py
import time
import board
import usb_hid
from adafruit_hid.mouse import Mouse
from digitalio import DigitalInOut, Direction
class LED:
def __init__(self, inout):
self.__digitalio = DigitalInOut(inout)
self.__digitalio.direction = Direction.OUTPUT
self.off()
def off(self):
self.__digitalio.value = True
def on(self):
self.__digitalio.value = False
class LEDs:
def __init__(self):
self.__yellow = LED(board.LED_INVERTED)
self.__blue = LED(board.BLUE_LED2_INVERTED)
def blink(self):
for i in range(3):
self.__yellow.on()
time.sleep(0.5)
self.__yellow.off()
self.__blue.on()
time.sleep(0.5)
self.__blue.off()
time.sleep(3)
leds = LEDs()
m = Mouse(usb_hid.devices)
while True:
m.move(1, 0, 0)
m.move(-1, 0, 0)
leds.blink()
time.sleep(300)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment