micropython-osc (uosc) - a minimal Open Sound Control (OSC) client and server library for (Micro)Python

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

micropython-osc (uosc) - a minimal Open Sound Control (OSC) client and server library for (Micro)Python

Post by SpotlightKid » Sun Sep 04, 2016 10:54 pm

Micropython-OSC

Micropython-osc (aka uosc) is a minimal Open Sound Control (OSC) client and server library for MicroPython and CPython 2 or 3.

https://github.com/SpotlightKid/micropython-osc


Status / Supported Boards

It should work on the Unix, stmhal (Pyboard) and esp8266 port of MicroPython and under CPython 2.7 and 3.3+. Since OSC is a network-protocol using UDP or TCP as a transport, the main requirement is a working and compatible socket module. Currently this module only supports UDP as the transport.

The server code so far has only been tested under the Unix port and CPython 2 and 3, but the client portion has been confirmed to work on a ESP-8266 board running MicroPython 1.8.x.

(NB: I've been sitting on this code for rather a while now and have tested it quite thoroughly under the unix port and CPython, but until recently I didn't have a MicroPython board with a network device to test it with. Today I took some time to try it out on a ESP-8266 board, added some workarounds for a few library incompatibilities and are now happy to report that the client seems to work quite well.)

Usage

Here's a minmal usage example for the client. Further documentation is currently only available by looking at the docstrings and the source code (the whole package has a total LLOC of < 400).

Code: Select all

from uosc.client import Bundle, Client, create_message

osc = Client('192.168.4.2', 9001)
osc.send('/controls/frobnicator', 42, 3.1419, "spamm")
b = Bundle()
b.add(create_message("/foo", bar))
b.add(create_message("/spamm", 12345))
osc.send(b)

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: micropython-osc (uosc) - a minimal Open Sound Control (OSC) client and server library for (Micro)Python

Post by SpotlightKid » Tue Sep 06, 2016 8:34 am

Here's another, slightly more real-world example of using the client from this library:

https://github.com/SpotlightKid/micropy ... cclient.py

This makes use of my encoder library to read a rotary encoder attached to an ESP-866 board and sends the values read from the encoder as OSC-encapsulated MIDI messages. To use the script, adapt the IP address in the script file and copy the needed parts of the uosc package and the script to your esp8622, for example with ampy:

Code: Select all

ampy -p /dev/ttyUSB0 mkdir uosc
ampy -p /dev/ttyUSB0 put uosc/client.py uosc/client.py
ampy -p /dev/ttyUSB0 put uosc/common.py uosc/common.py
ampy -p /dev/ttyUSB0 put examples/esp_oscclient.py
Then in your "main.py" connect to your WiFi network and import the script's main function and run it.

Code: Select all

# connect to wifi here...
from enc_oscclient import main
main()
As the OSC server you can use my fork of the touchosc2midi program (use the "generickeys" branch and run the program with the "-c" option) to translate the incoming OSC messages into MIDI control change messages. Now you have a wireless physical MIDI controller!

Post Reply