Pages: [1]   Go Down
Author Topic: [PD] puredata to arduino  (Read 669 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
I love YaBB 1G - SP1!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm trying to control the Arduino digital out from PureData. I'm using comport in PD to send serial data over the port and I need Arduino to read it and excecute a task. This seems like a realy simple thing to do, but I can't get it to work.
I'm using the Serial Read Advanced example included int the Arduino 003. The TX light turns on in the board when sending data over the port, but no luck with the
LED...

Any help would be very apreciated,

Thanks,
adrián goya


int ledPin = 13;  // LED en el pin 13
int val = 0; //variabe para guardar el data del puerto serial
int serbyte = 0;  //variable para guardar el data VALIDO del puerto

void setup()
{

 pinMode(ledPin, OUTPUT);  
 beginSerial(19200);
}
 
void loop()
{
 serbyte = serialRead();
   if (val !=  -1) {
  val = serbyte;  
   }
 
 if (val == 113) {      
 digitalWrite(ledPin, LOW);    
}  else {
   digitalWrite(ledPin, HIGH);    
 delay(1000);
 }

}
 
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Whoops, looks like a bug in that example.  Thanks for finding it.

This code:

Quote
   if (val !=  -1) {
   val = serbyte;  
    }
  


should be:

   if (serbyte !=  -1) {
  val = serbyte;  
   }
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
I love YaBB 1G - SP1!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you mellis for the response. I corrected the error you pointed out but it didn't completely fix it.

I also changed the variable declaration in the beginning:

int val = 0;
int serbyte = 0;

for:

char val = 0;
char serbyte = 0;

and now it seems to be working fine.

adrian goya.


note: same story for the Serial Read Basic example.
« Last Edit: February 14, 2006, 02:24:10 am by adrian_goya » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your patience and posting the corrections (and in Spanish too!).  It's been added to the bug database and should be fixed in the next release.
Logged

Pages: [1]   Go Up
Jump to: