Skip to main content

[BETA] Link Arduino and Python using serial port

Project description

SeriArduino

Install

For Arduino

  • Clone the repo
  • Compress the seriarduino_cpp folder into seriarduino_cpp.zip

Note: You can also download seriarduino_cpp.zip from the releases

  • Open the Arduino IDE
  • Go into Sketch > Include a library and add the library from the seriarduino_cpp.zip file

For Python (tested on Raspbian)

  • Clone the repo OR uncompress the seriarduino_py.zip file from the releases

  • Open the seriarduino_py folder 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for seriarduino, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size seriarduino-0.1.0-py2-none-any.whl (2.6 kB) File type Wheel Python version py2 Upload date Hashes View hashes
Filename, size seriarduino-0.1.0-py3-none-any.whl (2.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size seriarduino-0.1.0.tar.gz (2.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page