Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Arduino library to send key/value pairs from PC (Python) to Arduino

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 .gitignore
Octocat-spinner-32 DataReceiver.h
Octocat-spinner-32 DataSender.py
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Shared.h
README.markdown

DataReceiver

Arduino library to provide simple sending of key/value pairs from a computer to the Arduino. (For example: I have a CPU usage value on my desktop computer, and want to use an Arduino to control some lights in response to that. This gets the number to from desktop to Arduino.)

To match DataReceiver (the Arduino side) is DataSender in Python. It depends on pySerial for serial communication.

Example

See examples/ for a quick introduction. Even more briefly:

Python:

sender = DataSender.Sender('/dev/usb.serialmodemfa141')
with sender:
    while True:
        ... # Generate a value.
        sender.send(KEY=value)

        # Maybe handle responses from the Arduino.
        sender.readAndPrint()

Arduino:

#include <DataReceiver.h>
DataReceiver<1> receiver; // templated on # keys expected
void callback(size_t size, const char* value) {
    ... // do something with value
}
void setup() {
    receiver.setup(); // Serial.begin
    receiver.addKey("KEY", &callback);
    receiver.sendReady(); // once ready to take Serial input
}
void loop() {
    receiver.readAndUpdate(); // read Serial, call callbacks
}
Something went wrong with that request. Please try again.