Skip to main content

A library to enable robust communication between an Arduino and a host via serial

Project description

Host-side ArduComm python library and examples

This is the host-side library implementation of ArduComm, written in Python. In addition to the library's source code, different examples and tests are provided in examples and test.

Installation

PYPI installation

The easiest way to install the package is using pip:

python3 -m pip install arducomm

Manual installation

Alternatively, this package can also be manually installed using Python's build module and pip.

First, install the build package if this hasn't been done before:

python3 -m pip install build

Then, build the package and install it with pip:

python3 -m build
python3 -m pip install dist/arducomm-*.whl --force-reinstall

How to use

The class ArduComm is provided in the package and can be used to send and receive data. A callback function must be provided to process the received messages. Note that this implementation handles the incoming messages in a different thread, so there are no reading methods. The provided callback will be called when a new message is available.

from arducomm import ArduComm

def recv_callback(command, payload):
    print(F"Command received: {command}")
    print(F"Payload:\n{payload}")

comms = ArduComm(recv_callback, port='/dev/ttyUSB0', baudrate=57600)
comms.start() # Open the serial port
# Use comms object...
comms.stop() # Close the serial port

How to send data

The function send(command, payload) can be used to send a message with the given command and payload. The payload must be a list of integers, a bytearray, or a bytes object.

comms.send(0x07) # Send command 0x07 with no payload
comms.send(0x03, [55, 50]) # Send command 0x03 with payload bytes [55, 50]

Serialization

In order to work with payloads containing other types than pure bytes (aka uint8_t, aka unsigned char), these types must be serialized (converted to bytes) before being transmitted. Similarly, the array of bytes that is received in the payload must be parsed (deserialized) to reconstruct these types.

To this end, a serialization module is also included in this library, following the implementation of the Arduino library, with support for basic types (char, str, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, and float). Additional "complex" types are also defined in the types directory to provide more options with types such as 2D and 3D vectors, quaternions, or 2D/3D poses.

You can find the full list of supported types and how to serialize/parse them in serialization_test and parser_test.

Finally, you can also define your own types and use the provided serialization functions as it is done in the custom_type example.

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

arducomm-0.1.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

arducomm-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file arducomm-0.1.0.tar.gz.

File metadata

  • Download URL: arducomm-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for arducomm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6cfe33f537b1a2dba78876ebf17d990096cbd4a52903720d43945243eaed7647
MD5 d6d2c8c5baac26ec946250ca58543fa3
BLAKE2b-256 e06e4b30bbb12e5656702ca8423403acf71540f9d7716faa301b20ab350e49a1

See more details on using hashes here.

File details

Details for the file arducomm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: arducomm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for arducomm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b10ce9e1c1f5436c3cf417cae10000f43652bb28db60e006ad0899cf34ad1ae
MD5 8c7fc5c39fc624d0d7cded46b4b71907
BLAKE2b-256 b2975d194da13fb1c271c4684996ec886903ff5c7a1fb5f7b3a2a71d9f6d1a8e

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