Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
execuc committed Mar 20, 2021
0 parents commit 24e6a2b
Show file tree
Hide file tree
Showing 126 changed files with 72,028 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
firmware/pico-sdk
firmware/source/build/
firmware/source/config.h.in
*.idea
dist
u2if.egg-info
build
*.txt.user
__pycache__
venv/
5 changes: 5 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
See License files for the three parts of the u2if project:
- python library: source/LICENSE
- firmware for raspberry pico: firmware/source/LICENSE
- KiCad dev. board: board/LICENSE

114 changes: 114 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# 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.

<p align="center"><img src="images/principle.png"/></p>

**Python led swith on/off**:
```python
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](firmware/README.md)).


## 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](https://github.com/adafruit/Adafruit_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

Other features to do:
* WS2812B led driver
* I2S
* ...

## Licenses and Project directories
This repository is presented as the sources of a python project ([License](source/LICENSE)).
But it also contains the following projects:

* [firmware](firmware/): PICO firmware, binary and C++ source [License](firmware/source/LICENSE).
* [examples](examples/): Python program examples.
* [board](board/): Example of a pico headers board for this project ([License](firmware/source/LICENSE)).


## How to use it

### Upload PICO firmware
See [Firmware README](firmware/README.md)

### 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](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
* ...


## 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.
<p align="center"><img src="images/u2if_pinout.png"/></p>

## 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:
```python
import ustruct
```
to:
```python
import struct as ustruct
```

#### import utime & const

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



30 changes: 30 additions & 0 deletions board/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# From https://raw.githubusercontent.com/github/gitignore/master/KiCad.gitignore
# For PCBs designed using KiCad: http://www.kicad-pcb.org/
# Format documentation: http://kicad-pcb.org/help/file-formats/

# Temporary files
*.000
*.bak
*.bck
*.kicad_pcb-bak
*.kicad_sch-bak
*.kicad_prl
*.sch-bak
*~
_autosave-*
*.tmp
*-save.pro
*-save.kicad_pcb
fp-info-cache

# Netlist files (exported from Eeschema)
*.net

# Autorouter files (exported from Pcbnew)
*.dsn
*.ses

# Exported BOM files
*.xml
*.csv

89 changes: 89 additions & 0 deletions board/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Project u2if (KiCad dev. board):
--------------------------------

MIT License

Copyright (c) 2021 execuc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



External library licenses:
--------------------------

--------------
KiCad library:
--------------

Creative Commons CC-BY-SA 4.0 License
------------------------------------------------------------------------------

------------------------------------------------------------------------------
Raspberry Pico KiCad library (https://github.com/HeadBoffin/RP_Silicon_KiCad):
------------------------------------------------------------------------------
The original Raspberry Pi Foundation / Trading license:

These design files are made available openly, with no limitations.

Permission to use, copy, modify, and/or distribute this design for
any purpose with or without fee is hereby granted.

THE DESIGN IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS DESIGN INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS DESIGN.


Which looks rather like the UnLicense:

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>


-------------------------------------------------------------------------------------------------------------------------




12 changes: 12 additions & 0 deletions board/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# PICO headers dev board

<p align="center"><img src="images/pcb_3d.png"/></p>

It's a kicad project of a PCB with some I/O but mostly headers.
Zipped gerber file is available: [Gerber file](pico-dev/gerber/pico-dev.zip)

**Caution**: I am not an electronic engineer, check schematics and PCB before using it !

<p align="center"><img src="images/pcb.jpg"/></p>


Binary file added board/images/pcb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added board/images/pcb_3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added board/pico-dev/doc/0-96_oled_i2c_ssd1306.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added board/pico-dev/doc/GY91-IMU-Pin.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added board/pico-dev/doc/raspberry_pi_pico_pinout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(module Crystal_SMD_HC49-US (layer F.Cu) (tedit 5F0C7995)
(descr "SMD Crystal HC-49-SD http://cdn-reichelt.de/documents/datenblatt/B400/xxx-HC49-SMD.pdf, 11.4x4.7mm^2 package")
(tags "SMD SMT crystal")
(attr smd)
(fp_text reference Y1 (at 0 -3.55) (layer F.SilkS)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_text value ABLS-12.000MHZ-B4-T (at 0 3.55) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_line (start -6.7 1.3) (end -6.7 2.55) (layer F.SilkS) (width 0.12))
(fp_text user %R (at 0 0) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_line (start -5.7 -2.35) (end -5.7 2.35) (layer F.Fab) (width 0.1))
(fp_line (start -5.7 2.35) (end 5.7 2.35) (layer F.Fab) (width 0.1))
(fp_line (start 5.7 2.35) (end 5.7 -2.35) (layer F.Fab) (width 0.1))
(fp_line (start 5.7 -2.35) (end -5.7 -2.35) (layer F.Fab) (width 0.1))
(fp_line (start -3.015 -2.115) (end 3.015 -2.115) (layer F.Fab) (width 0.1))
(fp_line (start -3.015 2.115) (end 3.015 2.115) (layer F.Fab) (width 0.1))
(fp_line (start 5.9 -2.55) (end -6.7 -2.55) (layer F.SilkS) (width 0.12))
(fp_line (start -6.7 -2.55) (end -6.7 -1.3) (layer F.SilkS) (width 0.12))
(fp_line (start -6.7 2.55) (end 5.9 2.55) (layer F.SilkS) (width 0.12))
(fp_line (start -6.8 -2.6) (end -6.8 2.6) (layer F.CrtYd) (width 0.05))
(fp_line (start -6.8 2.6) (end 6.8 2.6) (layer F.CrtYd) (width 0.05))
(fp_line (start 6.8 2.6) (end 6.8 -2.6) (layer F.CrtYd) (width 0.05))
(fp_line (start 6.8 -2.6) (end -6.8 -2.6) (layer F.CrtYd) (width 0.05))
(fp_arc (start -3.015 0) (end -3.015 -2.115) (angle -180) (layer F.Fab) (width 0.1))
(fp_arc (start 3.015 0) (end 3.015 -2.115) (angle 180) (layer F.Fab) (width 0.1))
(pad 1 smd rect (at -4.5 0) (size 5.6 2.1) (layers F.Cu F.Paste F.Mask))
(pad 2 smd rect (at 4.5 0) (size 5.6 2.1) (layers F.Cu F.Paste F.Mask))
(model ${KISYS3DMOD}/Crystal.3dshapes/Crystal_SMD_HC49-SD.wrl
(at (xyz 0 0 0))
(scale (xyz 1 1 1))
(rotate (xyz 0 0 0))
)
)
Loading

0 comments on commit 24e6a2b

Please sign in to comment.