Description
Firmware
Adafruit CircuitPython 6.2.0-beta.4 on 2021-03-18; Raspberry Pi Pico with rp2040
Code/REPL
import time
import board
import digitalio
import analogio
import usb_hid
from adafruit_hid.mouse import Mouse
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
mouse = Mouse(usb_hid.devices)
kbd = Keyboard(usb_hid.devices)
x_axis = analogio.AnalogIn(board.A0)
y_axis = analogio.AnalogIn(board.A1)
btn_left = digitalio.DigitalInOut(board.GP22)
btn_left.direction = digitalio.Direction.INPUT
btn_left.pull = digitalio.Pull.UP
pot_min = 0.00
pot_max = 3.29
step = (pot_max - pot_min) / 20.0
def get_voltage(pin):
return (pin.value * 3.3)/65536
def steps(axis):
return round((axis - pot_min) / step)
while True:
x = get_voltage(x_axis)
y = get_voltage(y_axis)
print(x, y, btn_left.value)
if steps(x) > 11.0:
print('x>11', steps(x))
mouse.move(x=10)
if steps(x) < 9.0:
mouse.move(x=-10)
if steps(y) > 11.0:
print('y>11', steps(x))
mouse.move(y=10)
if steps(y) < 9.0:
mouse.move(y=-10)
if not btn_left.value:
print('button')
mouse.click(Mouse.LEFT_BUTTON)
time.sleep(0.2)
time.sleep(0.1)
Behavior
The mouse does not work on macOS Big Sur 11.2.1 but it works correctly on Windows 10 and Lubuntu 20.04.1.
Description
The board has an analog joystick (two potentiometers and a tact switch) connected. They are wired and configured correctly as in the console output I can see the correct voltages and switch status logged. What is more, the code above works correctly on Windows 10 and Lubuntu 20.04.1 - it moves the mouse cursor and performs the mouse clicks.
On macOS Big Sur 11.2.1 it has no effect at all - the cursor does not move and the click event does not work.
I tried adding the following keyboard key press code instead of the mouse click and it does work correctly on the Mac.
kbd.press(Keycode.A) # "Press"...
kbd.release_all() # ..."Release"!
Please let me know if there is anything I can do to help debugging or fixing this issue.