Raspberry Pi: Serial data to RNBO (OSC)

OoA's icon

Hello RNBO people!

I am trying to send the serial data of an RPi4 to the RNBO patch through OSC, following this tutorial (I am reading a few sensors with Arduino and then sending them to the serial port).

Here is my script:

import liblo as OSC
import sys
import serial

# send all messages to port 1234 on the local machine
try:
    target = OSC.Address(1234)
except OSC.AddressError as err:
    print(err)    
    sys.exit()

# start the transport via OSC
OSC.send (target, "/rnbo/jack/transport/rolling", 1)

# read the serial port and flush it
ser = serial.Serial('dev/ttyACM0', 9600)
ser.flushInput()

while True:
    raw = ser.readline()
    data = raw.decode('utf-8')
    print(data)
    OSC.send (target, "/rnbo/inst/0/params/name", data)

What is wrong/missing?

If I use the Commandline method it works:

oscsend osc.udp://c74rpi.local:1234 /rnbo/inst/0/params/name value

But I can't figure out how to send the serial data.

Thanks for any help/tips,

Gabriele

Alex Norman's icon

Does the 'transport/rolling' 1 message work?

I wonder what the type of your 'data' variable is? maybe you need to convert it to a floating point number?

OoA's icon

Yes, transport/rolling works (I checked with rnbo.remote) so - thanks for the heads up - the issue is definitely in the type of data I am trying to send (which is for sure not integers/float).

What I am getting from Arduino is:

b'value1, value2, etc\r\n' >(I put the comma from the IDE thinking might be useful to split the numbers later on)

I managed to clean it and get a list like this:

['value1', 'value2', etc]

But, I am still struggling to transform it into actual integers to be sent to an RNBO unpack.

Any tips is helpful as I am totally new to Python and everything takes ages to figure out.

Many thanks,

Gabriele

Jan M's icon

You are receiving byte values from the serial port, which is to be expected. The best approach is probably normalizing the values yo a (float) range of 0. to 1. and use the normalized OSC path to send them to RNBO. This way you don’t need to take care of the different parameter ranges.