# Coding help and SonicPi experiences needed

**URL:** <https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834>\
**Category:** Support, Help & Resources\
**Created:** [May 14, 2020, 9:59pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834 "2020-05-14T21:59:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 14, 2020, 9:59pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/1 "2020-05-14T21:59:14Z")

</div>

Hi,

I know this is not actually for this board. But I’m hoping one of you had already tried a similar thing and maybe want to share how they achieved it.

I’m not at all a very good programmer a more technical guy. But I’m still trying this because I want to finish something that at least works.  
Soo any help is very appreciated.

Info: I have got a working tool to find data (numbers) and pull it to my terminal in node.js. The program checks every 10 min for a new pull.  
I want to use the pulled numbers and divide them with 540. So for example the pull gave me x / 540 = y.  
The following last step is to send an osc message a simple (bang in maxmsp terms) alert to sonic pi for every second y is.

But I’m unable to first get it wrapped up in my head how to exactly do that. I know I should use setinterval.

Secondly and most important. I can’t seem to install npm i osc in to raspberry pi.

Any body who got this to work?? Because this is needed to communicate with Sonic Pi which is my eandgoal in this project.

All help is really welcome!!!

Kind regards,

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [May 15, 2020, 8:36am UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/2 "2020-05-15T08:36:03Z")

</div>

hi

well what’s your problem ? 🙂

how to use osc with npm via the `osc` npm package ? which version of raspberry pi ? which os on it ?  
could you draw a scheme of your installation ? Which machine ? wich role ? which softwares ? what do you want ? Max send to \*\*\*\*\* ? sonic pi receives from ???

maybe then we could help you… not sure 😉

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 15, 2020, 3:11pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/3 "2020-05-15T15:11:53Z")

</div>

@nlb ok I’ll try to explain it as good as possible bear with me 😃

Version Raspberry Pi :

> Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux

> Buster latest

I can’t install the node js osc package on this raspberry pi without getting loads of errors.

I want to send a message from a js script to sonic pi. The message should just be a “signal” (I’ve compared it with a bang like in max msp) when this osc message is received in Sonic Pi I would translate it to run a sound in an array to a speaker.  
The last part is no problem. But I can’t get the signal to be send to sonic pi from the js script.

The whole process would run from one single pi. The osc message would be send internally thus.

I hope it’s a bit clearder 😃

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [May 15, 2020, 3:19pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/4 "2020-05-15T15:19:27Z")

</div>

@dewildequinten what version of Sonic Pi are you using?

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 15, 2020, 3:38pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/5 "2020-05-15T15:38:13Z")

</div>

latest 3.1.0 it is. Do you think is a version issue?

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [May 15, 2020, 3:45pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/6 "2020-05-15T15:45:18Z")

</div>

In that case, yes, quite likely. (At least as far as Sonic Pi itself is concerned). The version that came with the Pi is incomplete, as it was a build created externally, outside of Sam’s control. (OSC and MIDI do not work).  
The latest official version of Sonic Pi is 3.2.2 - @robin.newman has kindly created a Raspberry Pi package for this: [http://r.newman.ch/rpi/sonic-pi-3.2.2/](http://r.newman.ch/rpi/sonic-pi-3.2.2/) (it will only work on Raspbian Buster).  
Give that a go, and hopefully it works for you 🙂

Once that’s working, it’s just a matter of getting the javascript set up.

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [May 15, 2020, 3:48pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/7 "2020-05-15T15:48:37Z")

</div>

> [@dewildequinten](#):
>
> I can’t install the node js osc package on this raspberry pi without getting loads of errors.

well first find a solution for this no ? [osc - npm](https://www.npmjs.com/package/osc)  
and ask [Issues · colinbdclark/osc.js · GitHub](https://github.com/colinbdclark/osc.js/issues)

Edit : oups you did it 🙂 Sorry

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 15, 2020, 9:16pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/8 "2020-05-15T21:16:57Z")

</div>

Yes I did,

But I reinstalled everything and know the package is in my node-modules.

So I thought just try the example and see if that works. When importing the library with node and running it, it gave me no errors. But then I tried the example code and got following error:

code:

```
var osc = require("osc");

var udpPort = new osc.UDPPort({
    // This is the port we're listening on.
    localAddress: "127.0.0.1",
    localPort: 57121,

    // This is where sclang is listening for OSC messages.
    remoteAddress: "127.0.0.1",
    remotePort: 57120,
    metadata: true
});

// Open the socket.
udpPort.open();

// Every second, send an OSC message to SuperCollider
setInterval(function() {
    var msg = {
        address: "/hello/from/oscjs",
        args: [
            {
                type: "f",
                value: Math.random()
            },
            {
                type: "f",
                value: Math.random()
            }
        ]
    };

    console.log("Sending message", msg.address, msg.args, "to", udpPort.options.remoteAddress + ":" + udpPort.options.remotePort);
    udpPort.send(msg);
}, 1000);

```

error:

```ruby
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: bind EADDRINUSE 192.168.1.23:4559
    at dgram.js:337:20
    at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on instance at:
    at Socket.<anonymous> (/home/pi/Tools-for-Instagram/node_modules/osc/src/platforms/osc-node.js:79:18)
    at Socket.emit (events.js:327:22)
    at dgram.js:339:14
    at processTicksAndRejections (internal/process/task_queues.js:85:21) {
  errno: -98,
  code: 'EADDRINUSE',
  syscall: 'bind',
  address: '192.168.1.23',
  port: 4559

```

---

<div class="post-metadata">

**Author:** ![lenz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/lenz/32/1391_2.png) [@lenz](https://in-thread.sonic-pi.net/u/lenz)\
**Post date:** [May 16, 2020, 5:38am UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/9 "2020-05-16T05:38:19Z")

</div>

Not sure what you are trying to do here, but I can definitely help with the error - it says that it cannot listen on port 4559 **because** there is something else attached to it.  
If you want to know what that is, just run a `lsof -i -P | grep 4559` as `root`.

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 16, 2020, 9:18am UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/10 "2020-05-16T09:18:57Z")

</div>

> [@lenz](#):
>
> lsof -i -P | grep 4559

this is the response

ruby 3341 pi 18u IPv4 83410 0t0 UDP \*:4559

But no idea wha this could be. Something from ruby??

UPDATE:

I restarted the whole machine and run it again.

Sending message /osc/trigger/prophet [  
{ type: ‘f’, value: 0.8651540092898522 },  
{ type: ‘f’, value: 0.5801701552646872 }  
] to 127.0.0.1:4559  
Sending message /osc/trigger/prophet [  
{ type: ‘f’, value: 0.16566471922413717 },  
{ type: ‘f’, value: 0.7892016716765036 }  
] to 127.0.0.1:4559  
Sending message /osc/trigger/prophet [  
{ type: ‘f’, value: 0.8855032933937974 },  
{ type: ‘f’, value: 0.3654368469507743 }  
] to 127.0.0.1:4559

Is the output so that works

But there’s nothing coming in on the sonic pi on the same device…

I’ve changed the ip adress to the rpi ip but no difference.

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [May 16, 2020, 10:40am UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/11 "2020-05-16T10:40:40Z")

</div>

> [@dewildequinten](#):
>
> ruby 3341 pi 18u IPv4 83410 0t0 UDP \*:4559

well imo it’s sonic pi 🙂

we want a scheme of your set up to help you ! we want a scheme of your set up to help you  
🙂

Have you installed the 3.2.2 version of sonic pi ?

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 16, 2020, 10:53am UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/12 "2020-05-16T10:53:30Z")

</div>

How exactly do I install this version on RPi3 ?  
I only found the update but that brought me to 3.1.0

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [May 16, 2020, 11:02am UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/13 "2020-05-16T11:02:15Z")

</div>

have a look above 🙂

> [@Coding help and SonicPi experiences needed](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/6):
>
> In that case, yes, quite likely. (At least as far as Sonic Pi itself is concerned). The version that came with the Pi is incomplete, as it was a build created externally, outside of Sam’s control. (OSC and MIDI do not work). The latest official version of Sonic Pi is 3.2.2 - @robin.newman has kindly created a Raspberry Pi package for this: [http://r.newman.ch/rpi/sonic-pi-3.2.2/](http://r.newman.ch/rpi/sonic-pi-3.2.2/) (it will only work on Raspbian Buster). Give that a go, and hopefully it works for you slight_smile Once that’s wo…

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 16, 2020, 12:31pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/14 "2020-05-16T12:31:48Z")

</div>

> [@dewildequinten](#):
>
> ```ruby
> var osc = require("osc");
> 
> var udpPort = new osc.UDPPort({
> // This is the port we're listening on.
> localAddress: "127.0.0.1",
> localPort: 57121,
> 
> // This is where sclang is listening for OSC messages.
> remoteAddress: "127.0.0.1",
> remotePort: 57120,
> metadata: true
> });
> 
> // Open the socket.
> udpPort.open();
> 
> // Every second, send an OSC message to SuperCollider
> setInterval(function() {
> var msg = {
> address: "/hello/from/oscjs",
> args: [
> {
> type: "f",
> value: Math.random()
> },
> {
> type: "f",
> value: Math.random()
> }
> ]
> };
> 
> console.log("Sending message", msg.address, msg.args, "to", udpPort.options.remoteAddress + ":" + udpPort.options.remotePort);
> udpPort.send(msg);
> }, 1000);
> 
> ```

Whoops missed that one! Successfully installed it but nothing happens.

Weird thing is that I can’t change anything about the arguments or the code breaks. If I change the f type it breaks if I change the value to whatever it also breaks.

Is there a better osc javascript package 😛 ?? 😃

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [May 16, 2020, 1:02pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/15 "2020-05-16T13:02:18Z")

</div>

what about a sketch to understand your setup ? 🙂  
would you put your code into a public repo ? maybe someone can test it ?

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 16, 2020, 1:28pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/16 "2020-05-16T13:28:00Z")

</div>

Sure it is totally open for me 🙂

The repo is Tools-for-Instagram. I installed the osc.js correctly because it shows up in my node-modules in the Tools-for-Instgram.

> **[linkfy/Tools-for-Instagram](https://github.com/linkfy/Tools-for-Instagram)**
>
> Automation scripts for Instagram. Contribute to linkfy/Tools-for-Instagram development by creating an account on GitHub.

But at the moment I just ran the osc.js example from the osc.js repo the (supercollider example!))

> **[colinbdclark/osc.js-examples](https://github.com/colinbdclark/osc.js-examples)**
>
> Sample code illustrating how to use osc.js in a variety of scenarios. - colinbdclark/osc.js-examples

And put those files in the tools-for-instagram folder.  
I wanted to test the osc.js code first before trying to merge two scripts together.

I’ll upload the folder of mine to my GitHub if it’s necessary. I’ll have to figure that one out then to but let me know!

Did it anyways

> **[quintendewilde/Tools-for-IAC](https://github.com/quintendewilde/Tools-for-IAC)**
>
> Tools for instagram for automation collective. Contribute to quintendewilde/Tools-for-IAC development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [May 16, 2020, 1:46pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/17 "2020-05-16T13:46:04Z")

</div>

Also, when you have installed 3.2.2 from my site, you want to send OSC messages to port 4560 which is now used by recent SonicPI version not 4559.

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 16, 2020, 1:51pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/18 "2020-05-16T13:51:11Z")

</div>

@robin.newman Thanks! wonderful job again with the update!

I changed it but nothing changed…

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [May 16, 2020, 1:54pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/19 "2020-05-16T13:54:47Z")

</div>

OK I’ve not looked at your code in detail, but I’m not sure where your 4559 port is coming from, as you shouldnt be using that with Sonic Pi 3.2.2

---

<div class="post-metadata">

**Author:** ![dewildequinten](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dewildequinten](https://in-thread.sonic-pi.net/u/dewildequinten)\
**Post date:** [May 16, 2020, 2:09pm UTC](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834/20 "2020-05-16T14:09:25Z")

</div>

If you are reffering to the code in the thread, that’s already adjust by the advice of @nlb.

The repo I posted shows the complete setup and code currently using.  
It’s under bots/osc.js

> **[quintendewilde/Tools-for-IAC](https://github.com/quintendewilde/Tools-for-IAC)**
>
> Tools for instagram for automation collective. Contribute to quintendewilde/Tools-for-IAC development by creating an account on GitHub.

Kind regards!

[Next page](https://in-thread.sonic-pi.net/t/coding-help-and-sonicpi-experiences-needed/3834.md?page=2)
