Giter VIP home page Giter VIP logo

u2if's Introduction

u2if project

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 microcontroller 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.GP_3, Pin.OUT, value=Pin.HIGH)
time.sleep(1)
# Switch off the led
led.value(Pin.LOW)

Caution

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).

Why this project ?

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.

Solutions already exist, for example Blinka from Adafruit via the FT2232H in CircuitPython or pyftdi in Python with the same IC.

Nevertheless I find it interesting to implement a majority of the functionalities of the machine module and add other protocols.

Implemented Interfaces

The following features are coded:

  • machine.Pin: input (+irq, +debounced), output (+pull down/up).
  • machine.Signal
  • machine.ADC: read (12bits)
  • machine.UART
  • machine.I2C
  • machine.SPI
  • machine.PWM
  • WS2812B led
  • I2S

Licenses and Project directories

This repository is presented as the sources of a python project (License). But it also contains the following projects:

How to use it

Upload PICO firmware

See Firmware README

Install u2if python package

Install python package from release file (u2if-..tar.gz) with python3 -m pip install dist/u2if-..tar.gz

Build u2if python package

To build package if wanted :

  • If needed, install build: python3 -m pip install --upgrade build
  • Build it: python3 -m build

Examples

There is no documentation but examples can help to use this library :

  • Led On/Off
  • Switch with or whithour irq and debouncing
  • PWM controlling servo-motor
  • Display testing: SSD1306 (I2C and SPI), GC9A01 (round lcd)
  • Some sensors simple test: MPU9250 (IMU), VL53L0X (range), BMP280(Temp)
  • UART read/Write
  • Analog read.
  • Rotrary encoder
  • I2C scan
  • Play 48khz 16bit .wav over I2S DAC (PAM5102)
  • ...

u2if pinout

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.

Troubleshooting

Import error using MicroPython module

import ustruct

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

import utime & const

Install micropython-cpython-utime and micropython-cpython-micropython.

u2if's People

Contributors

execuc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.