chipKIT® Development Platform

Inspired by Arduino™

Can't write and read serial in same sketch

Created Wed, 18 Apr 2012 09:14:23 +0000 by gregf


gregf

Wed, 18 Apr 2012 09:14:23 +0000

Hello All, I'm new to chipkit32 (from arduino-land) so please accept my apologies if this is a well known problem.

Somehow I cannot read/write between a sketch running on uno32 via a processing sketch. If I remove the write from the processing code, the code runs fine. I know it's counterintuitive that a problem on the processing side is caused by an issue on the uno32, these sketches do in fact work with Arduino 1.0 on an Uno (i.e. the 7s get printed in the processing console).

Any ideas what's going on? This is the simplest code I could boil down my issue to.

This is the uno32/arduino sketch:

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.write(7);
  delay(300);
}

And this is the processing sketch:

import processing.serial.*;

Serial myPort;                       // The serial port

void setup() {
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  if (myPort.available() > 0) {
    println(myPort.read());
  }
  
  myPort.write('B');
  delay(30);
}