Pages: [1]   Go Down
Author Topic: Problem with Port in ARDUINO/Processing  (Read 1133 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Operation BC means Operation BLACK CAT
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I am sending some data over serial from Processing to ARDUINO.
When I try to open the serial Monitor of Arduino to read the data I get the message that my port is already being used...and this makes sense. I am using in both processing and ARDUINO COM4 when I have one platform on the other conflicts and does not work.It depends what I open first, then the other application does not work.
Any advice?
Thank you
Logged

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

Why not make the Processing application read and display the responses from the Arduino?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Operation BC means Operation BLACK CAT
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi,
thanks for the reply..
You mean just send the data back to processing from ARDUINO to confirm that they are clear?
Logged

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

Quote
You mean just send the data back to processing from ARDUINO to confirm that they are clear?

Exactly.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Operation BC means Operation BLACK CAT
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
This was a good solution and it worked!!The thing is that I send a byte to ARDUINO which I know which byte is and then I confirmed and send back to Processing. My challenge now is to send 256 unknown bytes and confirm that arrived to ARDUINO and then send them back and print them in processing. My programming skills are not so good,so might post some pieces of code later on, but thanks for the nice solution!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Operation BC means Operation BLACK CAT
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I am sending to ARDUINO 9 red()values of 9 pixels and waiting for a ping back from ARDUINO in order to print my red values  into processing...but nothing seems to happen. I tried to clean my code as much as possible and keep it simple. My sequence is: I send to ARDUINO from Processing ,I read in ARDUINO and write back to Processing..but nothing seems to happen.
Any suggestion will be appreciated.
thanks again for the help so far.


[glow]Processing Code:[/glow]

//This code reads and prints the pixel values of a 9x9 matrix
import processing.serial.*;
Serial port;
int initval=0; //initial value that the matrix starts
int pixval; //pixel value each time
int col = 9; //number of the matrix columns

port = new Serial(this,Serial.list()[1], 9600);
size(300,300);
PImage myImage;
myImage = loadImage("jelly9x9.jpg");
image (myImage, 0, 0, width, height);

for (pixval = initval; pixval < initval + 1*col; pixval = pixval+1) {
   myImage.loadPixels();
   color a = myImage.pixels[pixval];
  
   float r = red(a);
   int intr = int(r);
   println(intr);    
   port.write(int(intr));
  
   if (port.available() > 0) {
   int inByte = port.read();
   println(binary(inByte));
  }
}

[glow]ARDUINO Code:[/glow]

byte incomingByte;

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

      if (Serial.available() > 0) {
            incomingByte = Serial.read();
                Serial.write(incomingByte);
            }
        }

Logged

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

I'd try blinking the pin 13 LED in the Arduino sketch, whenever it successfully read a byte. That way, you'd know when the Arduino received something, although the RX light should flash to tell you that. Similarly, the TX light should flash when the Arduino sends data.

The TX and RX light on duration is pretty short, and easy to miss, so making the onboard LED light up for longer makes it easier to see.

Code:
port.write(int(intr));

The variable intr is already an int. There is no reason to explicitly cast an int to an int.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Operation BC means Operation BLACK CAT
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks a lot for the advice!!!!It works indeed with the LED! At least I am sure that Arduino sends data back..want to print them neatly in processing though!!!will try this further...thanks again

Logged

Pages: [1]   Go Up
Jump to: