Skip to main content

A transparent library for communication between Python and Arduino

Project description

PyDuino Bridge Build Status PyPI

Library for bi-directional communication between Python and Arduino.

Connect Python and Arduino as easily as sending a list of variables from one platform and receiving it on the other one. With PyDuino Bridge, you can bi-directionally send a string, a list of integers, and a list of floats. Thus, you can bring the Python computational power and flexibility to the real-world interfacing capability of Arduino.

The library is built on the code posted in the Arduino forum by Robin2, who gave me his permission to use it. The main objective of PyDuino Bridge is to allow a high-level and straightforward connection between Python and Arduino.

Instalation

You need to install pyduinobridge in both Arduino IDE and Python.

In Python:

PyDuino Bridge is on the Python Package Index. To install the library, first install pip and then use the command pip install pyduinobridge.

The PyDuino Bridge library requires PySerial library. You can install it with the command pip install pyserial.

The library uses Python>=3.6 and has been tested on different platforms (Windows, Ubuntu, Raspberry Pi, and Jetson Nano).

To use the library in your Python code, use the command from pyduinobridge import Bridge_py.

[Linux] Port opening error due to permission requirements:

To solve this error, follow this tutorial from the Arduino official page. Remember that you can log out of your Linux session with the command gnome-session-quit.

If the problem persists, you may execute the command sudo chmod 666 /dev/ttyACM0 (as suggested here). For the example command given, I assume that your Arduino board is connected to the port ttyACM0.

In Arduino:

PyDuino Bridge is on the official Arduino Library Manager. Just type pyduino bridge in the search box and install the library. You can follow the official Arduino tutorial.

Optionally, you can manually add the files src/pyduino_bridge.h and src/pyduino_bridge.cpp to your .../Arduino/libraries/ folder.

To use the library in your Arduino code, add #include <pyduino_bridge.h> in the header.

Example of use

Once the libraries are installed, executepython_example.py on the Python device.

Also, upload examples/arduino_example/arduino_example.ino to your Arduino board. Connect the devices physically through their serial port. You can use a USB cable or maybe a serial Bluetooth module to achieve wireless connectivity. The example code has been tested on Arduino Nano and UNO boards with Python running on Windows, Ubuntu, Raspberry Pi, and Jetson Nano.

Configuration considerations

By default, the maximum number of characters allowed in the messages between Arduino and Python is 40. If you want to change this buffer size, you have to put the same value in both the Python (change the value buffSize when using the begin method) and the Arduino code (change the line #define buffSize 40 in the pyduino_bridge.h and pyduino_bridge.cpp files).

Also, verify that the same numIntValues_FromPy and numFloatsValues_FromPy values are configured in your Python code according to the Arduino library files (before uploading, change the lines #define numIntValues_FromPy 1 and #define numFloatValues_FromPy 1 in the pyduino_bridge.h and pyduino_bridge.cpp files). By default, PyDuino Bridge is configured to send and receive a list of one integer and a list of one float (besides the header and the time information).

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

pyduinobridge-1.0.7.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

pyduinobridge-1.0.7-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file pyduinobridge-1.0.7.tar.gz.

File metadata

  • Download URL: pyduinobridge-1.0.7.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for pyduinobridge-1.0.7.tar.gz
Algorithm Hash digest
SHA256 643e0d6eec8c922ffc0b54b98d342dd2c674bbec08ae6958d5665613c7935712
MD5 cbbd07d2ac3244487ba2ed845378b175
BLAKE2b-256 5a23850b0b33e32de3afbb77343340adf45fabf7e76d2ad4353f19d7aac4b29d

See more details on using hashes here.

File details

Details for the file pyduinobridge-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: pyduinobridge-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for pyduinobridge-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b425f2b7a475ea3e277e954c50d2730fda9054214875bc45e2d1d65ef63b7401
MD5 5fd49ea5081aae604e258084df5558be
BLAKE2b-256 5de0cc28b1541a232773b40ebe7534dd07cd68fe2d19bd1f59fab5b13047bc29

See more details on using hashes here.

Supported by

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