Whilst the upgrade to 3.2.2 allowed me to get ‘AV’ (ass opposed to HDMI) audio out of my Pi2 when playing the various samples included with the program my attempts to get output from the theremin project:
have hit stony ground.
I am sure I must be missing an Elephant somewhere but as I am a beginner with Python and SonicPi, I know not where he lurks.
The cue screen in Sonic Pi tells me the Python script appears to be sending values to SonicPi.
I note that there are a couple of “no echo received” messages. I noticed similar “no echo received” when I ran the script with the values being printed in Python - it looked like there were just one glitches; the data kept coming through after the error appeared.
Hopefully the image below will give the info needed for someone to tell me where my Pachyderm lurks
PS: I have just come across robin.newman’s dual Theremin Project AND his “Time of Flight” sensor version. I am tempted to give these a try but first, I think, get this one to work.
@SteveS I may be wrong but it’s possible the OSC syntax is out of date.
Try changing the sync command in Sonic Pi to this:
message = sync "/osc*/play_this"
(Though if the problem is on the sensor end, I have no idea sorry!)
Thank you for responding. Sadly that change has not worked.
From what my novice eye can make out, there’s something adrift in Sonic Pi. I can see the data arriving (as midi/pitch values?) in the Cues window but there is nothing happening in the log or indeed, in the scope, when I turn it on.
I am beginning to wonder if this has something to do with changes made in the latest version (3.2.2).
What does /osc:127.0.0.1:45401/play_this mean?
And is there a clue in the attached error log I got on just the one occasion when launching Sonic Pi? This popped up a while back, I put it down to memory issues, at the moment I am doing this on a Pi2B - I have launched Sonic Pi many times since on the same Pi without the error re-occurring.
Where can I find this start-up log on the Pi? I assume it is created at each ‘launch’.
(I think I have just answered this one by reading -
/home/pi/.sonic-pi/log/gui.log in the error log print out)
live_loop :listen do
m = sync "/osc*/play_this"
note = m
The initial code is a bit out of date syntax wise.
I’ll give that a go later.
Assuming I succeed with this basic Theremin I plan to move on to the other two Theremin Projects you have posted on your Wordpress blog: Dual sensor then Time of Flight.
Will these also “suffer” from out of date syntax and other issues relating to Sonic Pi versions, along with OS and Platform?
I am using a Pi2B running the lite version of the latest RaspiOS. (and a freshly installed version of Sonic Pi 3.2.2).
I would likely move on to a Pi4 for these next, bigger, projects (and maybe use the full OS)
In the published programs on the wordpress article you will have to replace all
/osc/ withing the Sonic Pi programs with
/osc*/ to allow for the new syntax. Also in the pytion script change the sonic pi port used from 4559 to 4560 Otherwise I think it should be OK. I’ll try and test it again myself in the near future but I don’t have it set up at present.
ADDITION. I tried the project running again on a Pi4 with latest Raspbian OS. There is one further change required. the python library downloaded from Pimoroni has been updated to version 0.0.5
If you use my python script, ti will only update the range figure infrequently, althouhg it will work. In order to get a more rapid response, you need to add the line.
tof.set_timing(66000, 70) immediately before the line
For completeness the osctheremin.py python script is now:
#script to read vl53l1x sensor and send reading via OSC to Sonic pi
#written by Robin Newman August 2018 updated August 2020 for version 0.0.5 of library
#with thanks to Pimoroni's Phil Howard @Gadgetoid for the graph.py example
#on which I based some of this script.
from pythonosc import osc_message_builder
from pythonosc import udp_client
MAX_DISTANCE_MM = 800 # Set upper range
Open and start the VL53L1X ranging sensor
tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open() # Initialise the i2c bus and configure the sensor
tof.set_timing(66000,70) #This line is added from the original version to set refresh timings
tof.start_ranging(2) # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range (LINE UPDATED)
running = True
def exit_handler(signal, frame):
running = False
tof.stop_ranging() # Stop ranging
sender=udp_client.SimpleUDPClient(spip,4560) #port updated to 4560
distance_in_mm = tof.get_distance() # Grab the range in mm
distance_in_mm = min(MAX_DISTANCE_MM, distance_in_mm) # Cap at our MAX_DISTANCE
sys.stdout.write("\r") # Return the cursor to the beginning of the current line
sys.stdout.write ("range %3d " % (distance_in_mm))
sys.stdout.flush() # Flush the output buffer, since we're overdrawing the last line
parser = argparse.ArgumentParser()
default = "127.0.0.1", help="The ip of the Sonic Pi computer")
args = parser.parse_args()
print("Sonic Pi on ip",spip)
New software saved on gist site here
Very kind from you to take time to update your article. Sonic Pi community should appreciate your work !
Thanks a lot @robin.newman
Thank you. Much appreciated.
Just tried the updated
m = sync "/osc*/play_this"
note = m
Still no joy.
You are missing a / after the osc*
that line should read:
m = sync "/osc*/play_this"
(I edited your post with my moderator privileges to make it display the picture properly)
as far as the dual sesonr ultrasonic project is concerned you will need to update the port from 4559 to 4560 in the line:
sender = udp_client.SimpleUDPClient(spip,4559)
ie it becomes
sender = udp_client.SimpleUDPClient(spip,4560)
in the python script.
In the Sonic PI program you will have to update the line:
b = sync "/osc/play_this"
b = sync "/osc*/play_this"
With these two modifications the programs for the Dual Unltrasonic Sensors should work OK with sonic-pi 3.2.2
It never ceases to amaze me how long one - is it just me?- can look at a piece of writing, in this case code, comparing it with the correct version and still not see the missing item(s)
Thank you very much for your help.
And for updating the dual sensor code.
No I’ve been there too: got the badge
Good to know I am not alone!
Incidentally. What was wrong with the image I put up? You had to edit with your Moderator Privileges
It looks like the link was initially displayed as plain text:
(Probably due to the mismatch in the code fence back-ticks (```) - there needs to be one set of three on a line before and a line after the code snippet).
Hello, a little late to this discussion, not trying to hijack it or anything but just wanted to ask: do the modifications to outdated code referenced in this thread also apply to the super basic version of the ultrasonic theremin found here?:
I’m not ready for the dual theremin, pimoroni version yet, I’d be happy to get the breadboard/one sensor/buncha jumpers/intended for grade school age kids five years ago version to work on my Pi 4 if possible
Yes modifications are required if you are using anything later than Sonic Pi 3.0.1 for the early version of raspbian stretch.
You need to change the port in the python script from 4559 to 4560
sender = udp_client.SimpleUDPClient('127.0.0.1', 4559)
sender = udp_client.SimpleUDPClient('127.0.0.1', 4560)
and you need to change the receiving program on Sonic Pi from
note = sync "/osc/play_this" to
note = sync "/osc*/play_this"
Other than that, if you are using latest raspberry pi os you need to replace the sonic pi version 3.1 (which doesn’t support OSC calls) with version 3.2.2 downloadable from sonic-pi.net
Let me know if you have further problems with this and I’ll try to help.
Thank you Robin, it works!
Now to monkey with the code and make it listenable LOL