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.
Metadata
Release files for oatmeal 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oatmeal-1.1.tar.gz | 23.5 kB | Without provenance | Details for oatmeal-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oatmeal-1.1-py3-none-any.whl | Python 3 | none | any | Details for oatmeal-1.1-py3-none-any.whl |
Total release size: 50.3 kB
Release files / oatmeal-1.1.tar.gz
| Download URL | oatmeal-1.1.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5fa2b2b500af4ecb85cf76862b0c973d0be652016a0a67d0436aecebd8e8a773
|
|
BLAKE2b-256 checksum How to use checksums |
cb4d565de64e5c41be3a804f604442d03bc98ec54b69c5b70a7f60ebe42e7aeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / oatmeal-1.1-py3-none-any.whl
| Download URL | oatmeal-1.1-py3-none-any.whl |
|---|---|
| Size | 26.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d32ee27afa50033fbd881f2512b6c206e5b6903fa45747c1b2c4dc748668cbd
|
|
BLAKE2b-256 checksum How to use checksums |
8df53eb916842d816027d47a2467096d92c1a47e0a095b924cfc12b81d2eedde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for oatmeal 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.