1

I'm just beginning to use Processing along side with Arduino and need help linking the two. Just to get started, I just wanted to send a single character (eventually strings) to the Arduino and have the Arduino light up a matrix if the Arduino receives the data.

Here's my code for the Arduino (I'm using an Arduino Uno):

#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

// Set up the matrix
#define CLK 8 
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

int incomingByte = 0;   // for incoming serial data

void setup() {

  Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
  matrix.begin();
}

void loop() {
    if(Serial.available() > 0) {
    incomingByte = Serial.read();

    // Print a white "Done!" to the matrix
    matrix.setCursor(1, 0);
    matrix.setTextSize(0);
    matrix.setTextColor(matrix.Color333(7, 7, 7));
    matrix.print("Done!");

  }
}

And here's the code for Processing:

// Example by Tom Igoe

import processing.serial.*;

// The serial port:
Serial myPort;

// List all the available serial ports:
println(Serial.list());

// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[1], 9600);

// Send a capital "A" out the serial port
myPort.write(65);

I run the processing sketch and then upload the code to the Arduino, but get nothing. The Arduino is using COM3 and I believe the Processing sketch is too, but that may be where I'm messing up.

If I open up the serial monitor and send some data to the Arduino that way, then the LED lights up fine, but only when I do it through that.

Any help would be appreciated. Thanks!

5
  • Please specify what Arduino board you are using. Boards like the Uno reset when you open the serial connection and won't respond till the bootloader has exited. I believe it takes 1-2 seconds.
    – user2973
    Jul 23, 2014 at 5:40
  • Just edited the post to specify, sorry about that. I'm using an Arduino Uno. Jul 23, 2014 at 17:25
  • Your code seems to be assuming that the Arduino is on the first port of the list you fetch, which doesn't sound like it is the case. Anyway, you should first make sure you can trigger your code with the serial monitor in the IDE. Jul 23, 2014 at 18:23
  • I can easily trigger the code with the serial monitor. I've tried it with Processing going to Serial.list()[0] and Serial.list()[1] but have gotten no results either way. Jul 23, 2014 at 23:50
  • 1
    What's the output of println(Serial.list());? Jul 24, 2014 at 12:46

1 Answer 1

1

When you open a serial connection to Arduino Uno the atmega328 microcontroller is usually reset(this depends if the OS is configured to toggle the DTR serial control signal on/off when a port is opened). Just after a reset the bootloader (optiboot) runs to see if you are trying to upload a new sketch. If the bootloader doesn't receive any meaningful communication it will start your sketch after ~1 sec. All communication sent to the serial port while the bootloader is running is lost.

When you use the serial monitor you are too slow to notice the 1 second where the board won't respond to your commands. But the processing sketch is another story.

The easiest fix will be to insert a delay after you open the serial port and before you send any data.

// Wait 1.2 sec
int start = millis();
while (millis() - start < 1200);

If you would rather use a hardware fix you can connect a 10uF capacitor between RESET and GND pins that will prevent the board from being reset by the usb to serial converter.

2
  • The resest-on-open behavior is often a configurable property of the host operating system's serial device, but even if configured not to happen it easily could if the board is moved to a different install. Jul 24, 2014 at 18:18
  • I updated the answer to be more speific
    – user2973
    Jul 24, 2014 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.