Csound Csound-dev Csound-tekno Search About

[Csnd] serial opcodes w/ arduino demo

Date2011-09-06 20:39
Frommatt ingalls
Subject[Csnd] serial opcodes w/ arduino demo
here's code and video of a little demo i made with these new serial bus opcodes:
( note the arduino code is even simpler than the csound code!! )

VIDEO:
http://gallery.me.com/mattingalls#100119

==========================================

ARDUINO CODE:

void setup()  { 
  // enable serial communication
  Serial.begin(9600);
  
  // declare pin 9 to be an output:
  pinMode(9, OUTPUT);
} 

void loop()  
{ 
  // only do something if we received something (this should be at csound's k-rate)
  if (Serial.available()) 
  {
         // set the brightness of LED (connected to pin 9) to our input value
       int brightness = Serial.read();
       analogWrite(9, brightness);
   
       // while we are here, get our knob value and send it to csound
       int sensorValue = analogRead(A0);
       Serial.write(sensorValue/4); // scale to 1-byte range (0-255)
  }     
}

======================================================

CSOUND CODE:
run with a commandline something like:
csound --opcode-lib=serialOpcodes.dylib serialdemo.csd -odac -iadc




ksmps = 500 ; the default krate can be too fast for the arduino to handle
0dbfs = 1

instr 1

; connect to the arduino with baudrate = 9600
iPort serialBegin "/dev/cu.usbmodemfa131", 9600

; read our knob value
kGain init 16
kVal serialRead iPort
if (kVal != -1) then
	kGain = kVal/128
endif

; get our audio input and get its rms
aSig in
kRms rms aSig*kGain

; scale the rms to a good value for the LED and send it out
kRms = kRms*kRms*255
serialWrite iPort, (kRms < 255 ? kRms : 255) ; must be in range: 0-255

endin




f 1 0 1024 10 1 1 1 1 1 1 
i 1 0 200
e



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2011-09-07 07:34
FromOeyvind Brandtsegg
SubjectRe: [Csnd] serial opcodes w/ arduino demo
Thanks a lot Matt,
for the opcodes and for a nice example.
Oeyvind

2011/9/6 matt ingalls <matt@sonomatics.com>
here's code and video of a little demo i made with these new serial bus opcodes:
( note the arduino code is even simpler than the csound code!! )

VIDEO:
http://gallery.me.com/mattingalls#100119

==========================================

ARDUINO CODE:

void setup()  {
 // enable serial communication
 Serial.begin(9600);

 // declare pin 9 to be an output:
 pinMode(9, OUTPUT);
}

void loop()
{
 // only do something if we received something (this should be at csound's k-rate)
 if (Serial.available())
 {
        // set the brightness of LED (connected to pin 9) to our input value
      int brightness = Serial.read();
      analogWrite(9, brightness);

      // while we are here, get our knob value and send it to csound
      int sensorValue = analogRead(A0);
      Serial.write(sensorValue/4); // scale to 1-byte range (0-255)
 }
}

======================================================

CSOUND CODE:
run with a commandline something like:
csound --opcode-lib=serialOpcodes.dylib serialdemo.csd -odac -iadc

<CsoundSynthesizer>
<CsInstruments>

ksmps = 500 ; the default krate can be too fast for the arduino to handle
0dbfs = 1

instr 1

; connect to the arduino with baudrate = 9600
iPort serialBegin "/dev/cu.usbmodemfa131", 9600

; read our knob value
kGain init 16
kVal serialRead iPort
if (kVal != -1) then
       kGain = kVal/128
endif

; get our audio input and get its rms
aSig in
kRms rms aSig*kGain

; scale the rms to a good value for the LED and send it out
kRms = kRms*kRms*255
serialWrite iPort, (kRms < 255 ? kRms : 255) ; must be in range: 0-255

endin


</CsInstruments>
<CsScore>
f 1 0 1024 10 1 1 1 1 1 1
i 1 0 200
e
</CsScore>
</CsoundSynthesizer>

Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2011-09-07 09:09
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] serial opcodes w/ arduino demo
These new opcodes are awesome!  
Thanks so much for writing them and adding them to Csound.
Can't wait to try them on my machine.  My Arduinos should arrive tomorrow.

Looking forward to more of your video demos and code that will serve to inspire all of us to 
Take full advantage of all the new possibilities that this capability brings to Csound. 

Thanks so much Matt.

Rick.

Sent from my iPad.

On Sep 6, 2011, at 3:39 PM, matt ingalls  wrote:

> here's code and video of a little demo i made with these new serial bus opcodes:
> ( note the arduino code is even simpler than the csound code!! )
> 
> VIDEO:
> http://gallery.me.com/mattingalls#100119
> 
> ==========================================
> 
> ARDUINO CODE:
> 
> void setup()  { 
>  // enable serial communication
>  Serial.begin(9600);
> 
>  // declare pin 9 to be an output:
>  pinMode(9, OUTPUT);
> } 
> 
> void loop()  
> { 
>  // only do something if we received something (this should be at csound's k-rate)
>  if (Serial.available()) 
>  {
>         // set the brightness of LED (connected to pin 9) to our input value
>       int brightness = Serial.read();
>       analogWrite(9, brightness);
> 
>       // while we are here, get our knob value and send it to csound
>       int sensorValue = analogRead(A0);
>       Serial.write(sensorValue/4); // scale to 1-byte range (0-255)
>  }     
> }
> 
> ======================================================
> 
> CSOUND CODE:
> run with a commandline something like:
> csound --opcode-lib=serialOpcodes.dylib serialdemo.csd -odac -iadc
> 
> 
> 
> 
> ksmps = 500 ; the default krate can be too fast for the arduino to handle
> 0dbfs = 1
> 
> instr 1
> 
> ; connect to the arduino with baudrate = 9600
> iPort serialBegin "/dev/cu.usbmodemfa131", 9600
> 
> ; read our knob value
> kGain init 16
> kVal serialRead iPort
> if (kVal != -1) then
>    kGain = kVal/128
> endif
> 
> ; get our audio input and get its rms
> aSig in
> kRms rms aSig*kGain
> 
> ; scale the rms to a good value for the LED and send it out
> kRms = kRms*kRms*255
> serialWrite iPort, (kRms < 255 ? kRms : 255) ; must be in range: 0-255
> 
> endin
> 
> 
> 
> 
> f 1 0 1024 10 1 1 1 1 1 1 
> i 1 0 200
> e
> 
> 
> 
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"