u2if(USB to interfaces) is an attempt to implement some of the MicroPython "machine" module functionalities on a computer. The goal is to be able to communicate with breakout boards (sensors, lcd...) simply from a python program on x86 machine. It uses a Raspberry PICO (or other RP2040 based board) to make the interface between the computer (USB) and peripherals/protocols.
Python led swith on/off:
import time
from machine import u2if, Pin
# Initialize GPIO to output and set the value HIGH
led = Pin(u2if.GP3, Pin.OUT, value=Pin.HIGH)
time.sleep(1)
# Switch off the led
led.value(Pin.LOW)
It is in experimental state and not everything has been tested. Use with caution. It is supposed to work on windows, linux and Mac. To work in Linux in non-root, an udev rules has to be added (See Firmware readme).
When I want to retrieve values from a sensor or even to play with a led or a button from the PC, I make an arduino program that communicate to the PC via the serial port. That umplies to define a serial "protocol" between the PC and the arduino and it is not necessarily reusable because it is specific. I find it interesting to implement a majority of the functionalities of the MicroPython machine module and add other protocols.
Solutions already exist, for example Adafruit Blinka from Adafruit via the FT2232H in CircuitPython or pyftdi in Python with the same IC. Note: now, firmware part can be also used with Adafruit Blinka !
The following features are coded:
This repository is presented as the sources of a python project (License). But it also contains the following projects:
See Firmware README
Install python package from release file (u2if-..tar.gz) with python3 -m pip install dist/u2if-..tar.gz
To build package if wanted :
There is no documentation but examples can help to use this library :
For simplicity, the pins of the SPI, I2C and UART devices have been fixed. If a peripheral is not used, its pins can be used as a classic I/O. Here are the compatibles boards.
The ustruct module is belongs by micropython. There is a micropython-cpython-ustruct compatibility module, but it doesn't seem to work for me. If necessary modify:
import ustruct
to:
import struct as ustruct
Install micropython-cpython-utime and micropython-cpython-micropython.