Csound Csound-dev Csound-tekno Search About

[Csnd] Arduino/Csound serial communication with multiple values

Date2014-09-16 14:07
FromSigurd Saue
Subject[Csnd] Arduino/Csound serial communication with multiple values
AttachmentsArduino_serial_recursive.csd  serial_recursive.ino  

In case anyone is interested:

The Arduino/Csound topic in the Floss manual shows how to receive the values of a single sensor from Arduino using the serial opcodes. The values are limited by the byte size (range 0 – 255). Iain McCurdy has promised an update with more sensors later, but in the meantime I’ll share my take on this.

The attached files show how to transfer a variety of sensor values, possibly with values larger then 255 (the typical analog range on the Arduino is 0 – 1023). The solution is similar to MIDI. You have to define an ID (a unique number >= 128) for every sensor. The sensor values are transmitted as ID, length (number of data bytes), and the data itself. The Csound code receives the values with the ID first. You should of course use the same IDs in the Csound code to identify the correct sensor.

The serial communication requires a pretty high ksmps. In this case I only transfer one sensor value at krate and toggles between them at each pass. I’m happy to receive suggestions on how to improve the code.

Sigurd


Date2014-09-16 14:48
Fromzappfinger
Subject[Csnd] Re: Arduino/Csound serial communication with multiple values
Very interesting, thanks.
I am specially interested on how this behaves on much higher baud rates...

I hink you could safely use a ksmps of 256:
Say the Arduino is set at 9600 baud, 8, N, 1, then each 'byte' is actually
10 bits
For 3 'bytes' (ID, val1, val2) this takes 30/9600 = 3.125 ms.
A ksmps of 256 takes 256/44100 = 5.8 ms, so you have enough time to process
the 3 bytes in that period...

Richard



--
View this message in context: http://csound.1045644.n5.nabble.com/Arduino-Csound-serial-communication-with-multiple-values-tp5737532p5737534.html
Sent from the Csound - General mailing list archive at Nabble.com.

Date2014-09-16 15:08
FromSigurd Saue
SubjectRE: [Csnd] Re: Arduino/Csound serial communication with multiple
First of all, the typical serial transaction will involve 5 bytes: One sent from Csound and four in return (id, length, val1, val2).

Still, there is something else going on: With a baud rate of 9600, ksmps=256 does not work. If I double the baud rate to 19200, ksmps=256 does work. However, not even with a baud rate of 115200 does ksmps=128 work. I don't know why.

Sigurd

-----Original Message-----
From: zappfinger [mailto:zappfinger@gmail.com] 
Sent: Tuesday, September 16, 2014 3:48 PM
To: csound@lists.bath.ac.uk
Subject: [Csnd] Re: Arduino/Csound serial communication with multiple values

Very interesting, thanks.
I am specially interested on how this behaves on much higher baud rates...

I hink you could safely use a ksmps of 256:
Say the Arduino is set at 9600 baud, 8, N, 1, then each 'byte' is actually
10 bits
For 3 'bytes' (ID, val1, val2) this takes 30/9600 = 3.125 ms.
A ksmps of 256 takes 256/44100 = 5.8 ms, so you have enough time to process the 3 bytes in that period...

Richard



--
View this message in context: http://csound.1045644.n5.nabble.com/Arduino-Csound-serial-communication-with-multiple-values-tp5737532p5737534.html
Sent from the Csound - General mailing list archive at Nabble.com.


Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"





Date2014-09-16 15:24
Fromzappfinger
Subject[Csnd] Re: Arduino/Csound serial communication with multiple
In my 'box' project (https://www.youtube.com/watch?v=zz12Mwo8Mwk) I use an
Arduino over Xbee at 38400 baud, but that goes via Processing.
Processing converts it to OSC that is then received by Csound.

Richard



--
View this message in context: http://csound.1045644.n5.nabble.com/Arduino-Csound-serial-communication-with-multiple-values-tp5737532p5737536.html
Sent from the Csound - General mailing list archive at Nabble.com.

Date2014-09-16 15:32
FromSigurd Saue
SubjectRE: [Csnd] Re: Arduino/Csound serial communication with multiple
Nice project. The clue is probably that there are two separate processes going on, which means that Csound is not delayed/interrupted by the slow serial communication. Iain McCurdy does suggest a bunch of other options, including Processing, Maxuino, Pduino or MIDI, but I just wanted to try to let Csound handle it all by itself.

Sigurd

-----Original Message-----
From: zappfinger [mailto:zappfinger@gmail.com] 
Sent: Tuesday, September 16, 2014 4:25 PM
To: csound@lists.bath.ac.uk
Subject: [Csnd] Re: Arduino/Csound serial communication with multiple

In my 'box' project (https://www.youtube.com/watch?v=zz12Mwo8Mwk) I use an Arduino over Xbee at 38400 baud, but that goes via Processing.
Processing converts it to OSC that is then received by Csound.

Richard



--
View this message in context: http://csound.1045644.n5.nabble.com/Arduino-Csound-serial-communication-with-multiple-values-tp5737532p5737536.html
Sent from the Csound - General mailing list archive at Nabble.com.


Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"





Date2014-09-16 15:43
Fromthorin kerr
SubjectRe: [Csnd] Arduino/Csound serial communication with multiple values
This looks nice, and very handy.
For what it's worth, I found I could get the full 1024 range on a pot by getting lowByte and highByte on the analogueRead.
i.e. 
      sensorValue = analogRead(A0);
      lobyte = lowByte(sensorValue);
      hibyte = highByte(sensorValue);

The high byte is in the range 0 - 3. So, it's easy enough to just multiply it by 256, then add the low byte value.

Thorin




On Tue, Sep 16, 2014 at 11:07 PM, Sigurd Saue <sigurd.saue@ntnu.no> wrote:

In case anyone is interested:

The Arduino/Csound topic in the Floss manual shows how to receive the values of a single sensor from Arduino using the serial opcodes. The values are limited by the byte size (range 0 – 255). Iain McCurdy has promised an update with more sensors later, but in the meantime I’ll share my take on this.

The attached files show how to transfer a variety of sensor values, possibly with values larger then 255 (the typical analog range on the Arduino is 0 – 1023). The solution is similar to MIDI. You have to define an ID (a unique number >= 128) for every sensor. The sensor values are transmitted as ID, length (number of data bytes), and the data itself. The Csound code receives the values with the ID first. You should of course use the same IDs in the Csound code to identify the correct sensor.

The serial communication requires a pretty high ksmps. In this case I only transfer one sensor value at krate and toggles between them at each pass. I’m happy to receive suggestions on how to improve the code.

Sigurd



Date2014-09-16 16:08
FromSigurd Saue
SubjectRE: [Csnd] Arduino/Csound serial communication with multiple values

That is basically what’s happening in the recursive Arduino functions (they could in principle handle any large integer). To ensure that the receiver can sync to the stream of bytes, only the ID can be >= 128 (as in MIDI). Consequently the data bytes can only use the 7 least significant bits (< 128).

 

Sigurd

 

From: thorin kerr [mailto:thorin.kerr@gmail.com]
Sent: Tuesday, September 16, 2014 4:44 PM
To: csound@lists.bath.ac.uk
Subject: Re: [Csnd] Arduino/Csound serial communication with multiple values

 

This looks nice, and very handy.

For what it's worth, I found I could get the full 1024 range on a pot by getting lowByte and highByte on the analogueRead.

i.e. 

      sensorValue = analogRead(A0);

      lobyte = lowByte(sensorValue);

      hibyte = highByte(sensorValue);

 

The high byte is in the range 0 - 3. So, it's easy enough to just multiply it by 256, then add the low byte value.

 

Thorin

 

 

 

 

On Tue, Sep 16, 2014 at 11:07 PM, Sigurd Saue <sigurd.saue@ntnu.no> wrote:

In case anyone is interested:

The Arduino/Csound topic in the Floss manual shows how to receive the values of a single sensor from Arduino using the serial opcodes. The values are limited by the byte size (range 0 – 255). Iain McCurdy has promised an update with more sensors later, but in the meantime I’ll share my take on this.

The attached files show how to transfer a variety of sensor values, possibly with values larger then 255 (the typical analog range on the Arduino is 0 – 1023). The solution is similar to MIDI. You have to define an ID (a unique number >= 128) for every sensor. The sensor values are transmitted as ID, length (number of data bytes), and the data itself. The Csound code receives the values with the ID first. You should of course use the same IDs in the Csound code to identify the correct sensor.

The serial communication requires a pretty high ksmps. In this case I only transfer one sensor value at krate and toggles between them at each pass. I’m happy to receive suggestions on how to improve the code.

Sigurd

 


Date2014-09-16 18:52
FromTarmo Johannes
SubjectRe: [Csnd] Arduino/Csound serial communication with multiple values
Nice and compact examples,
thanks!
tarmo

On Tuesday 16 September 2014 13:07:05 Sigurd Saue wrote:
> In case anyone is interested:
> 
> The Arduino/Csound topic in the Floss manual shows how to receive the values
> of a single sensor from Arduino using the serial opcodes. The values are
> limited by the byte size (range 0 – 255). Iain McCurdy has promised an
> update with more sensors later, but in the meantime I’ll share my take on
> this.
 
> The attached files show how to transfer a variety of sensor values, possibly
> with values larger then 255 (the typical analog range on the Arduino is 0 –
> 1023). The solution is similar to MIDI. You have to define an ID (a unique
> number >= 128) for every sensor. The sensor values are transmitted as ID,
> length (number of data bytes), and the data itself. The Csound code
> receives the values with the ID first. You should of course use the same
> IDs in the Csound code to identify the correct sensor.
 
> The serial communication requires a pretty high ksmps. In this case I only
> transfer one sensor value at krate and toggles between them at each pass.
> I’m happy to receive suggestions on how to improve the code.
 
> Sigurd



Date2014-09-16 21:57
FromDaisy Audio
SubjectRe: [Csnd] Arduino/Csound serial communication with multiple values
Nice to see how others are using Arduino in projects. Thanks for sharing. I'm keen to try an UDOO board soon as I can. Powerful arm platform with pretty much a built in arduino. Has to be worth a go ;) 

Cheers

Dominic 

On Tuesday, September 16, 2014, Tarmo Johannes <tarmo.johannes@otsakool.edu.ee> wrote:
Nice and compact examples,
thanks!
tarmo

On Tuesday 16 September 2014 13:07:05 Sigurd Saue wrote:
> In case anyone is interested:
>
> The Arduino/Csound topic in the Floss manual shows how to receive the values
> of a single sensor from Arduino using the serial opcodes. The values are
> limited by the byte size (range 0 – 255). Iain McCurdy has promised an
> update with more sensors later, but in the meantime I’ll share my take on
> this.

> The attached files show how to transfer a variety of sensor values, possibly
> with values larger then 255 (the typical analog range on the Arduino is 0 –
> 1023). The solution is similar to MIDI. You have to define an ID (a unique
> number >= 128) for every sensor. The sensor values are transmitted as ID,
> length (number of data bytes), and the data itself. The Csound code
> receives the values with the ID first. You should of course use the same
> IDs in the Csound code to identify the correct sensor.

> The serial communication requires a pretty high ksmps. In this case I only
> transfer one sensor value at krate and toggles between them at each pass.
> I’m happy to receive suggestions on how to improve the code.

> Sigurd



Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"




Date2014-09-16 22:40
FromDaisy Audio
SubjectRe: [Csnd] Re: Arduino/Csound serial communication with multiple
Hi Richard, 

Do you have any further information or code you'd be willing to share about your "the box" project? I'm particularly interested in the xbee communication and the interaction via OSC you've got going on. Really interesting project. Well done indeed! 

Thanks 

Dominic 

On Tuesday, September 16, 2014, zappfinger <zappfinger@gmail.com> wrote:
In my 'box' project (the Box) I use an
Arduino over Xbee at 38400 baud, but that goes via Processing.
Processing converts it to OSC that is then received by Csound.

Richard



--
View this message in context: http://csound.1045644.n5.nabble.com/Arduino-Csound-serial-communication-with-multiple-values-tp5737532p5737536.html
Sent from the Csound - General mailing list archive at Nabble.com.


Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"




Date2014-09-17 12:43
Fromzappfinger
Subject[Csnd] Re: Arduino/Csound serial communication with multiple
Hello Dominic,

Ok, here are the Arduino and Processing sketches.
I use the Xbee's in their basic form, where they emulate a normal serial
connection.
Only had to add the addresses and change the baudrate.

xBeeOsc.pde   
OSCstuff.pde
  
xbeeTest2.ino
  

BTW, when I use the box as a drum trigger by tapping on it, there is a small
latency.
I still have to look at this, but it might have to do with loop I use in the
Arduino to read the Analog pin.
Now it is at 100, should be no problem because reading an analog pin should
take only 1 ns per read...

Richard
  




--
View this message in context: http://csound.1045644.n5.nabble.com/Arduino-Csound-serial-communication-with-multiple-values-tp5737532p5737546.html
Sent from the Csound - General mailing list archive at Nabble.com.

Date2014-09-17 20:55
FromDaisy Audio
SubjectRe: [Csnd] Re: Arduino/Csound serial communication with multiple
Thanks a lot for the info and files Richard. Really interesting to see and a big help for stuff I'm doing. I've never really looked at the Xbee stuff much before, but can see how useful it can be now. I'm hoping to get some wireless osc communication going using either the arduino wifi or gsm shields. Wifi seems to make more sense to me, but a friend is getting good results with the gsm module piped into an iOS app. But that's a whole other ball game! Maybe a Csound iOS API based app could be cool though. Too many options! 

Thanks again. 

Dominic 

On Wednesday, September 17, 2014, zappfinger <zappfinger@gmail.com> wrote:
Hello Dominic,

Ok, here are the Arduino and Processing sketches.
I use the Xbee's in their basic form, where they emulate a normal serial
connection.
Only had to add the addresses and change the baudrate.

xBeeOsc.pde <http://csound.1045644.n5.nabble.com/file/n5737546/xBeeOsc.pde>
OSCstuff.pde
<http://csound.1045644.n5.nabble.com/file/n5737546/OSCstuff.pde>
xbeeTest2.ino
<http://csound.1045644.n5.nabble.com/file/n5737546/xbeeTest2.ino>

BTW, when I use the box as a drum trigger by tapping on it, there is a small
latency.
I still have to look at this, but it might have to do with loop I use in the
Arduino to read the Analog pin.
Now it is at 100, should be no problem because reading an analog pin should
take only 1 ns per read...

Richard





--
View this message in context: http://csound.1045644.n5.nabble.com/Arduino-Csound-serial-communication-with-multiple-values-tp5737532p5737546.html
Sent from the Csound - General mailing list archive at Nabble.com.


Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"