ezarduino
ezarduino is a Python library designed to facilitate communication between Python and Arduino devices via the Arduino Serial Port (ASP). It provides a Python-based reconstruction of Arduino's Serial class, making it easier to send and receive data between your Python scripts and Arduino projects.
Features
- Easy-to-use class for managing Arduino devices over serial ports.
- Core functionality mirroring Arduino's
Serialclass. - Support for:
- Reading bytes and strings from Arduino.
- Writing data to Arduino.
- Checking available bytes and write readiness.
- Built-in support for encoding (default: UTF-8).
Installation
To install ezarduino from the PyPi, run the next command:
pip install ezarduino
But to install ezarduino from the repo, run the next commands:
git clone https://github.com/cr4t3/ezarduino.git
cd ezarduino
pip install .
Usage
Here is a quick example to demonstrate the basic functionality of ezarduino:
Example: Sending and Receiving Data
from ezarduino import ArduinoDevice
# Connect to Arduino (adjust COM por, baud rate and timeout as necessary)
arduino = ArduinoDevice(com="COM3", baud_rate=9600, timeout=1000)
# Send data to Arduino
arduino.println("Hello, Arduino!")
# Read data from Arduino
try:
while arduino.available():
print("Received:", arduino.readString())
except IndexError:
print("No data available to read.")
# Close connection
arduino.end()
API Reference
ArduinoDevice
Initialization
ArduinoDevice(com: str, baud_rate: int = 9600, timeout: int = 1000, encoding: str = "utf-8")
- com: Serial port of the Arduino device (e.g.,
"COM3"or"/dev/ttyUSB0"). - baud_rate: Communication speed (default:
9600). - timeout: Timeout in milliseconds (default:
1000). - encoding: Encoding used for string communication (default:
UTF-8).
Methods
available(): Returns the number of bytes available for reading.availableForWriting(): Returns the number of bytes available for writing.end(): Closes the serial port connection.begin(): Initializes the serial port connection.find(target: str, length: int = 0): Searches for a character in the serial buffer.findUntil(target: str, terminal: str): Searches for a character in the serial buffer until a terminal character is found.flush(): Waits until all data is written to the serial port.parseFloat(lookahead: LookaheadMode = SKIP_ALL, ignore: strs = None): Reads a float from the serial buffer.parseInt(lookahead: LookaheadMode = SKIP_ALL, ignore: str = None): Reads an integer from the serial buffer.read(): Reads one byte from the serial buffer.readBytes(buffer: list[byte], length: int): Reads a specified number of bytes into a buffer.readBytesUntil(character: str, buffer: list[str or byte], length: int): Reads bytes into a buffer until a specified character is found.readString(): Reads all available bytes from the serial buffer as a string.readStringUntil(terminator: str): Reads bytes from the serial buffer until a terminator character is found.print(val: any, format: FormatMode = None): Prints a value to the serial buffer.println(val: any, format: FormatMode = None): Prints a value to the serial buffer followed by a newline.setTimeout(time: int): Sets the timeout for the serial port connection.write(val) OR write(str) OR write(buf, len): Writes data to the serial buffer.
Contributing
We welcome contributions! If you would like to contribute to ezarduino, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
For issues, suggestions, or feedback, please open a GitHub Issue in the repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Requirements
- Python 3.12.1 or newer
- pyserial 3.5 or newer
Acknowledgments
Special thanks to the open-source community for inspiring this project. Let's make Arduino projects even more accessible with Python!
Release files for ezarduino 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ezarduino-1.0.0.tar.gz | 10.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ezarduino-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / ezarduino-1.0.0.tar.gz
| Download URL | ezarduino-1.0.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07ac355c93d1bae2c4dd0be63408d755489f8f2cf858c001d1ca33e320f6dea6
|
|
BLAKE2b-256 checksum How to use checksums |
3fd8842cbabf133136a360ea919127b7dd6b9245226a0724d57b9ba32ff5d2b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.1
|
Release files / ezarduino-1.0.0-py3-none-any.whl
| Download URL | ezarduino-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6488ea25ca743dd90f71a72bd4db35a11a3a9be61e97e37e250c6cb68dba09f
|
|
BLAKE2b-256 checksum How to use checksums |
ca50ba254d264bdfc5495327def1a51bfc79cb7cb2e945f0b2e6b35c01c20d41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.1
|