Skip to main content

A library designed to facilitate communication between Python and Arduino devices.

Project description

ezarduino

Static Badge Static Badge

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 Serial class.
  • 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:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. 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!

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

ezarduino-1.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ezarduino-1.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file ezarduino-1.0.0.tar.gz.

File metadata

  • Download URL: ezarduino-1.0.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.1

File hashes

Hashes for ezarduino-1.0.0.tar.gz
Algorithm Hash digest
SHA256 07ac355c93d1bae2c4dd0be63408d755489f8f2cf858c001d1ca33e320f6dea6
MD5 133d5c4fb0b9f9a0282142afb0bcd6f5
BLAKE2b-256 3fd8842cbabf133136a360ea919127b7dd6b9245226a0724d57b9ba32ff5d2b2

See more details on using hashes here.

File details

Details for the file ezarduino-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ezarduino-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.1

File hashes

Hashes for ezarduino-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6488ea25ca743dd90f71a72bd4db35a11a3a9be61e97e37e250c6cb68dba09f
MD5 c607b743b53f183d4bb11416263926d1
BLAKE2b-256 ca50ba254d264bdfc5495327def1a51bfc79cb7cb2e945f0b2e6b35c01c20d41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page