Problem on serial communication with Lazarus (free pascal)

Hi all,

After a long time, i decided to go ahead to develop a program to read the data from different sensors installed in my arduino board, based on the use of Pascal on Lazarus open source.

I located also this component to establish the serial communication between arduino and lazarus: http://wiki.lazarus.freepascal.org/5dpo

How to use it is explained in this webpage: EDITED: http://www.laboelectronique.be/english/laz_serial_ang.html

and here is the example code for a simple Lazarus application: http://www.laboelectronique.be/fich_joints/serial_laz_file.zip

and this is the code proposed in this webpage to have a reply from the Arduino:

int incomingByte = 0;
void setup()
{
  Serial.begin(9600);
  Serial.println("Arduino Serial Link");
  Serial.println("connected!") ;
}

void loop()
{
  if(Serial.available()>0)
  {
    incomingByte=Serial.read();
    Serial.print(char(incomingByte));
  }
}

Now, my problem is that when the monitor terminal at the simple program returns something, it is divided in different lines. For example, the two sentences included in the Setup() section of the arduino code appear on the terminal, but divided in different lines like this:

Arduino Seria l Link connect ed!

Any idea about how could i have each sentence contained in one "Serial.println()" command into a unique line?

Thanks!

(long time ago delphi user)

The lazarus serial package (LSP) seem to insert a return as the Arduino does not send it.

possible causes:

  • communication is slow and if the LSP doesnt receive any char it might do an
    ==> try using Serial.begin(115200);

  • There could be an internal buffer in the LSP that overflows. Try sending a realy long text e.g. 100 chars.
    Serial.println("1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ");
    and look what you get

  • The application as shown by the link has a rather small textbox. That can insert linebreaks too (in theory).

sofar some ideas,
Rob

Thanks robtillaart,

I am also a Delphi user, but long time ago....

About the idea of increase the bauds rate i will try it to see what happens. And about the memo component, i am practically usere that this is not the problem. I create my own application, and it has a really wide memo component, but the problem persist. So i will try increasing the velocity on communications.

Thanks for the idea!

ok,

I tried to increase the bauds rate on the serial port communication to 115200 bauds and now there is partially solved the problem.

However, i sended a very long number, as long as: "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

It was partially divided sometimes. To solve partially it, i made a change on one of the properties of the Memo component in Lazarus... WordWarp option sould be FALSE, and ScrollBars to ssAutoBoth, or, at least, ssAutoHorizontal or ssHorizontal to allow to increase the Memo wide.

I will explore if changing some other options i could solve finally the problem.

Thanks robtillaart for your recommendations!