First for reference I verified that a Logitech K270 mouse/keyboard plugged into an iHaper USB C003 USB-C to 3-Port USB 3.0 Hub works and provides about mouse and keyboard functionality. I used the Notes iOS app for testing.
* CircuitPython on ItsyBitsy M4 Express *
CircuitPython 6.0.0 Alpha 3 was announced here:
https://forums.adafruit.com/viewtopic.php?f=60&t=168889But I couldn't find it here:
https://circuitpython.org/board/itsybitsy_m4_express/So I'm sticking with 6.0.0 Alpha 2.
- Code: Select all | TOGGLE FULL SIZE
Adafruit CircuitPython 6.0.0-alpha.2 on 2020-07-23; Adafruit ItsyBitsy M4 Express with samd51g19
I downloaded the latest libraries in adafruit-circuitpython-bundle-6.x-mpy-20200829 and installed.
Here is the CircuitPython test program:
- Code: Select all | TOGGLE FULL SIZE
import adafruit_hid # So we can see __version__
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_hid.mouse import Mouse
import board
from digitalio import DigitalInOut, Direction, Pull
import time
import usb_hid
button1 = DigitalInOut(board.D1)
button1.direction = Direction.INPUT
button1.pull = Pull.UP
button2 = DigitalInOut(board.D0)
button2.direction = Direction.INPUT
button2.pull = Pull.UP
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
mouse = Mouse(usb_hid.devices)
print("adafruit_hid.__version__", adafruit_hid.__version__)
# usb_hid - __version__ not available?
# print("usb_hid.__version__", usb_hid.__version__)
while True:
if not button1.value:
layout.write("# Hello")
kbd.send(Keycode.ENTER)
time.sleep(1)
if not button2.value:
# Double-click (not sure what this does on iPad?)
mouse.click(Mouse.LEFT_BUTTON)
mouse.click(Mouse.LEFT_BUTTON)
time.sleep(1)
This works on Mac OS, but not on the iPad.
First ported to Arduino with the Arduino USB stack
- Code: Select all | TOGGLE FULL SIZE
#include <Keyboard.h>
#include <Mouse.h>
void setup() {
pinMode(0, INPUT_PULLUP); // Button1
pinMode(1, INPUT_PULLUP); // Button2
Mouse.begin();
Keyboard.begin();
}
void loop() {
if (digitalRead(1) == LOW) {
Keyboard.println("# Hello");
delay(1000);
}
if (digitalRead(0) == LOW) {
Mouse.click();
Mouse.click();
delay(1000);
}
}
This works on Mac OS X, and on the iPad.
Then I switched to the TinyUSB library, and installed
https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard so that I wouldn't have to change the above much.
The includes were simply changed to:
- Code: Select all | TOGGLE FULL SIZE
#include <TinyUSB_Mouse_and_Keyboard.h>
This works on Mac OS X, and still works on the iPad.