[BETA] Link Arduino and Python using serial port
Project description
SeriArduino
Install
For Arduino
- Clone the repo
- Compress the
seriarduino_cppfolder intoseriarduino_cpp.zip
Note: You can also download
seriarduino_cpp.zipfrom the releases
- Open the Arduino IDE
- Go into
Sketch>Include a libraryand add the library from theseriarduino_cpp.zipfile
For Python (tested on Raspbian)
-
Clone the repo OR uncompress the
seriarduino_py.zipfile from the releases -
Open the
seriarduino_pyfolder in a terminal -
In the terminal, enter
./setup.py install
Usage
The following sample is linking an Arduino with a Raspberry Pi:
Arduino side
#include <SeriArduino.h>
SeriArduino raspberry;
String input;
float value;
void setup () {
// We set the serial to 9600 bauds (be sure to use the same on the Python side)
Serial.begin(9600);
}
void loop() {
// If raspberry gets any data
if(raspberry.available()) {
// We read the data and save it into the "input" variable
input = raspberry.read();
// We convert the input into a float,
// to do some computations later
value = input.toFloat();
Serial.println("We got a " + String(value));
// A simple computation
value = value * 2;
// We send the new data to the Raspberry Pi
raspberry.write(value);
}
delay(100);
}
Python side (Raspberry Pi)
from seriarduino import SeriArduino
arduino = SeriArduino(bauds = 9600)
while True:
# We ask what value to send
val = input("Value to send: ")
# We send to Arduino this value
arduino.write(val)
print ("Value sent: ", val)
# We wait for the answer
answer = arduino.read()
print ("The Arduino answer is: ", answer)
By default, SeriArduino will try to find the serial address, but you can also manually specify it by using the address argument on the constructor (e.g.
SeriArduino(address = "/dev/ttyACM0"))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seriarduino-0.1.0.tar.gz.
File metadata
- Download URL: seriarduino-0.1.0.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73090f1576cb773a8c52e273012a46dfb0de0ee3d3f88126344d9a69421d62b3
|
|
| MD5 |
2a15ab048bf9fa3516227a4e7795eaf2
|
|
| BLAKE2b-256 |
46366cc5fb996cd54e643b1b0657d20937427e5d46506e4102484f2bba2352d0
|
File details
Details for the file seriarduino-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seriarduino-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79c6aec3be8fd82bd79bfabba04ff201aa1934cc536c3e150573856d00e5de38
|
|
| MD5 |
3f134755d3cbe2532f5b462334a459d2
|
|
| BLAKE2b-256 |
0d934d02924230ac4a72a39ae801607f9db1f699ab68670371902e46baca679f
|
File details
Details for the file seriarduino-0.1.0-py2-none-any.whl.
File metadata
- Download URL: seriarduino-0.1.0-py2-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8572d0097033c38468822dba6ebcf83e6013d39b9a6b0c7359e3b7b363fcce8a
|
|
| MD5 |
0c725c6a8e977528e8f63336b33e7648
|
|
| BLAKE2b-256 |
2863f43e1ed0f51f27da88af3a557e9f462853ae75373f51f20fd60137304d96
|