chipKIT® Development Platform

Inspired by Arduino™

problem with serial communication

Created Sun, 08 Jan 2012 11:57:46 +0000 by neptunier


neptunier

Sun, 08 Jan 2012 11:57:46 +0000

hello all, i have a problem with serial communication with the uno32. i want to read data from a biofeedback programm. the code i used works perfectly on a arduino but it does not work on the chipkit. here i wrote some examplecode just for checking.this is the code:

int ledpin2 = 43;

void setup() {
   
    pinMode(ledpin2, OUTPUT);
    Serial.begin(9600); 
}

void loop() {
   digitalWrite(ledpin2, LOW);
   
 
  if (Serial.available() > 0)
  {
    digitalWrite(ledpin2, HIGH);
    
     delay (500);
    
     
     digitalWrite(ledpin2, LOW);

     delay(500);
     
    }
    
  }

one led of the two indicating serial communication blinks, so the board seems to receive data. but it just does not process this incomong data. nothing more happens. is there something i missed? thanks for your help, michael


majenko

Sun, 08 Jan 2012 12:15:36 +0000

One thing with your example code -

You are checking Serial.available(), but you aren't doing anything with the data.

Once data arrives Serial.available() will have the number of bytes in the buffer. That number will stay the same or increase as more data arrives. It won't ever go down, unless you read the data from the buffer.

As it stands, the code on my UNO32 does nothing until data arrives - then LD5 starts flashing at 1 second intervals.

This modification is probably more along the lines of what you are after in your test code:

{snip}

void loop() {
  char data;
   digitalWrite(ledpin2, LOW);
   

  if (Serial.available() > 0)
  {
    data = Serial.read();
    digitalWrite(ledpin2, HIGH);
   
     delay (500);
   
     
     digitalWrite(ledpin2, LOW);

     delay(500);
     
    }
   
  }

neptunier

Sun, 08 Jan 2012 19:29:02 +0000

hi majenko, yes what you say is true but this code was just an example. i used different code for the real application. the other code works on arduino fine, this code is just to check if something is coming in and then chipkit should blink. but he doesnt and i wonder why. michael


majenko

Sun, 08 Jan 2012 19:32:37 +0000

The code works beautifully on my UNO32â„¢ board.

What version of MPIDE are you using?

What are you using to do the serial communications at the computer end?


neptunier

Sun, 08 Jan 2012 20:43:52 +0000

i am using bioera software with a serial port element on the computer side. as i said, the arduino works beautifully. maybe there is something wrong with my chipkit board if the code works fine on your board. or do you have to change some jumpers. i am using the multiplatform mpide. other code works well on the chipkit, just not the serial communication.


majenko

Sun, 08 Jan 2012 21:01:39 +0000

Does the test code work if you use the serial monitor in the MPIDE?


Tallystick

Sun, 08 Jan 2012 23:07:06 +0000

This sounds very similar to the problem I'm having.

See my post in General Discussions. I tried linking directly to my post, but received a stupid error message "Your post looks too spamy for a new user, please remove off-site URLs. " even though I linked to an on-site URL.

If I try to use the serial monitor in the MPIDE while the Processing sketch is running, I get a "COM3 is already in use" error message.


pshouse

Fri, 16 Mar 2012 14:59:07 +0000

To me it doesn't work as expected, either. I have to send several chars (around 20) before it starts receiving them, then it works. I think it's the bootloader that messes up and receives the chars instead of the user program.

My work-around is: a) UPLOAD the new code b) send a char via serial monitor (it gets ignored/lost, probably cought by bootloader) c) Hardware reset (click on the button on the board) d) wait for the bootloader startup led blinking to stop e) Now it works ok.

Doing b) each time is frustrating. No, if you do c) without b), it still doesn't work.


fishkit

Thu, 16 Aug 2012 11:39:11 +0000

just come across the similar problem - Serial.available doesnt seem to see last byte in the buffer. So I tried just calling Serial.read() instead (ignore it if it returns -1) and bingo! now it reads the final byte.