A wrapper for MATRIX HAL in Python
Project description
MATRIX-Lite-Py
MATRIX Lite Python is a library that allows users of varying skill levels to easily program their MATRIX Device.
Roadmap
- Leds
- Sensors
- IMU
- Humidity
- Pressure
- UV
- GPIO
- Microphones
- Hal Mics
- ALSA Mics (available through any ALSA wrapper)
- NFC (separate library)
Installation
Ensure you have a Raspberry Pi, attached with a MATRIX device, that's flashed with Raspbian.
1. Install MATRIX HAL
https://matrix-io.github.io/matrix-documentation/matrix-hal/getting-started/installation-package/
2. Install Python 3
To call your scripts with python 3, use
python3 YOUR_SCRIPT.py
sudo apt-get install python3-pip
3. Upgrade PIP
python3 -m pip install --upgrade pip
4. Install matrix-lite-py
python3 -m pip install --user matrix-lite
Usage
The matrix-lite package contains a matrix_lite
& _matrix_hal
Python module. _matrix_hal
is the direct HAL implementation. matrix_lite
contains small abstractions for _matrix_hal
.
Everloop
from matrix_lite import led
import time
# Get LED count
print('This device has ' + str(led.length) + ' Leds')
# A single string, object, or tuple will set all LEDs
# Below are different ways of expressing a color (number values are from 0-255)
led.set('blue')
led.set('#0000ff')
# Objects and tuples can utilize the white LED
led.set({'r':0, 'g':0, 'b':255, 'w':0 })
led.set((0,0,255,0))
# LEDs off
led.set('black')
led.set([])
led.set()
led.set({})
# Arrays set individual LEDs
led.set(['red', 'gold', 'purple', {}, 'black', '#6F41C1', 'blue', {'g':255}])
# Arrays can simulate motion
everloop = ['black'] * led.length
everloop[0] = {'b':100}
while True:
everloop.append(everloop.pop(0))
led.set(everloop)
time.sleep(0.050)
Sensors
from matrix_lite import sensors
import time
# Sensors will update with each .read() call
while True:
# Each .read() returns a dictionary
print(sensors.imu.read())
print(sensors.uv.read())
print(sensors.humidity.read())
print(sensors.pressure.read())
time.sleep(5/1000)
GPIO
from matrix_lite import gpio
# Read GPIO pin 0 (digital)
gpio.setFunction(0, 'DIGITAL')
gpio.setMode(0, 'input')
print('Pin 0 is: ' + str(gpio.getDigital(0)))
# Set GPIO pin 1 (digital)
gpio.setFunction(1, 'DIGITAL')
gpio.setMode(1, 'output')
gpio.setDigital(1, 'ON')
# Set GPIO pin 2 (PWM)
gpio.setFunction(2, 'PWM')
gpio.setMode(2, 'output')
gpio.setPWM({
"pin": 2,
"percentage": 25,
"frequency": 50, # min 36
})
# Set Servo Angle pin 3
gpio.setFunction(3, 'PWM')
gpio.setMode(3, 'output')
gpio.setServoAngle({
"pin": 3,
"angle": 90,
# min_pulse_ms (minimum pulse width for a PWM wave in milliseconds)
"min_pulse_ms": 0.8,
})
Building Locally For Development
Make sure you have MATRIX HAL & Python 3 installed.
If you want to contribute to matrix-lite-py, below are the steps to build locally. Each step should take place on your Raspberry Pi.
Download the repository.
git clone https://github.com/matrix-io/matrix-lite-py
Install pybind11.
sudo python3 -m pip install pybind11
Compile and install the matrix_lite
python package with your changes.
cd matrix-lite-py
sudo python3 -m pip install ./
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file matrix-lite-0.0.8.tar.gz
.
File metadata
- Download URL: matrix-lite-0.0.8.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a761fb31e059f72c568c44a6771dc9f9cd6050221b48ca171d2f882eb71181a4 |
|
MD5 | 97d178256b8bff53af4e6ef1bccd1a49 |
|
BLAKE2b-256 | ca09dc1b23f758583b168165eab553f3300fae309820d51a1a5031f96e6d2e73 |
File details
Details for the file matrix_lite-0.0.8-cp37-cp37m-linux_armv7l.whl
.
File metadata
- Download URL: matrix_lite-0.0.8-cp37-cp37m-linux_armv7l.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c7864cf45a83838f6e0f12c9801eb7b045f350ce6fd290995c6c8a589e4e7f5 |
|
MD5 | c35e21439079d27e1d02aa99c392f09f |
|
BLAKE2b-256 | 66c7e90c58adcbda7c0e3e4f564309d51f7be1ab85625168a7d50698f85c8045 |
File details
Details for the file matrix_lite-0.0.8-cp37-cp37m-linux_armv6l.whl
.
File metadata
- Download URL: matrix_lite-0.0.8-cp37-cp37m-linux_armv6l.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05d787ef7a2e3bdff6af1152e627d098d2ea8223aae80e1cda32f65dc735b6c7 |
|
MD5 | b9049aa1c375843e28d70af79b1cb4c3 |
|
BLAKE2b-256 | 3dd1b8d292f7c714aca469359c0e79e7689be625f6b58e85968cdedae4bf6d39 |
File details
Details for the file matrix_lite-0.0.8-cp35-cp35m-linux_armv7l.whl
.
File metadata
- Download URL: matrix_lite-0.0.8-cp35-cp35m-linux_armv7l.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fc57c3a8cc9c19628a4605290f3082998a364385b0a1a339771d5ff6ab8480b |
|
MD5 | 205b681b4f8bd3ab253df1731788136b |
|
BLAKE2b-256 | a97e49cf325266075d6622b0e86b6e3ca4109bb8c6d35892ce37405e3b2984de |
File details
Details for the file matrix_lite-0.0.8-cp35-cp35m-linux_armv6l.whl
.
File metadata
- Download URL: matrix_lite-0.0.8-cp35-cp35m-linux_armv6l.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1d1461dbac55940907b8bf2e052db07657f494e7aad9c6e1c7c343931df6a5e |
|
MD5 | 12a9c19ed8bb99ba9955217a274ff05a |
|
BLAKE2b-256 | 4ec3d5f3ff97c8f1fab1d54fca307e607a85337fd6f71149de380532f34c67ac |