Problem to receive serial data from processing to arduino duemilanove

edited October 2015 in Arduino

Hi all, Does anyone has information to receive data commnunication from processing to "arduino duemilanove" by sending "0" or "1" byte through serial ? I've received nothing when communicate from serial to arduino and need someone to further guide me. Those reference I took from websites "https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing"

My coding in processing:

import processing.serial.*; Serial myport;

void setup(){

  String portname = Serial.list()[0]; 
  myport = new Serial(this,portname,9600);

}

void draw(){

  if (myport.available() > 0 )
  {
         myport.write("1");
         println("Print 1 to arduino Now");
  }

}

My coding in arduino : (I'd tried to monitor incoming byte from process in serial monitor)

int incomingByte = 0 ;

void setup() {

Serial.begin(9600); 

}

void loop() {

if (Serial.available() > 0 )
{
  incomingByte = Serial.read();
  Serial.print("check :");
  Serial.println(incomingByte,DEC);
}

}

The situation is weird where It show nothing happened and returned empty in output once I opened serial monitor to check out. I've managed to pluged in to power arduino(First) and click to run processing(second). How i could possible to receive "1" from processing to arduino through serial monitor?

Hopw someone could guide me in further, Thanks.

Answers

  • Answer ✓

    Your code cannot work: Both sketches wait for an incoming message before they start to send something.

    This example should work (the serialEvent()-function is not needed, it is only to print the responses from the arduino):

    import processing.serial.*;
    Serial myport;
    
    void setup() {
      // show available serial-ports
      printArray(Serial.list());
      String portname = Serial.list()[3]; 
      myport = new Serial(this, portname, 9600);
    }
    
    void draw() {
      myport.write("1");
      println("Print 1 to arduino Now");
    }
    
    
    // serial event
    void serialEvent(Serial p) {
      try {
    
        // get message till line break (ASCII > 13)
        String message = p.readStringUntil(13);
        // just if there is data
        if (message != null) {
          println(message);
        }
      }
      catch (Exception e) {
      }
    }
    

    Other possible error-sources:

    1.: You might use the wrong serial-port. Verify that your arduino is really on the selected serial port with this line in setup:

    printArray(Serial.list());

    2.: You cannot use processing and the serial-monitor at the same time. But to verify, that your arduino code works as expected, you can use the serial monitor and send data manually.

    Hope that helps. Regards.

  • Hi benja, Thanks for your answer and I finally realised there is interlocking issues between processing and arduino.

Sign In or Register to comment.