First off... the sticky topic at the top of this forum: "No linux support for Trinket."
Does that pertain to both Trinket and Trinket M0 or only the former?
Next: I am having trouble making the Trinket M0 show up as a raw HID device.
Can the Trinket M0 function as a raw HID device, in the same manner as the AtMega32U4 controllers will?
NOTE: I am using the Arduino IDE to program the Trinket M0, on Ubuntu 21.10 now.
Thanks!
Trinket M0 as raw HID
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Trinket M0 as raw HID
The Trinket M0 will work fine with linux for programming via Arduino or with CircuitPython loaded.
There is CircuitPython HID support for the Trinket M0.
https://learn.adafruit.com/adafruit-tri ... -and-mouse
I think this would be the Arduino equivalent.
https://www.arduino.cc/reference/en/lan ... /keyboard/
There is CircuitPython HID support for the Trinket M0.
Code: Select all
"""CircuitPython Essentials HID Keyboard example"""
import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
# A simple neat keyboard demo in CircuitPython
# The pins we'll use, each will have an internal pullup
keypress_pins = [board.A1, board.A2]
# Our array of key objects
key_pin_array = []
# The Keycode sent for each button, will be paired with a control key
keys_pressed = [Keycode.A, "Hello World!\n"]
control_key = Keycode.SHIFT
# The keyboard object!
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
# Make all pin objects inputs with pullups
for pin in keypress_pins:
key_pin = digitalio.DigitalInOut(pin)
key_pin.direction = digitalio.Direction.INPUT
key_pin.pull = digitalio.Pull.UP
key_pin_array.append(key_pin)
# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.LED)
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.direction = digitalio.Direction.OUTPUT
print("Waiting for key pin...")
while True:
# Check each pin
for key_pin in key_pin_array:
if not key_pin.value: # Is it grounded?
i = key_pin_array.index(key_pin)
print("Pin #%d is grounded." % i)
# Turn on the red LED
led.value = True
while not key_pin.value:
pass # Wait for it to be ungrounded!
# "Type" the Keycode or string
key = keys_pressed[i] # Get the corresponding Keycode or string
if isinstance(key, str): # If it's a string...
keyboard_layout.write(key) # ...Print the string
else: # If it's not a string...
keyboard.press(control_key, key) # "Press"...
keyboard.release_all() # ..."Release"!
# Turn off the red LED
led.value = False
time.sleep(0.01)
I think this would be the Arduino equivalent.
https://www.arduino.cc/reference/en/lan ... /keyboard/
- Stolk
- Posts: 19
- Joined: Sat Oct 30, 2021 11:10 am
Re: Trinket M0 as raw HID
Thanks, I am trying to make it a raw hid, though. Not a kb or mouse. Rawhid works with itsy bitsy, but so far no luck w trinket m0.
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Please be positive and constructive with your questions and comments.