Package: pyduinobridge
PyDuino BridgeLibrary 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 thecodeposted 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.InstalationYou need to installpyduinobridgein both Arduino IDE and Python.In Python:PyDuino Bridge is on thePython Package Index.
To install the library, first installpipand then use the commandpip install pyduinobridge.The PyDuino Bridge library requires PySerial library. You can install it with the commandpip 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 commandfrom pyduinobridge import Bridge_py.[Linux] Port opening error due to permission requirements:To solve this error, followthis tutorialfrom the Arduino official page. Remember that you can log out of your Linux session with the commandgnome-session-quit.If the problem persists, you may execute the commandsudo chmod 666 /dev/ttyACM0(as suggestedhere). For the example command given, I assume that your Arduino board is connected to the portttyACM0.In Arduino:PyDuino Bridge is on the official Arduino Library Manager. Just typepyduino bridgein the search box and install the library. You can followthe official Arduino tutorial.Optionally, you can manually add the filessrc/pyduino_bridge.handsrc/pyduino_bridge.cppto your.../Arduino/libraries/folder.To use the library in your Arduino code, add#include <pyduino_bridge.h>in the header.Example of useOnce the libraries are installed, executepython_example.pyon the Python device.Also, uploadexamples/arduino_example/arduino_example.inoto 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 considerationsBy 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 valuebuffSizewhen using thebeginmethod) and the Arduino code (change the line#define buffSize 40in thepyduino_bridge.handpyduino_bridge.cppfiles).Also, verify that the samenumIntValues_FromPyandnumFloatsValues_FromPyvalues are configured in your Python code according to the Arduino library files (before uploading, change the lines#define numIntValues_FromPy 1and#define numFloatValues_FromPy 1in thepyduino_bridge.handpyduino_bridge.cppfiles). 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).