Package: circuitpython-microosc
IntroductionMinimal OSC parser, server, and client for CircuitPython and CPythonOpen Sound Controlis an efficient data transport
encoding/protocol for real-time performance messages for music or other similar endeavors.
The OSC byte encoding is designed to be semi-human readable and efficient enough for
UDP packet transmission.OSC Messages are defined by an “OSC Address” (e.g. “/1/faderA”) and optional “OSC Arguments”,
one or more possible of several data types (e.g. float32 or int32). OSC doesn’t pre-define
specific OSC Addresses, it is up the the sender and receiver to agree upon them.This “MicroOSC” library is a minimal UDP receiver (“OSC Server”) and parser of OSC packets.
The MicroOSC UDP receiver supports both unicast and multicast UDP on both CircuitPython and CPython.RequirementsTo run this library you will need one of:CircuitPython board with nativewifisupport, like those based on ESP32-S2, ESP32-S3, etc.Desktop Python (CPython) computerTo send OSC messages, you will need an OSC UDP sender (aka “OSC client”).
Some easy-to-use OSC clients are:TouchOSCOSCSend for Ableton LiveTo receive OSC messages, you will need an OSC UDP receiver (aka “OSC server”).
Some easy-to-use OSC clients are:Protokol for Mac/Win/Linux/iOS/AndroidDependenciesThis driver depends on:Adafruit CircuitPythonPlease ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloadingthe Adafruit library and driver bundleor individual libraries can be installed usingcircup.Installing from PyPIOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locallyfrom
PyPI.
To install for current user:pip3installcircuitpython-microoscTo install system-wide (this may be required in some cases):sudopip3installcircuitpython-microoscTo install in a virtual environment in your current project:mkdirproject-name&&cdproject-namepython3-mvenv.venvsource.env/bin/activatepip3installcircuitpython-microoscInstalling to a Connected CircuitPython Device with CircupMake sure that you havecircupinstalled in your Python environment.
Install it with the following command if necessary:pip3installcircupWithcircupinstalled and your CircuitPython device connected use the
following command to install:circupinstallmicrooscOr the following command to update an existing version:circupupdateUsage Exampleimporttime,os,wifi,socketpoolimportmicrooscUDP_HOST="224.0.0.1"# multicast UDPUDP_PORT=5000ssid=os.getenv("CIRCUITPY_WIFI_SSID")password=os.getenv("CIRCUITPY_WIFI_PASSWORD")print("connecting to WiFi",ssid)wifi.radio.connect(ssid,password)socket_pool=socketpool.SocketPool(wifi.radio)deffader_handler(msg):"""Used to handle 'fader' OscMsgs, printing it as a '*' text progress bar
   :param OscMsg msg: message with one required float32 value
   """print(msg.addr,"*"*int(20*msg.args[0]))# make a little bar chartdispatch_map={"/":lambdamsg:print("\t\tmsg:",msg.addr,msg.args),# prints all messages"/1/fader":fader_handler,"/filter1":fader_handler,}osc_server=micro_osc.Server(socket_pool,UDP_HOST,UDP_PORT,dispatch_map)print("MicroOSC server started on ",UDP_HOST,UDP_PORT)last_time=time.monotonic()whileTrue:osc_server.poll()iftime.monotonic()-last_time>1.0:last_time=time.monotonic()print(f"waiting{last_time:.2f}")ReferencesOpen Sound Control Spec 1.0OSC Message examplesOSC info and toolsTouchOSC apps for Mac/Win/LinuxDocumentationAPI documentation for this library can be found onRead the Docs.For information on building library documentation, please check outthis guide.ContributingContributions are welcome! Please read ourCode of Conductbefore contributing to help this project stay welcoming.