Pages: [1] 2 3   Go Down
Author Topic: bug with serial port?  (Read 3314 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi...
i just got some new decimilias and i found something strange with the serial port. first of all i recognized, that the delay between sending and recieving data got longer with the decimilias(compared to the NG). my second problem is, that simply sending a number and recieving it doesn´t work with processing. i tried the same code with the ng and it works perfect- so it must be something with the decimilia. is there something new one has to take care of or is it a bug?

timm
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a difference in the Diecimila, in that opening a serial connection to the board will reset it.  This means that for the first second or so, any serial data you send goes to the bootloader, not your sketch.  You can avoid this by having a slight delay after opening the port but before writing data to it.  Or, if your program sends and receives the same type of data repeatedly, it should work, it's just that the first few pieces of data might not arrive.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what my programm does is to send data to the arduino to compare it to the data of the sensor(on arduino side). to test the decimilia i made a simple programm just sending every second an int to the controller and print out everything that comes in. problem is(so far) that nothing is coming back. and it´s not a code thing as it works fine on the ng. would the arduino react differently with a pin0 pin1 connection?
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Possibly.  Do you have something connected to pins 0 and 1?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no, so far i don´t. it´s just a bit more complicated(would have to use a MAX232, don´t i?)...and i don´t have too much time. but do you know, if a connection via those pins would go to the bootloader as well?
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would try inserting a delay before you write to the Arduino.  Something like this:

Code:
import processing.serial.*;

Serial port;
boolean first = true;

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

void draw() {
  if (first) {
    delay(2000);
    first = false;
  }
  
  // rest of sketch goes here.
}

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

took a while now, till i found some time to look at it more carefully... it is working with this kind of delay, but it must be quite big. right now i´m using about 11 seconds and it´s doing fine with this. less didn´t work.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Huh.  It shouldn't need to be anything near that large, since the bootloader is supposed to time out after a second or two.  Can you post the whole sketch (or a simplified version that shows the same problem)?  I'd like to try it out for myself and see if I can do anything about it.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

actually, for testing, there is not a lot of code. but i tried it again and i´m getting back null(all the time) when using less then 11seconds...


void draw() {
  
  if (first) {
    delay (11000);
    println("ab geht´s!");
    first = false;
  }
  
  myPort.write(send);
  delay (100);
  
  background(0);
  inString = myPort.readString();
  
  println(inString);
  send++;
  delay(100);
  
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and on arduino side it´s simply this

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

i tested several of the new boards and all of them reacted equal.
(btw: first code comes from processing)
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Strange.  Can you post the whole sketch (just so it's easier for me to paste in and try out)?  I'll see if I can figure out what the deal is.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well, there´s not much more:)

import processing.serial.*;

Serial myPort;
String inString;

int send = 30;
boolean first = true;

void setup() {

  size(20,20);
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[2], 9600);

}

void draw() {
  
  if (first) {
    delay (11000);
    println("ab geht´s!");
    first = false;
  }

  myPort.write(send);
  delay (100);
  
  inString = myPort.readString();
  
  println(inString);
  send++;
  delay(100);
  
}

the arduino code is the one of the 'Serial.read  "".println' example
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

now i´ve got another strange behaviour of my decimilia: every time i restart the serial communication(via processing), the arduino resets.
(i made a programm which needs ~5 minutes to adapt to the specific situations and restarting means to loose all those values. besides i´m using all pins which means when restarting i´m having some on/offs on pin 13... so restarting the serial port right now means crushing the whole installation...)
on the description it says "it is programmed to ignore malformed data". seems like this doesn´t work on mine(i didn´t try all of them, but three different ones, all having the same behaviour). can i do something to get around this?
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Diecimila does in fact reset every time you open a serial connection to it.  There are a few ways to get around it.  The easiest might be to remove the capacitor that allows the automatic reset (although if you do, you'll also need to replace the bootloader with the NG one or you'll have a hard time uploading new sketches).  It's the last thing (closest to the ATmega168) in the column of components that includes the L led and the RX and TX leds, I think.  

Or you could use some sort of proxy (i.e. another simple Processing sketch) that keeps the serial port open all the time and forwards data to the other sketch over a local network connection (or some other means).  

There's another trick, but it will probably require you to modify the Processing serial library and or the RXTX library that it uses.  If you unset HUPCL when you have the port open, the next time you open it, the board won't reset.  
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I experienced the same problem relating to this issue.

I just got my decimila and tried using the example program 'physicalpixel' ; I was only able to get the processing program to interact with the arduino by adding a delay of about 12 seconds along the lines suggested in the previous replies.

Could you explain why it is necessary to do this, since I presume that the previous versions of the board did not require it?

You may want to amend the example programs as I am sure a lot of folks like myself will try the communications examples, such as physicalpixel and be a bit disappointed when they dont work.

Logged

Pages: [1] 2 3   Go Up
Jump to: