Ultra Sonic Theremin on Raspberry pi 4

I am making an ultrasonic theremin using sonic pi and thonny(python). It does detect the distance, and the sonic pi’s live loop does work, but the sonic pi wont receive any information from the python code detecting the distance.
Sonic Pi code:
live_loop :listen do
m = sync “/osc*/play_this”
note = m[0]
play note

Python code:
from gpiozero import DistanceSensor
from time import sleep

from pythonosc import osc_message_builder
from pythonosc import udp_client

sensor = DistanceSensor(echo=18, trigger=17)
sender = udp_client.SimpleUDPClient(‘’, 4560)

while True:
pitch = (sensor.distance * 100 + 30)
sender.send_message(’/play_this_p’, pitch)

Which version of sonic pi are you using?
What happens if you replace the play note with puts more?
Do you see incoming OSC cues in the cues log?

At least going by the code that you have shared above, there is a difference between the addresses that you are sending messages to and receiving messages from:

m = sync “/osc*/play_this”


sender.send_message(’/play_this_p’, pitch)

I am using sonic pi 3.3.1 and I can’t see any cues in the cues log. I only have access to the programs during class, so I will try your suggestion as soon as I can.

Thank you, I will fix this when I next have CS class(when I can next access my raspberry pi).

I have corrected the error, and tried puts more instead of play note. Neither have made the programs work as wished. There is nothing showing up in the cues, so I think that either the python code is not sending the information or that Sonic Pi isn’t open to receiving information.

By ‘puts more’, it’s possible Robin meant ‘puts note’ to see what the value of ‘note’ was :slight_smile:

You can check whether the OSC networking feature is enabled by looking at the IO tab of the preferences panel, (or IO menu in the main menu) and seeing whether ‘Allow incoming OSC’ is checked.

If it is checked, then assuming you are in fact sending and receiving to/from the same address, (which would be easier to see if you’re able to share your code again), there might be a networking problem, such as a firewall blocking a port. If that were the case, it would be helpful for us to see your log files, in your home directory, in .sonic-pi/log.