reflect_cut
Posts: 21
Joined: Fri Apr 13, 2018 2:04 pm

6050 to PureData communication on RBP3

Fri Apr 13, 2018 2:13 pm

Hello all,
I'm working on a simple project using a Raspberry Pi 3, a MPU6050 sensor and the open source music program Pure Data.
I want the changing data of the sensor to trigger 'samples' within Pure Data.

So far I have installed the library for the sensor as well as Pure data, I'm using python scripts from tutorials which work fine to show me the constant stream of data from the sensor within shell.

My question is, how do I "export" this data so it can be received within Pure Data.
Pure data can receive OSC protocol and UDP, does someone know how to "easily" set up an OSC server so the data can be transmitted? Or might there be a simpler way without having to use the network? I was advised to take a look at the WiringPi library but haven't figured out how to make use of it...

Thank you all in advance,

reflect_cut
Posts: 21
Joined: Fri Apr 13, 2018 2:04 pm

Re: 6050 to PureData communication on RBP3

Sat Apr 14, 2018 8:38 am

Also I found out about pyOSC which should make it possible to create an OSC server to transmit the data, but I don't know how to do that.
any thoughts would be greatly appreciated,

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: 6050 to PureData communication on RBP3

Sat Apr 14, 2018 9:02 am

see some old tutorial for this sensor and python
https://www.sunfounder.com/learn/sensor ... -plus.html
https://github.com/sunfounder/SunFounde ... mpu6050.py
and see ?python to PD?
http://puredata.info/Members/thomas/py/

but i never used PD, only python to sonic pi
with this code i would love to test that sensor.

now on a window ( clicked by mouse ) i have 2 axis : left to right NOTE, up to down AMP
with your sensor you have 3 axis? what you want to do with it?

reflect_cut
Posts: 21
Joined: Fri Apr 13, 2018 2:04 pm

Re: 6050 to PureData communication on RBP3

Sun Apr 15, 2018 9:47 am

Thank you for the reply,

I am currently already using the code from the second tutorial you linked me:
(https://github.com/sunfounder/SunFounde ... mpu6050.py)
to get data from the sensor, which then appears in the shell.

I would like to receive that data in pd (pure data) and use it (after appropriate scaling) to trigger different audio samples (when the gyroscope overcomes a certain threshold the sample should skip to the next)

would any "export" code be added to the python script I am already using or would this be a second, separate script?

http://puredata.info/Members/thomas/py/ seems like something useful but there should be an easier way just for sensor data, maybe something using the netreceive and netsend objects (see screenshot), the wiringPi library or rpi_GPIO...

I will continue my research for tutorials and code but any thoughts on this would be greatly appreciated ...am a complete noob at linux/python :roll:
Attachments
Screen Shot 2018-04-14 at 14.13.03.png
Screen Shot 2018-04-14 at 14.13.03.png (31.68 KiB) Viewed 733 times

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: 6050 to PureData communication on RBP3

Sun Apr 15, 2018 12:26 pm

reflect_cut wrote:
Sat Apr 14, 2018 8:38 am
Also I found out about pyOSC which should make it possible to create an OSC server to transmit the data, but I don't know how to do that.
any thoughts would be greatly appreciated,
the pyOSC seems to be 10 years old ( not maintained ),
but here at forum find many links
or why not just try it.

the
pip3 install python-osc (about 1 year ago updated )
what i use to talk from python3 to Sonic Pi

Code: Select all

from pythonosc import osc_message_builder
from pythonosc import udp_client

sender = udp_client.SimpleUDPClient('127.0.0.1', 4559)

sender.send_message('/play_this', [note, amp, cutoff, sustain])
______________ and here the sonic pi (3.0.1) part:

Code: Select all

# Welcome to Sonic Pi v3.0.1
live_loop :RPI_theremin do
  use_real_time
  a, b, c, d = sync "/osc/play_this"
  synth :supersaw, note: a, amp: b, cutoff: c, sustain: d
end
# and press [RUN]


______________________________________________________________
for PD?
possibly learn https://guitarextended.wordpress.com/20 ... pberry-pi/

reflect_cut
Posts: 21
Joined: Fri Apr 13, 2018 2:04 pm

Re: 6050 to PureData communication on RBP3

Sun Apr 15, 2018 6:06 pm

that looks promising, would i put the OSC script into the mpu6050 script or run it as a separate one?
thanks again, im ok with glueing stuff together just not good at writing code myself ...

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: 6050 to PureData communication on RBP3

Mon Apr 16, 2018 1:00 pm

it is not only promising, its working
my old python script send UDP, ( read by Sonic Pi )
also can be read by PD
Image
but there is some add terrible sound... / i don't know that tool at all / install today /
and just put in the basic flow to rip appart UDP..
( use NOTE and AMP only -> so while Sonic Pi plays single notes ( on each click ) this here queeks constant... )
sorry, my input is still mouse click over pygame window ( not changed that python code)
/ so no fancy sensor hardware /
Image
there might be a much more easy way / data structure / but as Sonic Pi is installed per default
i think its good that the python code stays "compatible"

Return to “Beginners”