execuc / u2if Goto Github PK
View Code? Open in Web Editor NEWUSB to interfaces implementing MicroPython "machine" module functionalities on a computer.
License: Other
USB to interfaces implementing MicroPython "machine" module functionalities on a computer.
License: Other
Below is a possible improvement to the udev-rules. It is based on the suggest udev-rules in the libusb/hidraw
project
Ref: https://github.com/libusb/hidapi/blob/6fcb0bb2282dbb505561a53689eba0c0536570d9/udev/69-hid.rules
# PICO
#KERNEL=="hidraw*", ATTRS{idVendor}=="cafe", ATTRS{idProduct}=="4005", TAG+="uaccess", GROUP="plugdev", MODE="0660"
# Adafruit Feather
#KERNEL=="hidraw*", ATTRS{idVendor}=="239a", ATTRS{idProduct}=="00f1", TAG+="uaccess", GROUP="plugdev", MODE="0660"
# Adafruit ItsyBitsy
#KERNEL=="hidraw*", ATTRS{idVendor}=="239a", ATTRS{idProduct}=="00fd", TAG+="uaccess", GROUP="plugdev", MODE="0660"
# Adafruit QT2040 Trinkey
#KERNEL=="hidraw*", ATTRS{idVendor}=="239a", ATTRS{idProduct}=="0109", TAG+="uaccess", GROUP="plugdev", MODE="0660"
# Adafruit QTPY
#KERNEL=="hidraw*", ATTRS{idVendor}=="239a", ATTRS{idProduct}=="00f7", TAG+="uaccess", GROUP="plugdev", MODE="0660"
I have tested this connected from a Raspberry Pi 4 to a RP2040 Pico and they work
> ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Jun 29 16:46 /dev/ttyACM0
> ls -l /dev/hidraw*
crw-rw----+ 1 root plugdev 244, 2 Jun 29 16:46 /dev/hidraw2
Great project, I'm really excited to have i2c access on my Ubuntu desktop. I was trying your scan_i2c.py example and measured the SCL period with a logic analyzer and oscilloscope.
i2c = I2C(i2c_index=0, frequency=400000)
resulted in a frequency of 357kHz (about 11% lower)
requesting frequency=450000 measured exactly 400kHz
i2c = I2C(i2c_index=0, frequency=1000000)
resulted in a frequency of 791kHz (about 21% lower)
requesting frequency=1350000 measured exactly 1MHz
I'm fine using these new values for my scripts, but I thought I would pass on the observation.
I have been using u2if to control a relay through GP (gpio) from my PI3 in a plugin used for another program and it has worked fine. I really like the use of this project thanks for this.
Now I have another PICO, which does some other things also via GP (gpio), but I cannot control the 2 PICOs separately.
Although I have tried to use the serial numbers for the 2 PICOs, it always chooses the first PICO, or the one with the lowest serial number.
So my question is: Can you not decide from a python script which PICO should receive the information for the GP (gpio). And if you can, what is the procedure for this?
I was not able to detect the VCNL4010 ambient light sensor, as it will not ACK to a write to an invalid internal address (0x00 is not valid). This has the effect of the sensor not being detected from the i2c.scan() function. A further look at the i2c.scan() function sees it implement as multi-byte writes, which is not the spec recommended I2C quick commands.
Could you post some build instructions please?
Hello
Due to wanting to use a PC as an emulator of a production device, we want to be able to connect to the same connection as our host device (which is a SPI Master)...
we would like therefore be able to connect the Pico acting as a SPI slave, and the (UI based on C#) communicate via the PICO as that slave.
(we also use a GPIO as a flag to the host so the GPIO support will be used for that)
Is this possible - i think currently, the interfaces supported on the Pico is a Master implementation of the SPI only - but wonder if we can extend and create a SPI-slave.cpp implementation?
regards
Would it be possible to implement a USB-to-UART bridge that shows up on USB-CDC similar to how the MCP2221a has the USB-HID and USB-CDC which maps the TX and RX pins to /dev/ttyACM0 on your laptop?
I found this project https://github.com/Noltari/pico-uart-bridge but I would like to combine that functionality with the u2if firmware.
Hi, im having issue with BLINKA_U2IF vs BLINKA_FT232H, adafruit_epd gives error on U2IF - SPI write_readinto Not implemented ?
Using example based on
https://github.com/adafruit/Adafruit_CircuitPython_EPD/blob/main/examples/epd_blinka.py
Works fine on BLINKA_FT232H
user@uD3H:~/e-ink$ export BLINKA_U2IF=1; python3 pico_u2if_eink.py
Creating display
Clear buffer
Draw Rectangles
Draw lines
Draw text
Traceback (most recent call last):
File "/home/user/e-ink/pico_u2if_eink.py", line 81, in <module>
display.display()
File "/home/user/.local/lib/python3.10/site-packages/adafruit_epd/epd.py", line 81, in display
self.power_up()
File "/home/user/.local/lib/python3.10/site-packages/adafruit_epd/ssd1680.py", line 132, in power_up
self.command(_SSD1680_SW_RESET)
File "/home/user/.local/lib/python3.10/site-packages/adafruit_epd/epd.py", line 170, in command
ret = self._spi_transfer(cmd)
File "/home/user/.local/lib/python3.10/site-packages/adafruit_epd/epd.py", line 187, in _spi_transfer
self.spi_device.write_readinto(self._spibuf, self._spibuf)
File "/usr/local/lib/python3.10/dist-packages/busio.py", line 396, in write_readinto
return self._spi.write_readinto(
File "/usr/local/lib/python3.10/dist-packages/adafruit_blinka/microcontroller/rp2040_u2if/spi.py", line 58, in write_readinto
rp2040_u2if.spi_write_readinto(
File "/usr/local/lib/python3.10/dist-packages/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py", line 375, in spi_write_readinto
raise NotImplementedError("SPI write_readinto Not implemented")
NotImplementedError: SPI write_readinto Not implemented
Hey @execuc , this isn't an issue.
First, thanks for writing this cool firmware. I did the work to add the additional support needed to allow using the Pico w/ u2if firmware from a PC via the Blinka library:
https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico
It all worked really well!
I've also done some simple modifications to allow adding other RP2040 based boards:
adafruit#1
which generally came down to a pin re-mapping. Would you be interested in a pull request to add that capability here?
Also - curious what build environment you used for your release artifacts? I was originally using gcc-arm-none-eabi-10-2020-q4-major
to build for the PR linked above and had issues with it creating an infinite loop inside StreamedInterface::streamRxRead
. Eventually tried just switching to gcc-arm-none-eabi-7-2018-q2-update
which worked as expected. Really weird issue.
In my project, I want run "regular" Python code on my main computer and have it communicate with external devices connected through the Raspberry Pi Pico. So I use this u2if file.
In the actual use process I found that when I set the SPI configure like that (polarity=0, phase=1), But what I see in the oscilloscope is (polarity=0, phase=0). I'm very confused about this, and I'm guessing if these two parameters of polarity and phase are not actually being received, the program is still using the default parameters.
Can you give me some suggestions? thanks!
Below is my code.
`import busio
import board
import digitalio
cs = digitalio.DigitalInOut(board.GP26)
cs.direction = digitalio.Direction.OUTPUT
cs.value = True
spi = busio.SPI(clock=board.SCK0, MOSI=board.MOSI0, MISO=board.MISO0)
while not spi.try_lock():
pass
spi.configure(baudrate=4000000, polarity=0, phase=1, bits=8)
try:
cs.value = False
spi.write(b'\xff')
cs.value = True
finally:
spi.unlock()`
when using machine.u2if.py I was confronted with an error
I investigated the cause. I found that
line 40 reads: serial_number = self._hid.serial
and line 49 reads: return self.serial_number.
When I changed line 40 into: self.serial_number = self._hid.serial
the error disappeared and I got an answer: the serial number of the Pico.
For any reason, it seems the udev rule is not working, which is weird because it´s syntactically correct.
Whenever I change manually the rights on /dev/hidraw1 I can execute some code but as soon as the code ends, the rights are changed back to 600.
changing the udev rule to:
SUBSYSTEM=="usbhid", ATTR{idVendor}=="cafe", ATTR{idProduct}=="4005", MODE="0666"
has no effect. When adding an action to the rule, the script is not interpreted.
Here is what udevadm monitor says when I plug-unplug the RP2040 board flashed running the u2if firmware, compiled from source, (af31706)
KERNEL[10776.365159] add /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
KERNEL[10776.367501] change /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
KERNEL[10776.367759] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
KERNEL[10776.368106] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0/tty/ttyACM0 (tty)
KERNEL[10776.368192] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
KERNEL[10776.368253] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
KERNEL[10776.368310] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
KERNEL[10776.368560] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
KERNEL[10776.369569] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
KERNEL[10776.369618] add /class/usbmisc (class)
KERNEL[10776.369759] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/usbmisc/hiddev0 (usbmisc)
KERNEL[10776.370026] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022/hidraw/hidraw1 (hidraw)
KERNEL[10776.370091] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
KERNEL[10776.370144] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
KERNEL[10776.370200] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
UDEV [10776.370576] add /class/usbmisc (class)
UDEV [10776.381484] add /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
UDEV [10776.394132] change /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
UDEV [10776.398635] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
UDEV [10776.398980] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
UDEV [10776.401738] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
UDEV [10776.401890] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
UDEV [10776.403834] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0/tty/ttyACM0 (tty)
UDEV [10776.405416] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
UDEV [10776.405779] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/usbmisc/hiddev0 (usbmisc)
UDEV [10776.411430] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
UDEV [10776.415320] add /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022/hidraw/hidraw1 (hidraw)
UDEV [10776.416902] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
UDEV [10776.417782] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
UDEV [10776.422553] bind /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
KERNEL[10850.835526] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0/tty/ttyACM0 (tty)
KERNEL[10850.835582] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
KERNEL[10850.835611] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
KERNEL[10850.835642] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
KERNEL[10850.835672] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
KERNEL[10850.835820] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/usbmisc/hiddev0 (usbmisc)
KERNEL[10850.835844] remove /class/usbmisc (class)
KERNEL[10850.835867] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022/hidraw/hidraw1 (hidraw)
KERNEL[10850.835893] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
KERNEL[10850.835922] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
KERNEL[10850.835946] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
KERNEL[10850.835975] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
KERNEL[10850.836487] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
KERNEL[10850.836564] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
UDEV [10850.838048] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0/tty/ttyACM0 (tty)
UDEV [10850.838755] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
UDEV [10850.839523] remove /class/usbmisc (class)
UDEV [10850.839890] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.1 (usb)
UDEV [10850.840796] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/usbmisc/hiddev0 (usbmisc)
UDEV [10850.842037] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
UDEV [10850.842621] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022/hidraw/hidraw1 (hidraw)
UDEV [10850.843225] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0 (usb)
UDEV [10850.843259] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
UDEV [10850.843839] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2/0003:CAFE:4005.0022 (hid)
UDEV [10850.844845] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
UDEV [10850.845521] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.2 (usb)
UDEV [10850.846463] unbind /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
UDEV [10850.847146] remove /devices/pci0000:00/0000:00:14.0/usb2/2-6 (usb)
The error thrown is always the same: HIDException: unable to open device
The Correct VID and PID is passed to the python HID lib, but no serial.
Well, and I´m using the Python example in a venv with jupyter-lab on Debian 11. (kernel 5.10.06)
I´ve tested the udev rule on Fedora 33 (kernel 5.11.11) and it´s same: the correct rights never are applied.
While testing U2IF I've noticed that it sometimes takes more than one try to connect to the device:
>>> dev = machine.Device()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/helper.py", line 9, in __call__
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/u2if.py", line 22, in __init__
raise ValueError("No board found")
ValueError: No board found
>>> dev = machine.Device()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/helper.py", line 9, in __call__
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/u2if.py", line 22, in __init__
raise ValueError("No board found")
ValueError: No board found
>>> dev = machine.Device()
>>> dev.firmware_version
[0, 5, 0]
>>> dev.vid
51966
>>> dev.pid
16389
In the example above it took 3 attempts to connect to a RP2040 Pico. Given that the hid
library seems to only return null/None
with no apparent errors thrown would it be possible to add some kind of connection retry mechanism?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.