Blinka setup on R Pi 4 for Trinkey

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
JimBoulder
 
Posts: 11
Joined: Wed Jul 12, 2023 10:32 pm

Blinka setup on R Pi 4 for Trinkey

Post by JimBoulder »

I am trying to setup a Raspberry Pi 4 to use blinka to control a trinkey.

Folling the instructions https://learn.adafruit.com/circuitpytho ... pico/linux. I am stuck on the step to install pyserial.

jim@pi03:~ $ sudo pip3 install pyserial
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install. ...

jim@pi03:~ $ sudo apt install python3-pyserial
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python3-pyserial

jim@pi03:~ $ sudo apt install python-pyserial
returns the same error.

The step before. for hiaapi
jim@pi03:~ $ sudo apt install python3-hidapi
was successful.

What am I missing?

Thank you,
Jim

User avatar
Franklin97355
 
Posts: 24333
Joined: Mon Apr 21, 2008 2:33 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by Franklin97355 »

This might help. https://pimylifeup.com/python-externall ... vironment/ I have the problem on my Linux computer sometimes and this helps.

User avatar
JimBoulder
 
Posts: 11
Joined: Wed Jul 12, 2023 10:32 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by JimBoulder »

OK that worked to install pyserial and adafruit-blinka. The first few post install checks are good.

It fails on the check-if-found test.
>>> import hid
>>> device = hid.device()
>>> device.open(0x239A, 0x0109)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "hid.pyx", line 143, in hid.device.open
OSError: open failed

I have the Trinkey QT2040 - RP2040 USB Key with Stemma QT PID 5056. I have the same result with u2if_trinkey_qt2040_rp2040.uf2 and u2if_trinkey.uf2 installed.

Any ideas?

Thank you,
Jim

User avatar
adafruit2
 
Posts: 22717
Joined: Fri Mar 11, 2005 7:36 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by adafruit2 »

why do you need low level - hid control? you can just use pyserial right?

(like this https://learn.adafruit.com/uart-communi ... hon-boards but one side uses pyserial to send over the commands rather than bidirecitonally)

User avatar
JimBoulder
 
Posts: 11
Joined: Wed Jul 12, 2023 10:32 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by JimBoulder »

I would like to have direct reading of my sensors from my Raspberry Pi host. As described in
https://learn.adafruit.com/adafruit-tri ... on-example
and
https://learn.adafruit.com/diy-trinkey- ... -with-u2if
This has one install hidapi, pyserial and adafruit-blinka.

In following the instructions it fails the post install checks, as I detailed above. I did try running the sample code and it fails.

How do I get to where I can do direct reading?

Thank you,
Jim

User avatar
adafruit2
 
Posts: 22717
Joined: Fri Mar 11, 2005 7:36 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by adafruit2 »

ok so you installed U2IF on the trinkey?

User avatar
Speedy_VI
 
Posts: 227
Joined: Sat Feb 24, 2024 10:58 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by Speedy_VI »

Sorry to butt in but curious - Is the U2IF a Trinkey QT2040 only thing or can this be done on any RP2040 based board?

Thanks.

User avatar
adafruit2
 
Posts: 22717
Joined: Fri Mar 11, 2005 7:36 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by adafruit2 »

we have builds ready for *some* boards but it could be recompiled to any RP2040

User avatar
Speedy_VI
 
Posts: 227
Joined: Sat Feb 24, 2024 10:58 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by Speedy_VI »

adafruit2 wrote: Thu Jan 02, 2025 11:22 am we have builds ready for *some* boards but it could be recompiled to any RP2040
Thanks.

User avatar
JimBoulder
 
Posts: 11
Joined: Wed Jul 12, 2023 10:32 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by JimBoulder »

adafruit2 wrote: Wed Jan 01, 2025 3:23 pm ok so you installed U2IF on the trinkey?
Yes

User avatar
adafruit2
 
Posts: 22717
Joined: Fri Mar 11, 2005 7:36 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by adafruit2 »

oh i see what you mean, so you have the trinkey but you want blinka to use that not the native Pi GPIO. i've never done that before (most folks just use the native IO) but you should be able to set an environment variable BLINKA_U2IF in the same shell before calling python

https://github.com/adafruit/Adafruit_Py ... ip.py#L103

User avatar
JimBoulder
 
Posts: 11
Joined: Wed Jul 12, 2023 10:32 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by JimBoulder »

Yes I have set BLINKA_U2IF, and the connection check fails.
jim@pi03:~/trinkey $ echo $BLINKA_U2IF
1
jim@pi03:~/trinkey $ python3
Python 3.11.2 (main, Sep 14 2024, 03:00:30) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
>>> device = hid.device()
>>> device.open(0x239A, 0x0109)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "hid.pyx", line 143, in hid.device.open
OSError: open failed

Running the chip.py referenced in the previous post returns nothing.
jim@pi03:~/trinkey $ echo $BLINKA_U2IF
1
jim@pi03:~/trinkey $ python3 chip.py
jim@pi03:~/trinkey $ echo $?
0
Any ideas?

User avatar
adafruit2
 
Posts: 22717
Joined: Fri Mar 11, 2005 7:36 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by adafruit2 »

well you dont want to run any of that HID stuff right? you should just `import board` ?

is there a particular reason you want to use U2IF and not just connect to the pi directly?

User avatar
JimBoulder
 
Posts: 11
Joined: Wed Jul 12, 2023 10:32 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by JimBoulder »

The 'import hid' statemant is part of the check-if-found test code on https://learn.adafruit.com/circuitpytho ... 040-boards.
Running 'import board' generated errors.

Note that https://learn.adafruit.com/circuitpytho ... pico/linux
has one install hidapi not hid, which is what I have done.

The chip.py file uses hid:
if os.environ.get("BLINKA_U2IF"):
import hid

I have reinstalled the OS and the libraries etc following the instructions on https://learn.adafruit.com/circuitpytho ... pico/linux. With the same results.

I would prefer to use U2IF because my Pi case makes it difficult to access the GPIO pins. The Adafruit instructions indicate this should be a valid way to access the I2C sensor boards.

User avatar
adafruit2
 
Posts: 22717
Joined: Fri Mar 11, 2005 7:36 pm

Re: Blinka setup on R Pi 4 for Trinkey

Post by adafruit2 »

maybe run the python3 command as sudo?

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”