Giter VIP home page Giter VIP logo

firmatazero's Introduction

firmatazero Code style: black

The simplest Python interface for controlling pins on Arduino by using Firmata protocol.

This project aims to bring GPIO Zero's excellent Python interface from Raspberry Pi's to Arduinos, while making only minor adjustments that make sense in due to different hardware. This means that in some cases existing gpiozero code can work on Arduino by simply changing imports and pin numbers.

Firmatazero automatically detects Arduino's port and on default expects Arduino Uno, and is thread safe.

Blink example:

from firmatazero import LED
from time import sleep

led = LED(13) # 13 == LED_BUILTIN

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)

Servo example:

from firmatazero import Servo
from time import sleep

servo = Servo(9)
while True:
    servo.min()
    sleep(1)
    servo.mid()
    sleep(1)
    servo.max()
    sleep(1)

Needless to say, this project is heavily inspired by GPIO Zero. This means that the project structure and docstrings are very related, even if the underlying code is different.

This project is build with pyFirmata2 and pySerial libraries.

Currently has very limited amount of devices. Used in botafar.com for making shareable, realtime global remote controls possible for robotics projects.

Installation

Python side:

pip install firmatazero --upgrade

Arduino side: on Arduino IDE select File > Examples > Firmata > StandardFirmata.

Then select your board and port from Tools > Board and Tools > Port. Then press Upload.

Supported devices

You can use GPIO Zero's docs, if you take changes intpo account:

DigitalOutputDevice

Same as GPIO Zero's LED, except:

  • blink() not implemented
  • pin_factory does not have an effect

LED

Same as GPIO Zero's LED, except:

  • pin parameter has a default value of 13, the buildin LED
  • blink() function and active_high parameter not implemented
  • pin_factory does not have an effect

Servo

Same as GPIO Zero's Servo, except:

  • pin parameter has a default value of 9, the pin used in Knob and Sweep examples
  • min_pulse_width and max_pulse_width have default values from Arduino Servo.h library, this means that most hobby servos move 180 degrees out of the box
  • detach() function not implemented, so Servo.value = None is not allowed
  • pin_factory does not have an effect

New functions

  • detect_port() detects and returns the first Arduino port it finds, or raises RuntimeError
  • set_port(port) allows skipping port autodetection, for example: set_port("COM1")
  • set_board(board) allows setting another pyFirmata2 board or settings compared to the default one, for example: set_board(pyFirmata2.ArduinoMega("COM4"))
  • get_board get pyFirmata2 board shared with all devices, to run some custom code with

Contributing

Contributions are very welcome. Anything that makes this project to support more GPIO Zero's Devices are very welcome.

firmatazero's People

Contributors

ollipal avatar

Watchers

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