Go Down

Topic: [PD] puredata to arduino (Read 813 times) previous topic - next topic

adrian_goya

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);
  }
 
 }
  

mellis

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;  
    }

adrian_goya

#2
Feb 14, 2006, 08:19 am Last Edit: Feb 14, 2006, 08:24 am by adrian_goya Reason: 1
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.

mellis

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.

Go Up