From e87a4a291b22376b8f968f8229f23c69fe3c92a6 Mon Sep 17 00:00:00 2001 From: zolliker Date: Fri, 16 May 2025 10:19:06 +0200 Subject: [PATCH] Update README.md --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/README.md b/README.md index e69de29..510904c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,70 @@ +pxsi: parameter update over serial interface +============================================ + +Markus Zolliker (markus.zolliker@psi.ch) + +helper library for micropython on RP2040 (e.g. Arduino Nano Connect or Paspberry Pico) + +Code example +------------ + + from pxsi import Pxsi + + # declare variables visibile over serial + + vars = Pxsi('MyBox', # idn will be: pxsi,MyBox + t = 5, + a = 2, + ) + + # create action functions for some of the variables + + def change_t(value): + # write here what to do when t changes + + # your real code + + print(t) # the given variables are now available in the main namesapce + + while True: + # handle IO, wait at most 0.5 secs + vars.handle_io(0.5) + # read out sensors, do control logic here + # important: do not sleep here! + + +Serial protocol +--------------- + +Commands: + + name # get value of variable name + name=value # change value (value must be a valid JSON value) + ["name1", ["name2", value]] # multiple commands: query name1, change name2. must be a valid JSON array + {"name1": null, "name2": value} # alternative form - be aware that order is not guaranteed + +Special command for identification + + *IDN? + +returns: + + pxsi, + + +For all other commands the reply is always a JSON object: + + {"name1": value1, "name2", value2} + +In case of an error, the result contains an item with the key "_error_" and a JSON array as value, +listing the errors appeared. + + +Hints for Arduino Nano Connect +------------------------------ + +For a soft reset send '\x03\x04' (Ctrl-C Ctrl-D). +The reply will be quite some text, with the last line: + + pxsi: +