Coder Social home page Coder Social logo

hermitter / matrix-lite-py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matrix-io/matrix-lite-py

0.0 1.0 0.0 2.11 MB

Program your MATRIX device with Python!

Home Page: https://matrix-io.github.io/matrix-documentation/matrix-lite/getting-started/python/

License: GNU General Public License v3.0

Python 40.19% Dockerfile 2.53% Shell 5.06% C++ 52.21%

matrix-lite-py's Introduction

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
  • 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 ./

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.