arduino: alternatives to ArduinoSMS

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

arduino: alternatives to ArduinoSMS

yvan volochine-2
hi,
I'd like to trigger some code with my arduino but as I only get very rare triggers, I'm not really willing to use a Routine/Task via ArduinoSMS.
what other approach could I use ?

cheers,
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

Fredrik Olofsson
24 okt 2011 kl. 01.59 skrev yvan volochine:

> hi,
> I'd like to trigger some code with my arduino but as I only get very rare triggers, I'm not really willing to use a Routine/Task via ArduinoSMS.
> what other approach could I use ?

hi Yvan,
sounds like you're not using the correct baudrate in sc.  doublecheck that it's the same in the arduino code as in the sms code.

i never liked sms.  it's just as easy to roll your own.  here's an example reading an analog pin and triggering functions in sc.

//--arduino code
int val;
void setup() {
  Serial.begin(38400); //baudrate
}
void loop() {
  val= analogRead(A0); //read pin A0 (10bit value)
  Serial.print(val>>2, BYTE); //convert to 8bit and send via serial
  delay(10); //wait 10milliseconds
}


//--sc code
//SerialPort.listDevices.postln; //list available ports
(
var thresh= 100;
var port= SerialPort("/dev/tty.usbmodemfd121", 38400); //edit port here
Routine({
        var byte, state= false;
        inf.do{
                byte= port.read;
                //byte.postln; //debug
                if(state==false, {
                        if(byte>=thresh, {
                                "on".postln;
                                state= true;
                        });
                }, {
                        if(byte<thresh, {
                                "off".postln;
                                state= false;
                        });
                });
        };
}).play;
CmdPeriod.doOnce({port.close});
)




  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

yvan volochine-2
On 10/24/2011 09:40 AM, Fredrik Olofsson wrote:
> hi Yvan,
> sounds like you're not using the correct baudrate in sc.  doublecheck that it's the same in the arduino code as in the sms code.
>
> i never liked sms.  it's just as easy to roll your own.  here's an example reading an analog pin and triggering functions in sc.

hi Fredrik,

my baudrate is correct, that's my english which was not clear enough ;)

I meant that I only trigger a couple of times during the performance, so
I thought that using a Routine might not be the cheapest way to do things.
I imagined I could have the Arduino triggering events à la HID but it
seems I was wrong.

anyway, using SerialPort instead of SMS works like a charm.

tack så mycket !
_y

--
[hidden email]
http://yvanvolochine.com

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

Fredrik Olofsson

24 okt 2011 kl. 14.34 skrev yvan volochine:

> On 10/24/2011 09:40 AM, Fredrik Olofsson wrote:
>> hi Yvan,
>> sounds like you're not using the correct baudrate in sc.  doublecheck that it's the same in the arduino code as in the sms code.
>>
>> i never liked sms.  it's just as easy to roll your own.  here's an example reading an analog pin and triggering functions in sc.
>
> hi Fredrik,
>
> my baudrate is correct, that's my english which was not clear enough ;)
>
> I meant that I only trigger a couple of times during the performance, so I thought that using a Routine might not be the cheapest way to do things.
> I imagined I could have the Arduino triggering events à la HID but it seems I was wrong.
>
> anyway, using SerialPort instead of SMS works like a charm.
>
> tack så mycket !

var så god.

i wouldn't worry about a routine taking up cpu.  though here's another example that sits and waits for any incoming serial data.  should be more efficient than the one i posted previously.  it checks ten times per second.  tune it to your needs.


//--arduino code
int thresh= 512;    //of 0-1023
int val;
boolean state;
void setup() {
 Serial.begin(38400); //baudrate
 state= false;
}
void loop() {
 val= analogRead(A0); //read pin A0 (10bit value)
 if(!state) {
   if(val>=thresh) {
     state= true;
     Serial.print(val>>2, BYTE); //convert to 8bit and send via serial
   }
 } else {
   if(val<thresh) {
     state= false;
     Serial.print(val>>2, BYTE); //convert to 8bit and send via serial
   }
 }
 delay(10); //wait 10milliseconds
}


//--sc code
//SerialPort.listDevices.postln; //list available ports
(
var port= SerialPort("/dev/tty.usbmodemfa131", 38400); //edit port here
Routine({
        var byte;
        inf.do{
                while({(byte= port.next).isNil}, {
                        0.1.wait; //update rate 10hz
                });
                //--the function:
                ("received"+byte).postln;
        };
}).play;
CmdPeriod.doOnce({port.close});
)






  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

yvan volochine-2
On 10/24/2011 03:06 PM, Fredrik Olofsson wrote:
> i wouldn't worry about a routine taking up cpu.  though here's another example that sits and waits for any incoming serial data.  should be more efficient than the one i posted previously.  it checks ten times per second.  tune it to your needs.

I see..
thanks for the tips Fredrik !

cheers,
_y

--
[hidden email]
http://yvanvolochine.com

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

connecting SC to remote application via URL

Konstantinos Vasilakos-2
Hello I am using the example of SC to connect with a remote app://
application 1:
n = NetAddr("127.0.0.1", 57120); // the url should be the one of computer
of app 2 (or nil)

o = OSCresponderNode(n, '/chat', { |t, r, msg| ("time:" + t).postln;
msg[1].postln }).add;

// application 2:
m = NetAddr("127.0.0.1", 57120); // the url should be the one of computer
of app 1
m.sendMsg("/chat", "Hello App 1");

So far we didn't manage any connectivity although there is a possibility
that the routers are blocking the communication,

would you see any other problem before concluding to routers?


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: connecting SC to remote application via URL

Luke Selden
Check out OSCGroups (Google for it, and there's a Quark) -- it creates a HTTP tunnel for your UDP (OSC) messages, and is quite helpful for remote communication.

Hope that helps!
~luke

On Thu, Oct 27, 2011 at 2:31 PM, Konstantinos Vasilakos <[hidden email]> wrote:
Hello I am using the example of SC to connect with a remote app://
application 1:
n = NetAddr("127.0.0.1", 57120); // the url should be the one of computer
of app 2 (or nil)

o = OSCresponderNode(n, '/chat', { |t, r, msg| ("time:" + t).postln;
msg[1].postln }).add;

// application 2:
m = NetAddr("127.0.0.1", 57120); // the url should be the one of computer
of app 1
m.sendMsg("/chat", "Hello App 1");

So far we didn't manage any connectivity although there is a possibility
that the routers are blocking the communication,

would you see any other problem before concluding to routers?


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

rags música
In reply to this post by yvan volochine-2
Hi Fredrik,
This code works well for me, thanks. But what I want to do is to send continuous values from a potentiometer. Then I have to use Serial.write, but while in the arduino console I get values from 0 to 1021 (using .println), in supercollider I get values from 0 to 255, and everytime I go to a higher position on the potentiometer, it goes to 0 again until the next 255, and so on..
Does the .write method wraps up until 255? How can I get my 1021 values?

Thanks,

Roberto


2011/10/25 yvan volochine <[hidden email]>
On 10/24/2011 03:06 PM, Fredrik Olofsson wrote:
i wouldn't worry about a routine taking up cpu.  though here's another example that sits and waits for any incoming serial data.  should be more efficient than the one i posted previously.  it checks ten times per second.  tune it to your needs.

I see..
thanks for the tips Fredrik !

cheers,
_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

Fredrik Olofsson
correct.  to simplify things i made that example 8bit (0-255) only.  the val>>2 part means divide by 4 so downscaling the value from the analog read 10bit (0-1023) to 8bit.  (1024/4= 256).
to send 'all' the values and the full 10bit resolution from the pot, you'll need to write/print two (8bit) bytes from arduino, read these two out in the right order in sc, and combine them again (the
two 8bit bytes) into a 10bit value.  usually you use one for the lower 8 bits and one of the upper 2 bits, but other schemes are possible.

here's a new example that deals with a single 10bit sesor.  slightly more complex because the safety mechanism sending two 'header' bytes (255 and 254) as a lead in.  these can never occur in the lo/hi bytes if you think about it so useful for detecting where sc picks up the serial stream of data.  this is necessary to know you're reading the right byte into the right variable (lo/hi).  also here there are other ways of doing it.  ask again or maybe someone else will show their preferred method.

good luck,
_f


//--arduino code
int val;
void setup() {
  Serial.begin(38400); //baudrate
}
void loop() {
  val= analogRead(A0); //read pin A0 (10bit value)
  Serial.write(255);
  Serial.write(254);
  Serial.write(val>>2); //first the lower 8 bits
  Serial.write((val&0b1100000000)>>8); //then mask and send the upper 2 bits (never > 3)
  delay(10); //wait 10milliseconds
}

/*
//--sc code
//SerialPort.listDevices.postln; //list available ports
(
var port= SerialPort("/dev/tty.usbmodemfa131", 38400); //edit port here
Routine({
        var byte, loByte, hiByte, val, index= 0;
        inf.do{
                while({(byte= port.read).isNil}, {}); //wait for serial
                if(index==0 and:{byte==255}, {
                        index= 1;
                }, {
                        if(index==1 and:{byte==254}, {
                                index= 2;
                        }, {
                                if(index==2, {
                                        loByte= byte;
                                        index= 3;
                                }, {
                                        if(index==3, {
                                                hiByte= byte;
                                                val= hiByte<<8+loByte;
                                                //--the function:
                                                ("received loByte:"+loByte+"hiByte:"+hiByte+"= value"+val).postln;
                                        });
                                        index= 0;
                                });
                        });
                });
        };
}).play;
CmdPeriod.doOnce({port.close});
)
*/


_f

2 mar 2012 kl. 16.26 skrev rags música:

> Hi Fredrik,
> This code works well for me, thanks. But what I want to do is to send continuous values from a potentiometer. Then I have to use Serial.write, but while in the arduino console I get values from 0 to 1021 (using .println), in supercollider I get values from 0 to 255, and everytime I go to a higher position on the potentiometer, it goes to 0 again until the next 255, and so on..
> Does the .write method wraps up until 255? How can I get my 1021 values?


  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

rags música
Thanks Fredrik,
now I realize I wasn't using the 8 bit resolution before (stupid me!), but sending the direct values to SC, therefore while I was moving the slider up, after reaching the value 255 it started again from zero, until the next 255... but with the <<2 it gives from 0 to 255 for the whole range of the slider, which is fine for me. 
On the last code, although the val value goes from 0 to 1023, every time the index changes, there is a jump in val, so it is not continuous. I'l try to find out what it is.

Thanks a lot for your help!!

R




2012/3/2 Fredrik Olofsson <[hidden email]>
correct.  to simplify things i made that example 8bit (0-255) only.  the val>>2 part means divide by 4 so downscaling the value from the analog read 10bit (0-1023) to 8bit.  (1024/4= 256).
to send 'all' the values and the full 10bit resolution from the pot, you'll need to write/print two (8bit) bytes from arduino, read these two out in the right order in sc, and combine them again (the
two 8bit bytes) into a 10bit value.  usually you use one for the lower 8 bits and one of the upper 2 bits, but other schemes are possible.

here's a new example that deals with a single 10bit sesor.  slightly more complex because the safety mechanism sending two 'header' bytes (255 and 254) as a lead in.  these can never occur in the lo/hi bytes if you think about it so useful for detecting where sc picks up the serial stream of data.  this is necessary to know you're reading the right byte into the right variable (lo/hi).  also here there are other ways of doing it.  ask again or maybe someone else will show their preferred method.

good luck,
_f


//--arduino code
int val;
void setup() {
 Serial.begin(38400);  //baudrate
}
void loop() {
 val= analogRead(A0);  //read pin A0 (10bit value)
 Serial.write(255);
 Serial.write(254);
 Serial.write(val>>2); //first the lower 8 bits
 Serial.write((val&0b1100000000)>>8); //then mask and send the upper 2 bits (never > 3)
 delay(10);    //wait 10milliseconds
}

/*
//--sc code
//SerialPort.listDevices.postln;        //list available ports
(
var port= SerialPort("/dev/tty.usbmodemfa131", 38400);  //edit port here
Routine({
       var byte, loByte, hiByte, val, index= 0;
       inf.do{
               while({(byte= port.read).isNil}, {});                   //wait for serial
               if(index==0 and:{byte==255}, {
                       index= 1;
               }, {
                       if(index==1 and:{byte==254}, {
                               index= 2;
                       }, {
                               if(index==2, {
                                       loByte= byte;
                                       index= 3;
                               }, {
                                       if(index==3, {
                                               hiByte= byte;
                                               val= hiByte<<8+loByte;
                                               //--the function:
                                               ("received loByte:"+loByte+"hiByte:"+hiByte+"= value"+val).postln;
                                       });
                                       index= 0;
                               });
                       });
               });
       };
}).play;
CmdPeriod.doOnce({port.close});
)
*/


_f

2 mar 2012 kl. 16.26 skrev rags música:

> Hi Fredrik,
> This code works well for me, thanks. But what I want to do is to send continuous values from a potentiometer. Then I have to use Serial.write, but while in the arduino console I get values from 0 to 1021 (using .println), in supercollider I get values from 0 to 255, and everytime I go to a higher position on the potentiometer, it goes to 0 again until the next 255, and so on..
> Does the .write method wraps up until 255? How can I get my 1021 values?


 #|
    fredrikolofsson.com     musicalfieldsforever.com
 |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: arduino: alternatives to ArduinoSMS

Stefan Nussbaumer
In reply to this post by Fredrik Olofsson
Am 02.03.12 21:09, schrieb Fredrik Olofsson:

> //--arduino code
> int val;
> void setup() {
>    Serial.begin(38400); //baudrate
> }
> void loop() {
>    val= analogRead(A0); //read pin A0 (10bit value)
>    Serial.write(255);
>    Serial.write(254);
>    Serial.write(val>>2); //first the lower 8 bits
>    Serial.write((val&0b1100000000)>>8); //then mask and send the upper 2 bits (never>  3)
>    delay(10); //wait 10milliseconds
> }
this has been puzzling me for a while: i've connected a potentiometer to
test the setup but some values were always missing (i.e. there were
'jumps' from 300 something to 700 something or so). the following code
now works as expected:

//--arduino code
int val;
void setup() {
   Serial.begin(38400); //baudrate
}
void loop() {
   val= analogRead(A0); //read pin A0 (10bit value)
   Serial.write(255);
   Serial.write(254);
   Serial.write(lowByte(val));
   Serial.write(highByte(val));
   delay(10); //wait 10milliseconds
}

... for whom ever this is of interest

stefan



smime.p7s (3K) Download Attachment
Loading...