Pages: [1]   Go Down
Author Topic: Processing to Arduino communication  (Read 1288 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thanks for creating this great community.

I've been searching for a couple days but i didn't find anything.
I think is no need to explain the code, it's quite simple.
When I use a Ruby script to send the data trought the Serial port everything is correct, so I suppose that the error is in the Processing code.
When I execute this, Arduino puts on the Serial Window, random 6,5, and New Lines.

Thank you!

Arduino code:
Code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    Serial.println(Serial.read());
  }
}

Processing code:
Code:
import processing.serial.*;

Serial port;

void setup() {
  port = new Serial(this, Serial.list()[0], 9600);
  size(400, 50);
}

void draw() {
  port.write(65);
  delay(500);
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When I execute this, Arduino puts on the Serial Window, random 6,5, and New Lines.
You have the Arduino on one end of the serial port. On the PC, there can be one thing on the other end. Is that the Processing application or the Serial Monitor? It can't be both.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have connected Arduino to the USB, with de Serial Monitor opened to watch what's writing Arduino.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have connected Arduino to the USB, with de Serial Monitor opened to watch what's writing Arduino.
So, when you do that, Processing is not talking to the Arduino. It can't, the Serial Monitor has the port tied up.

You can read responses from the Arduino in Processing, and print them in Processing's message area.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I do this with Ruby it works fine.
I only want to do the same, but with Processing.

The ruby code:
Code:
require 'serialport'

port_str = "/dev/tty.usbmodem621"  #may be different for you
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
 
#just read forever
while true do
  sp.write('A')
  sleep(500)
end
 
sp.close
Logged

Pages: [1]   Go Up
Jump to: