Pages: [1]   Go Down
Author Topic: Processing: should I use Firmdata ?  (Read 947 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was trying to interact with processing using an Arduino nano. It should be a bidirectional interaction and I'm having problems. From arduino to processing works fine, but when I try to send data from processing to Arduino, then it is *very* slowly. I was looking for help and I found the firmdata code.
Is this the way I should go ? Install firmdata and program everything from processing ?
Thanks !
Logged

0
Offline Offline
Shannon Member
****
Karma: 136
Posts: 10525
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what do you mean is slow? it should communicate at baudrate speed.
maybe on the arduino code you are usong bloacking serial like
while(Serial.avaiable>0){...}
??
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, solved.
I used the processing examples but they are no so good IMO. The problem is that the serial buffer is saturated.
The solution is to send / receive only when there is a change in the state. For instance, on the arduino side:

  oer=analogRead(OER)>512?1:0;
  oef=analogRead(OEF)>512?1:0;
  odr=analogRead(ODR)>512?1:0;
  odf=analogRead(ODF)>512?1:0;
  b1=oer+oef*2+odr*4+odf*8;
  if (b0!=b1) { // send only if state changed
    Serial.print(b1,BYTE);
    b0=b1;
  }
 ...
 delay(100);


The same for Proessing.

If someone needs help, just ask me and I post both codes smiley



Logged

0
Offline Offline
Shannon Member
****
Karma: 136
Posts: 10525
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can calculate the amount of data for serial in this way:
baud rate is the number of symbols you can send per seconds...

you can also clear the buffer with Serial.clear(), both in processing and arduino.
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

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

Quote
you can also clear the buffer with Serial.clear(), both in processing and arduino.
Some people actually use the Serial.flush() function to do that, but, it really isn't recommended, since it throws away random amounts of unprocessed serial data.

Sending data only as fast as it can be dealt with is a much better solution.
Logged

Pages: [1]   Go Up
Jump to: