Skip to main content

A protocol to control and communicate with Arduino devices from Python.

Project description

Oatmeal Protocol - Control and communicate with Arduino devices from Python

Oatmeal Protocol provides a simple mechanism to autoconnect and control any Arduino-compatible microcontroller from Python over a UART serial port.

The protocol supports multiple data types including integers, strings, floats, booleans, lists, dictionaries and missing values (NULL/None/nil). It even supports nested and mixed type lists.

By using the Oatmeal libraries, developers don't need to develop yet-another bespoke protocol and all the code around parsing those messages -- and can instead focus on building cool devices faster.

Oatmeal was developed by the R&D Team @ Shield Dx and released under the Apache License 2.0. It is not an official Shield Dx product -- the code is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. For more details please see the LICENSE file.

Python Example

from oatmeal import OatmealDevice

class MyDevice(OatmealDevice):
    ROLE_STR = "MyDevice"

board = MyDevice.find()
print("Temperature: ", board.send_and_ack("TMPR").args[0])

Arduino Example (C++)

#define HARDWARE_ID_STR "MyDevice"
#include "oatmeal_protocol.h"

OatmealMsgReadonly msg;
while (port.check_for_msgs(&msg)) {
  if (msg.is_opcode("TMPR")) {
    port.start("TMP", 'A');
    port.append(TEMP_SENSOR.read());
    port.append(OTHER_SENSOR.read());
    port.finish();
  }
}

Message structure

>>> import oatmeal
>>> msg = oatmeal.OatmealMsg("RUNR", 1.23, True, "Hi!", [1, 2], token='aa')
>>> msg
OatmealMsg('RUNR', (1.23, True, 'Hi!', [1, 2]), token='aa')
>>> msg.encode()
bytearray(b'<RUNRaa1.23,T,Hi!,[1,2]>}V')
>>>

Installation

On linux you need to run sudo usermod -a -G dialout $USER and then restart before using UART over USB. You may also have to install USB-to-UART drivers depending on the chip used.

Oatmeal Python (3.5+) Library

Simply install our Python library using using pip:

sudo pip3 install oatmeal

Oatmeal Arduino (1.8+) Library

To install via the Arduino IDE, open the IDE and navigate to 'Sketch' -> 'Include Library' -> 'Manage Libraries...'. From there, search for 'oatmeal' and install the latest version.

To install without the Arduino IDE, download the library from the git repository and copy it into your Arduino libraries folder. For more info, see the Arduino website.

Minimal hardware set up

If you are running Python on a device that has a serial port, simply connect the serial port to the arduino device:

Python device Arduino device
Rx Tx
Tx Rx
GND GND

If you are running Python on a device that has a USB port, get a USB-to-UART bridge like Adafruit's FTDI Friend or Sparkfun's FTDI Basic Breakout and make the same 3 connections as shown above. Hardware flow control pins (DTR/CTS) are not used.

Debugging

Oatmeal proxies messages over UDP to localhost ports 5551 (incoming messages) and 5552 (outgoing messages).

Listen to UDP messages with socat:

# Listen to incoming UART messages
socat -u udp-recv:5551 -
# Listen to outgoing UART messages
socat -u udp-recv:5552 -

Issues, support and contributing

License: Apache v2.0 - see license.txt.

See CONTRIBUTING.md for guidelines on submitting issues and PRs.

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

oatmeal-1.1.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

oatmeal-1.1-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file oatmeal-1.1.tar.gz.

File metadata

  • Download URL: oatmeal-1.1.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for oatmeal-1.1.tar.gz
Algorithm Hash digest
SHA256 5fa2b2b500af4ecb85cf76862b0c973d0be652016a0a67d0436aecebd8e8a773
MD5 e07540b589a050efd3c0abd335338feb
BLAKE2b-256 cb4d565de64e5c41be3a804f604442d03bc98ec54b69c5b70a7f60ebe42e7aeb

See more details on using hashes here.

File details

Details for the file oatmeal-1.1-py3-none-any.whl.

File metadata

  • Download URL: oatmeal-1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for oatmeal-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d32ee27afa50033fbd881f2512b6c206e5b6903fa45747c1b2c4dc748668cbd
MD5 5ce92a3fac3624cd14eaa80d291a8e00
BLAKE2b-256 8df53eb916842d816027d47a2467096d92c1a47e0a095b924cfc12b81d2eedde

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