I recently discovered the Neo Trinkey and wanted to use it as a mini macro board for the raspberry pi 4.
Following the guide for the Neo Trinkey
https://learn.adafruit.com/adafruit-neo-trinkey
it was easy enough to set up the Trinkey as a macro pad using circuit python. In windows touching the touch buttons, sends the expected key presses.
But when connecting it to my raspberry pi 4, the "send" and "write" methods used in circuit python do not send keypresses or write anything in the pi.
Any help on how to get the macro pad (that works on windows) working on the raspberry pi os would be appreciated.
Neo Trinkey sending keyboard codes to raspberry pi os
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Pretzl
- Posts: 5
- Joined: Tue Jun 08, 2021 9:13 am
- mikeysklar
- Posts: 14165
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Neo Trinkey sending keyboard codes to raspberry pi os
@Pretzl,
We should pick one of the three CircuitPython examples and focus on that with your Pi4. Do you want to use Capacitive Touch HID? What happens when you run this script on your Pi?
https://learn.adafruit.com/adafruit-neo ... -touch-hid
We should pick one of the three CircuitPython examples and focus on that with your Pi4. Do you want to use Capacitive Touch HID? What happens when you run this script on your Pi?
https://learn.adafruit.com/adafruit-neo ... -touch-hid
Code: Select all
"""CircuitPython Capacitive Touch HID Example for Neo Trinkey"""
import time
import board
import touchio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)
touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)
while True:
if touch1.value: # If touch pad 1 is touched...
while touch1.value: # Wait for release...
time.sleep(0.1)
keyboard.send(Keycode.SHIFT, Keycode.A) # Then send key press.
if touch2.value: # If touch pad 2 is touched...
while touch2.value: # Wait for release...
time.sleep(0.1)
keyboard_layout.write("Hello World!\n") # Then send string.
- Pretzl
- Posts: 5
- Joined: Tue Jun 08, 2021 9:13 am
Re: Neo Trinkey sending keyboard codes to raspberry pi os
Thank you for the response. Exactly, I want to use the Capacitive Touch HID to send keyboard codes to a Pi4. Running the example code of the guide on the pi (the one you referred to) does not write out capital "A" or "Hello World!". However, when plugging it into my windows computer it does write out "A" and "Hello World!" when touching the pads. I have 2 Neo Trinkeys and 2 Pi4 (4gb and 2gb), both Trinkeys behave as expected on windows, but neither sends keycodes out on one of the Pi4s.
I also ran a slightly modified version of the code on the pi, to see whether the touch inputs were read properly by including print statements to the following:
The print statements get written into the terminal output of the mu editor when touching the pads, so the touch inputs themselves work as expected on the pi, only the keyboard.send and keyboard.write commands do not send or write.
I also ran a slightly modified version of the code on the pi, to see whether the touch inputs were read properly by including print statements to the following:
Code: Select all
"""CircuitPython Capacitive Touch HID Example for Neo Trinkey"""
import time
import board
import touchio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)
touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)
while True:
if touch1.value: # If touch pad 1 is touched...
while touch1.value: # Wait for release...
time.sleep(0.1)
keyboard.send(Keycode.SHIFT, Keycode.A) # Then send key press.
print("touch1")
if touch2.value: # If touch pad 2 is touched...
while touch2.value: # Wait for release...
time.sleep(0.1)
keyboard_layout.write("Hello World!\n") # Then send string.
print("touch2")
- mikeysklar
- Posts: 14165
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Neo Trinkey sending keyboard codes to raspberry pi os
@Pretzl,
Good trouble shooting. Now we know the Trinkey / CapTouch is properly functioning based on your straight up print statements.
Let's look into what is going on keyboard.send() and keyboard_layout.write().
I don't see any specific issues opened on the Adafruit_CircuitPython_HID library related to send() / write().
When you run the same example CapTouch code you have put together from the command line on your Pi's can you see the output? I'm wondering if this is more of a Mu console issue.
Good trouble shooting. Now we know the Trinkey / CapTouch is properly functioning based on your straight up print statements.
Let's look into what is going on keyboard.send() and keyboard_layout.write().
I don't see any specific issues opened on the Adafruit_CircuitPython_HID library related to send() / write().
When you run the same example CapTouch code you have put together from the command line on your Pi's can you see the output? I'm wondering if this is more of a Mu console issue.
Code: Select all
$ python3 CapTouchHID.py
- Pretzl
- Posts: 5
- Joined: Tue Jun 08, 2021 9:13 am
Re: Neo Trinkey sending keyboard codes to raspberry pi os
Well, if I run
in terminal, I get a 'ModuleNotFoundError' saying that there is no module named 'touchio'.
I am not surprised by this behavior, since -how I understand it and correct me if I am wrong- simply running the script over terminal means that python would try to set up the pi itself as an usb hid device with two touch inputs (and I don't have the library for touchio installed on the pi itself, neither did I have it installed on my windows machine where the Neo Trinkey works as expected). Additionally, simply saving the file should lead the Neo Trinkey to execute the script - there is no need to run it.
My guess would be that the problem I am encoutering is an issue with the write() and send() methods, or the usb_hid.device module in general, that is either specific to raspberry pi os or linux (or some additional configuration I need to make on the pi so that it recognizes the Neo Trinkey as an usb hid device?). I was wondering if others encountered the same problem on the pi and know a fix.
Code: Select all
python3 /media/pi/CIRCUITPY/code.py
I am not surprised by this behavior, since -how I understand it and correct me if I am wrong- simply running the script over terminal means that python would try to set up the pi itself as an usb hid device with two touch inputs (and I don't have the library for touchio installed on the pi itself, neither did I have it installed on my windows machine where the Neo Trinkey works as expected). Additionally, simply saving the file should lead the Neo Trinkey to execute the script - there is no need to run it.
My guess would be that the problem I am encoutering is an issue with the write() and send() methods, or the usb_hid.device module in general, that is either specific to raspberry pi os or linux (or some additional configuration I need to make on the pi so that it recognizes the Neo Trinkey as an usb hid device?). I was wondering if others encountered the same problem on the pi and know a fix.
- mikeysklar
- Posts: 14165
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Neo Trinkey sending keyboard codes to raspberry pi os
@Pretzl,
Okay, my bad not fully understanding that the Neo Trinkey looks like all of our M0 processors.
So forget that sytnax about python3...code.py is automatically being executed.
When you bring up the REPL>> for the Neo Trinkey what do you see? Your USB devicename might be different. Make sure the Mu is not running.
Also since you are using a Pi4 are you using the USB3 or USB2 ports? The blue ones are the USB3. Just curious if that makes a difference for the NeoTrinkey behavior.
Okay, my bad not fully understanding that the Neo Trinkey looks like all of our M0 processors.
So forget that sytnax about python3...code.py is automatically being executed.
When you bring up the REPL>> for the Neo Trinkey what do you see? Your USB devicename might be different. Make sure the Mu is not running.
Code: Select all
screen /dev/ttyUSB0 115200
- Pretzl
- Posts: 5
- Joined: Tue Jun 08, 2021 9:13 am
Re: Neo Trinkey sending keyboard codes to raspberry pi os
If I enter
into the command line (mu is not open), nothing shows at first. When I press ctrl+c and afterwards any key I enter the REPL and can do the usual REPL commands. After exiting REPL once again with ctrl+d there is a soft reboot and when I touch the pads of the NeoTrinkey I see the print statements I included, jet the information in .write() .send() does not get send (e.g. when having a text file open -or anywhere else for that matter- to verify if the .write() output gets written).
In the end, the behavior of the NeoTrinkey and the output from console is the exact same as the one I see via Mu.
Changing the USB Ports (e.g. USB3 vs USB2) does not change the behavior of the NeoTrinkey.
Code: Select all
screen /dev/ttyACM0 115200
In the end, the behavior of the NeoTrinkey and the output from console is the exact same as the one I see via Mu.
Changing the USB Ports (e.g. USB3 vs USB2) does not change the behavior of the NeoTrinkey.
- mikeysklar
- Posts: 14165
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Neo Trinkey sending keyboard codes to raspberry pi os
@Pretzl,
Thank you for confirming the manual serial console REPL and USB2 vs USB3 ports.
I think it is time to open an issue for the Adafruit_CircuitPython_HID library about the different behavior you are seeing with keyboard.send() and keyboard_layout.write() between Windows / Pi OS. Are you comfortable placing your example code and a short description here:
https://github.com/adafruit/Adafruit_Ci ... HID/issues
Thank you for confirming the manual serial console REPL and USB2 vs USB3 ports.
I think it is time to open an issue for the Adafruit_CircuitPython_HID library about the different behavior you are seeing with keyboard.send() and keyboard_layout.write() between Windows / Pi OS. Are you comfortable placing your example code and a short description here:
https://github.com/adafruit/Adafruit_Ci ... HID/issues
- Pretzl
- Posts: 5
- Joined: Tue Jun 08, 2021 9:13 am
Re: Neo Trinkey sending keyboard codes to raspberry pi os
Will do, thank you for your help.
- danhalbert
- Posts: 4686
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Neo Trinkey sending keyboard codes to raspberry pi os
I will pick this up in GitHub.
Please be positive and constructive with your questions and comments.