Rapidly develop code to control an Arduino using Python
Project description
Rapiduino
Rapiduino is a Python library to allow Python code to control an Arduino. The Python code runs on a computer connected to an Arduino through a serial connection.
A sketch is provided to upload to the Arduino. The Rapiduino library can be used to connect to the Arduino and send it familiar commands such as digitalWrite and pinMode. By sending these commands from Python and not writing them directly on the Arduino, you gain the power of Python's wonderful syntax and libraries.
Why use Rapiduino?
- Rapidly develop using everyone's favourite language 😉
- Easily integrate an Arduino with Python's libraries to provide a real-time clock, web access, data visualisation, number crunching etc...
- Allow hot-swappable parts. Change pin mode, pin state etc. whenever you like from your Python code!
- Easily obtain data from your Arduino without setting up any custom communication
- Probably many other benefits that will become realised as time goes on...
Are there any downsides?
Of course. Don't use this library if:
- You are not able to run a computer alongside an Arduino (not even a Raspberry Pi) because of issues such as size, battery, operating conditions etc.
- You need timing accuracy that Rapiduino does not yet support; For example, for an ultrasonic sensor where the connection lag could cause inaccuracy (although there are workarounds for this for specific components)
- Probably many others personal to your project...
Status
Rapiduino is in active development. It is ready to be used in simple projects, but there may be some breaking changes and restructuring until it settles down
Installation
pip install rapiduino
Usage
To use with an ArduinoUno, simply import the class and globals as follows. Importing globals give you access to the same INPUT, OUTPUT, HIGH, LOW, A0, A1 etc. as when developing an Arduino sketch
from rapiduino.globals.arduino_uno import *
from rapiduino.globals.common import *
from rapiduino.boards.arduino import Arduino
Set up the class and serial connection with the following. The port to be passed in can be identified using the Arduino software
arduino = Arduino.uno('port_identifier')
Then start using it! Here is a blinking LED example:
import time
while True:
arduino.digital_write(13, HIGH)
time.sleep(1)
arduino.digital_write(13, LOW)
time.sleep(1)
You can also use classes for components (such as LEDs) which make using the Arduino easier and less error-prone. The components are "registered" to the Arduino along with a pin-mapping which tells the Arduino object which pins are connected to the component. Let's look at an example with an LED:
from rapiduino.components.led import LED
led = LED(arduino, 13)
This creates an LED object and registers it to the arduino against pin 13. When binding, the code automatically takes care of checking compatibility, raising an error if there is a problem. For example, if you are trying to connect a component that requires a PWM pin to a non-PWM pin, you will get a helpful message.
You can re-write the blink example as:
while True:
led.toggle()
time.sleep(1)
The benefit of this is that you can use methods with familiar names such as:
led.turn_on()
led.turn_off()
led.toggle()
You don't need to think of pin states or pin modes when interacting with your components, and you don't need to keep track of which pin is connected to which component - rapiduino will do that for you.
Contribution
Yes please! Code and/or suggestions are very welcome! Feel free to raise an issue or raise a pull request from a fork.
Developing
Rapiduino uses poetry to handle the installation.
To install Rapiuino for development:
poetry install
To run tests:
make test
will run all testing, linting, type checking and coverage reporting
make fix
will auto-fix any issues found by isort
and black
Licence
Rapiduino is released under the Apache-2.0 licence.
If you contribute code to this repository, you agree that your code will also be released under this licence.
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 Distribution
File details
Details for the file rapiduino-1.2.0.tar.gz
.
File metadata
- Download URL: rapiduino-1.2.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 081c671c422f34570a799d8d2342f904cf07690bc6ceea064a660c117285caf2 |
|
MD5 | 2a2fc099d25c51ed9df4df655c2d9ea0 |
|
BLAKE2b-256 | f53d316e914d3bda48ca3dbbac1bf7501303995b1e625bf3885adfb2000e8b5c |
File details
Details for the file rapiduino-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: rapiduino-1.2.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/18.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8addd94735ae05d82cb2a235e6d3493d4266192500ac5017fb233e94083088e |
|
MD5 | a6f8b3c9cb6b54b19c1940e45bd072f6 |
|
BLAKE2b-256 | 1950ecfd60728548b202d94d2a05f1c0362ee1f3ef67494d62b5ee1d8b5ae892 |