Skip to main content

Python client for an Arduino RPC bridge using MsgPack over serial.

Project description

pyrpc

A tiny RPC bridge between Arduino and Python using MsgPack over serial.

It lets you expose C++ functions on an Arduino board and call them directly from Python, with automatic (de)serialization of basic types, containers, and structs.

Arduino side

  1. Install the Arduino MsgPack library (e.g. via Library Manager).
  2. Include the RPC header and register your functions:
#include <pyrpc.h>

double sum(int i, float d) {
	return i + d;
}

void setup() {
	Serial.begin(115200);

	pyrpc::begin();  

	pyrpc::register_rpc(
		"sum",
		sum,
		F("@brief sum two numbers @return double @arg i integer @arg d float")
	);
}

void loop() {
	pyrpc::process();  // handle incoming RPC calls
}

Upload this sketch to your Arduino (baudrate must match the Python side).

Python side

Install the Python package:

pip install pyrpc

Call your Arduino procedures from Python:

from pyrpc import Rpc

rpc = Rpc("/dev/ttyACM0", baudrate=115200)

print(rpc.help)  # shows all available remote procedures

result = rpc.call("sum", 3, 1.5)
print("sum result:", result)

rpc.close()

A more complete example is available in the examples/ folder.

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

ardupyrpc-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ardupyrpc-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file ardupyrpc-0.1.0.tar.gz.

File metadata

  • Download URL: ardupyrpc-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for ardupyrpc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc5018d051d4d49b92b341c59fce5c895d4672d6d6e88ec3c10de5022a0c682a
MD5 e6fb811b5dbabd8890b845f8e83de054
BLAKE2b-256 ad9edb67de8bc1953d4f42c5f10974785e6c4f9d208a5df187d2b78a3f193c3e

See more details on using hashes here.

File details

Details for the file ardupyrpc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ardupyrpc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for ardupyrpc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8ba79fcad492b5df4bd1766d49287f79da1f9873595f47a9f1b4887ec834973
MD5 ab20c009fd1f566faa05f65fddfa7d2f
BLAKE2b-256 dae42ad31a3c2666cec2ec8da949e1d84d1be8f45f8e07ff2593cfd41d857699

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page