Does one Need to Slow Down Processing in Order for Arduino to Catch Up?


i have processing , arduino communicating on com port fine. com port through usb , attached arduino mega 2560, on win xp. there lcd serial controller bv4618, attached arduino. lcd's serial controller using pins 4 & 5 serial rx/tx. communication between arduino , lcd set 9600 baud, otherwise silly korean characters.

i wrote simple processing test program sends few strings down , arduino happily receives them , displays them on lcd. tried speeds 57600 baud , works fine.

but problem need put delay(900); statement processing code, otherwise arduino stops receiving data. in other words, if processing delay 900 or higher, arduino shows received data on lcd. if drop processing delay 800, arduino stops showing data received data, although little rx led on arduino blinks sign went in.

now, testing. end product needs processing/arduino code works fast possible, without delay 1 second long. not know how serial works. how can avoid having delay(900) on processing side?

here processing code:

code: [select]

/**
* v1.00.a
*
* sketch illustrates how send commands parameters arduino sketch. commands
* need terminated lf or cr. processing sketch made work arduino
* sketch:
*
*   arduino_lcd_serial_byvac_bv4618_and_serial_com
*
* arduino needs have lcd display attached , configured. above arduino sketch using
* hd44780 lcd (4x20) controller byvac bv4618 serial controler.
*
*
* updates:
*
*   15:37 9.5.12 - v1.00.a = initial code.
*
*/

import processing.serial.*;

// serial port:
serial myport;

int = -1;  // counter switch() statement must start -1, not 0, 1
             // imagine.

void setup() {

  // list available serial ports:
  println(serial.list());

  // pick serial port arduino hooked, or find arduno
  // sits in control panel > system > device manager > usb ports.
  myport = new serial(this, "com6", 57600);
}

void draw() {

/*
  * found through experimentation processing wants execute 1 write()
  * statement per loop. if try execute 2 write()'s freezes, doesn't reset
  * arduino, otherwise normal @ begining of processing sketch run!
  *
  * processing's switch() statement, on other hand, wants start itterator -1, not 0,
  * logical.
  *
  * multiple write() statements, sending multiple commands arduino, stuck them up,
  * like: "servox 472\nsrx 2437\n", using '\n' command delimeter.
  */
  switch (i) {
    case 0:
      // line must terminated either '\n' or '\r' characters.
      myport.write("servox 1379\n"); break;
    case 1:
      myport.write("servoy 20\r"); break;
    case 2:
      // comands can stuck up, 1 after another, this:
      myport.write("srx 640\nsry 480\n"); = -1; break;
  }
  i++;
   
  // huge discovery!!! send 1 write() statement per loop. trying second one, blocks
  // processing code, @ runtime, , doesn't reset arduino!
  ///myport.write("servoy 20\n");

  delay(900);
}


here arduino code:
code: [select]

/**
* v1.00.a
*
* sending characters , words, via terminal serial monitor, arduino , displaying
* them on attached byvac bv4618 serial interface. byvac bv4618 attached negative
* black lcd display hd44780 4x20 (ymfc-c2004).
*
* modified original example file removing looked keypad instruction.
*
* circuit:
*
*   - byvac bv4618, hd44780 lcd controller serial, rs232 , i2c interface,
*       http://doc.byvac.com/index.php5?title=product_bv4618
*
*   - lcd display hd44780 4x20 black neg backlight (ymfc-c2004),
*       http://www.ebay.co.uk/itm/lcd-display-hd44780-4x20-chr-20x4-black-neg-backlight-/170440872374?pt=bauteile&hash=item27af1151b6
*
*   - power arduino, vcc= +5.0v (red wire) , gnd (black wire),
*   - 2.7kohm resistor between lcd's gnd (1st pin) , vo (3rd pin),
*   - ard.pwm.pin #4 - ard's tx pin, bv4618's rx pin, white wire,
*   - ard.pwm.pin #5 - ard's rx pin, bv4618's tx pin, green wire,
*
* usage:
*
*   settings:
*
*     - terminal program of choice, arduino ide's serial monitor, must set to:
*
*         - baud rate ........... 57,600
*         - line termination .... newline
*
*     - if instructions sent via serial port program, processing, than
*       lines must terminated '\n' or '\r'. example, these ones:
*
*         "servox 1375\n"  or  "sry 12\r"
*
*       space or ' ', not used delimeter. space ' ' treated other character.
*
*   input:
*
*     - type in: 'test1' (without quotes), press return. line termination must bed done
*       with lf , cr. if want use ' ' or char(32) line termination, must change
*       code.
*     - output above 'test1,' (without quotes), etc. outputs follow
*       each other like: test1,test 2,test3,test4 etc.
*
*       this arduino sketch made work processing sketch:
*
*         processing_serial_write_command_line_1
*
* updates:
*
*   15:37 9.5.12 - v1.00.a = initial code.
*
*/
#include <bserial.h>
#include <bv4618_s.h>

#define rxpin 5
#define txpin 4

bv4618_s lcdbyvacserial(rxpin, txpin);

boolean blnlcdrefresh = true;

char incomingchar = 0;      // arduino receiving incoming serial data int variable.

const int serial_input_buffer_size = 32;     // input line lenght 31 characcters.
char arrchrbuffer[serial_input_buffer_size];

int i;

void setup()  {

  // 9600 baud, 0 delay, '*' ack
  lcdbyvacserial.begin(9600,50,'*');
  // n.b. puts() arrays of char-s, or char*, not sting-s, putch() individual char-s.
  // 4 x 20 display
  lcdbyvacserial.puts("\e[4l\e[20c");
  // clear screen, needs delay
  lcdbyvacserial.puts("\e[2j"); delay(50); 
  // cursor on, static underline.
  lcdbyvacserial.puts("\e[?25h");
   
  // start our serial port, configured our xbee devices 38400 bps.
  serial.begin(57600);
}

void loop() {

  // print lcd if there new stuff show. otherwise lcd characters blink anoyingly.
  if (blnlcdrefresh) {

    ///lcdbyvacserial.puts("awaiting input:");
    // set lcd's cursor line 2, column 1.
    ///lcdbyvacserial.puts("\e[2;1h");
    blnlcdrefresh = false;
  }

  // if character received, show on lcd display.
  while (serial.available() > 0) {

    // read received bytes:
    incomingchar = serial.read();    // incoming char become int ascii ordinal.
    // write character array characters, except line termination ones, like: lf
    // , cr.
    if (incomingchar != '\n' && incomingchar != '\r') {
     
      arrchrbuffer[i] = arrchrbuffer[i] + incomingchar;
      i++;
    } else {
     
      // break enables stucking of multiple commands together, like: "srx 640\nsry 480\n"
      // individual commands need separated '\n' characters. when first '\n' met,
      // character array extracted point processed. rest of multi-
      // command still in serial buffer , extracted in next loop. voila!
      break;
    }
  }
 
  // lf , cr used line termination.
  if (incomingchar == '\n' || incomingchar == '\r') {
   
    // output lcd.
    // n.b. puts() arrays of char-s, or char*, not sting-s, putch() individual char-s.
    lcdbyvacserial.puts(arrchrbuffer); lcdbyvacserial.putch(',');
    // move lcd's cursor 1 place.
    ///lcdbyvacserial.puts("\e[1a");
    // set lcd's cursor line 2, column 1.
    ///lcdbyvacserial.puts("\e[2;1h");
   
    // after printing lcd, reset auxiliary variables.
    (int j=0;j < serial_input_buffer_size;j++) { arrchrbuffer[j] = '\0'; }
    = 0; incomingchar = '\0';
  }
 
  // catch breath.
  delay(100);                      // wait bit.
}


please have look.

code: [select]
  if (blnlcdrefresh) {
   blnlcdrefresh = false;
  }

what purpose of this? if variable contains false, set to true. otherwise, leave @ true.

code: [select]
      arrchrbuffer[i] = arrchrbuffer[i] + incomingchar;
why adding character character in array? seems me should replacing character in array.

code: [select]
    (int j=0;j < serial_input_buffer_size;j++) { arrchrbuffer[j] = '\0'; }
once again, appears not understand string null terminated. not necessary fill whole array nulls.

code: [select]
 
  // catch breath.
  delay(100);                      // wait bit.

the arduino not breathing hard. rid of this!


Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > Does one Need to Slow Down Processing in Order for Arduino to Catch Up?


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

listen to event