Lazarus control Arduino Nano with Enc28J60 lazarus / 78-Embedded - AVR ---------------------------------------------------------------------- microguy · 2017-05-15 03:16 This is my first time to post. Hope this is right place to post about control Arduino. I would like to use Lazarus with Arduino. My computer is window 10. I just download Lazarus and got it working. I have been use Delphi 5 for a long time.  Now I would like to learn how we can control Arduino with several LEDs and servos. I have google it but still not understand how to use. I understand we need to download serial port communication. Which one should we use? I would like to use USB port. Someone mention to use Synaser. I am not sure How do we use it.  Is there a step by step instruction how we add serial componet on Lazarus? Is there a webpage where I can download and run it? I just want to control Arduino with several LEDs at first then I will add some servos. Please don't give me the link to YouTube. I am very hard of hearing and having hard time to understand video. I am 58 years old. ---------------------------------------------------------------------- dogriz · 2017-05-15 06:03 There are a few things you need to be aware of: Arduino Nano is Atmel Microcontroller (https://en.wikipedia.org/wiki/ATmega328), you can easily program it using C language. On Arduino website there are enough resources for start (look for some examples about Ethernet) (https://www.arduino.cc/en/Reference/HomePage) ENC28J60 is not compatible with Arduino Ethernet Library (it is for WS5xxx), so you need other library to program Arduino as TCP client or server. Here are some resources: http://www.geeetech.com/wiki/index.php/Arduino_ENC28J60_Ethernet_Modul e https://github.com/jcw/ethercard http://www.homautomation.org/2014/10/27/how-to-choose-the-right- library-to-add-ethernet-enc28j60-to-your-arduino/ https://github.com/ntruchsess/arduino_uip And then you can try communicating with it using TCP (or UDP) (eg. Lazarus + LNet or Synapse). ---------------------------------------------------------------------- Thaddy · 2017-05-15 06:38 @dogriz No need for C. FPC supports AVR, and afaik it can target the ATMega328 directly. It is also possible to control an ATMega328 from any of the Lazarus supported platforms with software written for that platform. You just have to build a ppcrossavr compiler using the GNU C toolchain for AVR to compile for the ATmega328 itself. So: - you can write controlling software for atmega with Lazarus on e.g., linux.mac, windows - you can target the ATMega328 directly with an FPC cross compiler. http://wiki.lazarus.freepascal.org/AVR_Programming http://wiki.lazarus.freepascal.org/AVR (ignore the warning: the current state works) ---------------------------------------------------------------------- avra · 2017-05-15 07:11 For serial port communication in your Lazarus application take a look at these links: http://wiki.lazarus.freepascal.org/Hardware_Access#Serial_Communicatio n http://forum.lazarus.freepascal.org/index.php/topic,36523.msg245030.ht ml#msg245030 You will find small examples to get you started, but first you need to decide which serial lib/component to use. Wiki will help you with the choice. Have in mind that Synaser is not event based. Others are. Any of them will be able to talk to Arduino over USB virtual COM port. For developing Arduino and other ATMEL AVR microcontrollers in Pascal take a look at these links: http://forum.lazarus.freepascal.org/index.php/topic,30960.0.html http://forum.lazarus.freepascal.org/index.php/topic,32816.msg211887.ht ml#msg211887 http://forum.lazarus.freepascal.org/index.php/topic,24665.msg196700.ht ml#msg196700 http://forum.lazarus.freepascal.org/index.php/topic,29128.msg183767.ht ml#msg183767 Using forum search would bring you much more links. You are asking for serial communication, but your topic mentions ENC28J60 which can be used for Arduino TCP or UDP networking communication. If you decide to go that path instead then you can use Synapse, Dataport, Indy and several other networking communication libraries available for Free Pascal and Lazarus. ---------------------------------------------------------------------- dogriz · 2017-05-15 07:27 @Thaddy I wasn't aware of that. Thanks for the info Thaddy. But I'm not sure how to control ENC28J60 shield with FPC. ---------------------------------------------------------------------- microguy · 2017-05-21 06:03 Avra, Thank you for the information and links. I will try find time to work on it next week. Right now I would like to try use Ardunio UNO to make several LEDs to turn on and off from computer. In future I would like to control four or five Arduino with single one com or something. They are about ten feet apart each other. I will use it for HO train. I would like to control about 25 turnout, several RFID,and lot of LEDs. I thought I could use IC2 but it is my understand it will not work if it is long distance. I rather not to use Wi-Fi. I was thinking to use  ENC28J60 with Nano. Can we use five ENC28J60 with Nano and switch hub to computer with FPC. If we can then how do we do it? ---------------------------------------------------------------------- Thaddy · 2017-05-21 06:47 Quote from: dogriz on May 15, 2017, 09:27:30 am@Thaddy I wasn't aware of that. Thanks for the info Thaddy. But I'm not sure how to control ENC28J60 shield with FPC. Usually there is some sort of C header file available with a description of e.g. the pin layout, enumerations etc. These are easily translated to Pascal with h2pas. ---------------------------------------------------------------------- Thaddy · 2017-05-21 10:16 Quote from: avra on May 15, 2017, 09:11:37 amYou are asking for serial communication, Synaser (part of synapse) works. I guess the other X platforms will also work. I used the ATMega328 blink example with trunk to test both native and interfacing code on a RPi3 and Windows. I made some changes, but if anyone is interested I will post it later (nothing new, just different). ---------------------------------------------------------------------- avra · 2017-05-21 16:38 Quote from: microguy on May 21, 2017, 08:03:01 amI would like to control four or five Arduino with single one com or something. They are about ten feet apart each other.You can control them from any computer with serial port (yes, including Raspberry Pi) if you use some single master multi slaves protocol. On electrical level it can be RS485 - either 4 wires full duplex or 2 wires half duplex. So you will need 1 RS232-RS485 convertor for your computer, and one for each Arduino. Make sure that your Arduinos have RS232 and not only USB, otherwise you will need different level convertor like TTL-RS485 or USB-RS485). On protocol level it can be MODBUS RTU or ASCII, some other protocol, or even your own if you want to keep it simple. To be able to talk to everyone, all sides need to have unified electrical connection level and talk the same protocol. There are MODBUS libraries available for FPC and as Arduino C libraries. E-Lab AvrCo Pascal compiler has it, and I think that I have seen one for mikroPascal. Your board will have different MODBUS adresses, and when your PC asks for data from board 1 with address 1, only board 1 will answer. Then you ask for data from other boards one by one. QuoteI thought I could use IC2 but it is my understand it will not work if it is long distance.I2C can have extended range with little electronics, but how would you interface it to PC? You would need something like BusPirate or custom hardware, so I would not recommend it. Keep I2C just for connecting Arduinos to their local sensors. QuoteI was thinking to use  ENC28J60 with Nano. Can we use five ENC28J60 with Nano and switch hub to computer with FPC. If we can then how do we do it?Unlike W5100 and similar, ENC28J60 is a very simple chip capable to talk just UDP. However some libraries extend it and add TCP/IP layer and other popular protocols. You can talk with ENC28J60 from E-Lab AvrCo pascal, mikroPascal and Arduino C. All boards and your master PC should be connected to a ethernet switch. Your PC would then just need to call boards one by one in  a loop and request data from them. You can use MODBUS TCP protocol for ethernet, but you have very limited resources so you might want to keep it simple and light and instead implement your own request/reply data exchange protocol. ---------------------------------------------------------------------- avra · 2017-05-21 16:51 Quote from: microguy on May 21, 2017, 08:03:01 amI will use it for HO train. I would like to control about 25 turnout, several RFID,and lot of LEDs.OK, if by HO train you mean model train, then I have made a little research and found that DCC is a standard for model railways. There are even several DCC implementations for AVRs so you might want to take that route if you don't want to be a lone island and be able to take benefit of already existing DCC software and hardware (hint: type dcc railway on ebay). http://opendcc.sourceforge.net/ http://mrrwa.org/ http://www.dccwiki.com/DCC_Software http://forum.lazarus.freepascal.org/index.php/topic,24388.15.html ---------------------------------------------------------------------- microguy · 2017-05-28 21:58 I am lost. Right now I want to start begin to make Lazarus working with Arduino Mega on USB. I just want to be to turn on and off on several LEDs. I don't know where to start or where we can find step by step.  Is there a tutorial where I can lean how to use LAzarus with Arduino Mega? ---------------------------------------------------------------------- avra · 2017-05-29 00:43 Quote from: microguy on May 28, 2017, 11:58:53 pmI am lost.OK, then to get some confidence do the most simple thing first. Connect led to your Arduino using proper resistor. Light a led on and off using Arduino IDE for writing a very simple C program. Flash it to your Arduino and verify that the led blinks. After that use Arduino IDE to write another C program that listens to serial port to change led state with serial "on" and "off" commands. To test it use some terminal software, connect to proper serial port (check that port speed and other settings match Arduino port settings), and type on and off commands. Verify that Arduino led obeys your commands. For all this you can find a nice tutorial here: http://www.chrisbrand.co.za/2013/06/30/arduino-serial-port/ All you need to do now is to make a Lazarus application that will send serial commands to Arduino like you did previously by hand with your terminal. Quote from: microguy on May 28, 2017, 11:58:53 pmIs there a tutorial where I can lean how to use Lazarus with Arduino Mega?There is not such tutorial that I am aware of, but your question can be split into two parts: 1) Make Arduino part. That's what I have just shown you how to do. 2) Make Lazarus part. This follows... For Lazarus part make a form with 2 buttons, include Synaser unit and add Synapse package as a new requirement to your project. In OnClick event of both buttons put something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  ser: TBlockSerial;begin  ser := TBlockSerial.Create;  try    ser.Connect('COM1'); // write here your USB virtual COM port number    Sleep(250);    ser.config(9600, 8, 'N', SB1, False, False);    ser.SendString('on' + #13#10); // button 2 should have 'off' here  finally    ser.free;  end;end; Compile. Enjoy. Have fun... ---------------------------------------------------------------------- jb007 · 2017-05-29 19:07 Nice topic! Very understandable and clear! ---------------------------------------------------------------------- avra · 2017-05-30 08:40 Quote from: jb007 on May 29, 2017, 09:07:04 pmNice topic! Very understandable and clear! You are so kind, so I felt motivated and created an initial Arduino wiki page:  http://wiki.lazarus.freepascal.org/Arduino Everyone feel free to expand and improve it. ---------------------------------------------------------------------- microguy · 2017-06-24 05:56 Avra, Sorry for taking so long to respond. I was travel a lot for my company. I fiinlly be home few days. Anyway I got Arduino IDE working with Arduino Mega to turn on and off LED. Now I trying to get small Lazarus program that I create a button for one and another button for off. I think I am not sure how to use serial code and where do we put in Lazarus. Is there somewhere I can get more tutor on serial port on Lazarus or where I can download and already have source code and exe file that I can run? Reid ---------------------------------------------------------------------- avra · 2017-06-24 19:50 Quote from: microguy on June 24, 2017, 07:56:26 amNow I trying to get small Lazarus program that I create a button for one and another button for off. I think I am not sure how to use serial code and where do we put in Lazarus.Everything is already in the wiki and it should be beginner friendly. Please try it and report what is not clear so that we can eventually improve wiki. You can find there lazarus example with 2 buttons sending on and off serial commands to Arduino via synapse/synaser serial lib. And there is also Arduino code that you compile in Arduino IDE that responds with lighting LED on/off as a response to these serial commands. You need to have a valid serial connection and find your serial port number to replace COM1 in the example if needed. It is advised to first establish a serial link with Arduino through some simple serial terminal on your pc, and then light LED on and off by typing on and off commands to the terminal. Then, and only after that, when you have established a successful serial communication, you try with Lazarus. That way you go step by step and we know that you have serial working before trying lazarus example. ---------------------------------------------------------------------- microguy · 2017-06-25 05:03 Avra, I went to wiki and I am not sure if I got the right place. http://wiki.freepascal.org/Arduino Click on Minimal Lazarus Synaser serial example. I still can't find sample or instruction how to install it on my Win10. I am very frustrated and can't get it working. You mention there is step by step. I don't see it. Reid ---------------------------------------------------------------------- McStep · 2017-06-25 05:58 May be this thread will helb you, as it hleped me. http://forum.lazarus.freepascal.org/index.php?topic=20481.0 The installation procedure is explain in the beginning of that thread. https://github.com/JurassicPork/TLazSerial This ist where you can get the lib mentioned. It now works for me. I had some trouble with using chart for my sensor data caming from the nano together with the serial lib of jurassic pork, but in Laz 1.8 everything seems to do what it should. Stephan ---------------------------------------------------------------------- avra · 2017-06-25 16:14 Quote from: microguy on June 25, 2017, 07:03:48 amI went to wiki and I am not sure if I got the right place. http://wiki.freepascal.org/Arduino Click on Minimal Lazarus Synaser serial example. I still can't find sample or instruction how to install it on my Win10. I am very frustrated and can't get it working. You mention there is step by step. I don't see it.Wiki says this:QuoteWe will use Synaser from Synapse library in this example. Create Lazarus application with one form and two buttons. Include Synaser unit and add Synapse package as a new requirement to your project. In OnClick event of both buttons put something like this:Did you follow it? Did you download and install Synapse library into Lazarus? What Lazarus/FPC version you have? Did you create Lazarus application with one form and two buttons? Did you include synaser unit and added Synapse package as a new requirement to your project? If you skipped any of these steps then it is no wonder why you can't make it work. If you don't know how to do any of these steps then you need to learn how to do these things with Lazarus first. Without that you really can't follow wiki instructions. You need to be more descriptive so that we know what is the problem, and be able to assist you. ---------------------------------------------------------------------- avra · 2017-06-25 16:17 Quote from: McStep on June 25, 2017, 07:58:48 amMay be this thread will helb you, as it hleped me. http://forum.lazarus.freepascal.org/index.php?topic=20481.0 The installation procedure is explain in the beginning of that thread. https://github.com/JurassicPork/TLazSerial This ist where you can get the lib mentioned.No sorry. Wiki has example with Synapse/Synaser library, and not with TLazSerial (which is a fork of synaser btw). That is not the same lib and wiki example will not work with TLazSerial out of the box. It works with Synapse/Synaser and that is what should be used. ---------------------------------------------------------------------- microguy · 2017-06-25 22:39 Did you follow it? I think so.... Did you download and install Synapse library into Lazarus? Yes I download synapse40.zip create a new folder for synapse  c:\lazarus  (that is where main program is.  download and unzip to c:\lazarus\synapse  I installed package from from c:lazarus\snapse\source\lib\laz_synapse.lpk What Lazarus/FPC version you have? I have Lazarus IDE v1.6.4 Did you create Lazarus application with one form and two buttons? Yes I did. Did you include synaser unit? I assume you mean to add synaser.pas on it. I went to project Inspector to add on it. here is my source codes. procedure TForm1.Button1Click(Sender: TObject); var   ser: TBlockSerial; begin   ser := TBlockSerial.Create;   try     ser.Connect('COM5'); // write here your USB virtual COM port number     Sleep(250);     ser.config(9600, 8, 'N', SB1, False, False);     ser.SendString('on'); // button 2 should have 'off' here    finally     ser.free;   end; end;    I don't see which pin we can turn it on. Am I missing something? Reid ---------------------------------------------------------------------- microguy · 2017-06-25 23:08 One more question  I am wondering why not we use tlazserial package. It already have componet. Is it easier to use it than synapse? what is the difference and pro / con to use it. Reid ---------------------------------------------------------------------- McStep · 2017-06-26 03:48 Other struggled with the communication too. Big Dan had some success an his blog migth be of interest. https://bigdanzblog.wordpress.com/2014/11/06/serial-communications- between-a-pc-and-an-arduino-using-lazarus-free-pascal/ Hope it helps. Stephan ---------------------------------------------------------------------- avra · 2017-06-26 10:13 Quote from: microguy on June 26, 2017, 12:39:01 amDid you create Lazarus application with one form and two buttons? Yes I did.Can you compile without errors? Your button1 seams to have proper OnClick code. Did you type the same code for button2 OnClick event but just changed Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ser.SendString('on');to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ser.SendString('off');as code comment says? Is your Arduino really on COM5 as your code shows? If everything compiles then you should have a working application that sends 'on' and 'off' serial commands to COM5 when you press button1 and button2. That is all that your Lazarus application  needs to do in this simple demo. QuoteI don't see which pin we can turn it on. Am I missing something?Lazarus application just sends simple 'on' and 'off' commands. Arduino needs to interprete these commands and do some actions. For this you need to compile and download Arduino application into your board. Wiki gives the code and provides link to detailed step by step instructions. You need to confirm that this was a success. If it was, then your Arduino board now has proper firmware. If you attached leds with proper resistors everything is now ready for testing. QuoteTo test it use some terminal software, connect to proper serial port (check that port speed and other settings match Arduino port settings), and type on and off commands. Verify that Arduino led obeys your commands. For all this you can find a nice tutorial here: http://www.chrisbrand.co.za/2013/06/30/arduino-serial-port/If your Arduino board lights led on when you type in your terminal 'on' command (without quotes), and lights led off on your 'off' command, then you have a working communication and everything is ready for your lazarus application. Please confirm if you have this step working. If you have, and if you did everything as explained then you should also have a lazarus application buttons working too. Please report back... ---------------------------------------------------------------------- avra · 2017-06-26 10:27 Quote from: microguy on June 26, 2017, 01:08:58 amOne more question  I am wondering why not we use tlazserial package. It already have componet. Is it easier to use it than synapse? what is the difference and pro / con to use it.Although I have started that wiki page, that is not my property and everyone is free to expand it. If someone wants to explain how to do the same with LazSerial then be my guest. That is the whole purpose of wiki pages. Contributions are simple to add. Anyway, if you search the forum you will be able to find examples of LazSerial and DataPort components and try to adapt them for your purpose if you wish. The reason why I didn't use visual components is that they are ok for simple use, but sooner or later your GUI will suffer because your application has single thread which is used for GUI updating, mouse response and your serial communication. Since they are all in the same que if one of them is slow (usually serial) then others suffer. This reflects as erratic mouse movement and non responsive application from time to time. This problem is solved by adding a separate communication thread which then syncs with your GUI application when needed. That brings back the responsivity to your application, although is a very big step for beginners. Anyway, when you write a separate communication thread then visual async serial components are not of much help, and sync serial lib like Synapse/Synaser is the right way to go. I hope my reasoning is more clear now. ---------------------------------------------------------------------- avra · 2017-06-26 10:35 Quote from: McStep on June 26, 2017, 05:48:06 amBig Dan had some success an his blog migth be of interest.His work is already honored at the end of the wiki in 'Resources' section. ---------------------------------------------------------------------- microguy · 2017-06-27 02:31 When I click on 'on' button or 'off' button. The led went stay on. When I click on 'off' button or 'on button again the led blink off then back to stay on. (fast blink) I couldn't find a way to click off button  to turn led off. Here is my codes on arduino ide: int led = 13; // Pin 13 void setup() {     pinMode(led, OUTPUT); // Set pin 13 as digital out     // Start up serial connection     Serial.begin(9600); // baud rate     Serial.flush(); } void loop() {     String input = "";     // Read any serial input     while (Serial.available() > 0)     {         input += (char) Serial.read(); // Read in one char at a time         delay(5); // Delay for 5 ms so the next char has time to be received     }     if (input == "on")     {         digitalWrite(led, HIGH); // on     }     else if (input == "off")     {         digitalWrite(led, LOW); // off     } } Here is Laz code procedure TForm1.Button1Click(Sender: TObject);   var     ser: TBlockSerial;   begin     ser := TBlockSerial.Create;     try       ser.Connect('COM5'); // write here Arduino COM port number (on linux it's something like '/dev/ttyUSB0')       Sleep(250);       ser.config(9600, 8, 'N', SB1, False, False);       ser.SendString('on'); // button 2 should have 'off' here     finally       ser.free;     end;   end; procedure TForm1.Button2Click(Sender: TObject);   var     ser: TBlockSerial;   begin     ser := TBlockSerial.Create;     try       ser.Connect('COM5'); // write here Arduino COM port number (on linux it's something like '/dev/ttyUSB0')       Sleep(250);       ser.config(9600, 8, 'N', SB1, False, False);       ser.SendString('off'); // button 2 should have 'off' here     finally       ser.free;     end; end; There is no error message on both Arduino IDE and Lazarus. Am I missing something?  By the way if I unplug USB that connect to Arduino. The Led went off and plug back in and led still off. When I click on off button and led went on and stay on. ---------------------------------------------------------------------- avra · 2017-06-27 08:48 Can you change "delay(5)" into "delay(20)" in Arduino code and try again (although it should work with both values)? Can you also try to put Sleep(1000) before both "ser.Free" and try again? You still haven't tried with the terminal. We need that to eliminate if you are having a problem on Lazarus application side or on Arduino side. Try any terminal which can send whole ascii message at once (like HTerm or Bray Terminal), connect it to COM5 and then type 'on' (without quotes) and send to Arduino, and then 'off'. Report if your Arduino led stay on and off after these two commands, or you still have short flash with off command. ---------------------------------------------------------------------- McStep · 2017-06-27 13:51 @avra so you would put the code into the wiki, if I had samples for example from reading sensors (alcohol, CO2 etc)? I would like to keep my stuff on TLazSerial. @microguy is there a kind of steady reconnect? Arduino Uno restarts on every reconnect I think. ---------------------------------------------------------------------- avra · 2017-06-27 15:28 Quote from: McStep on June 27, 2017, 03:51:51 pm@avra so you would put the code into the wiki, if I had samples for example from reading sensors (alcohol, CO2 etc)? I would like to keep my stuff on TLazSerial.You login to wiki with your forum login credentials. Then you can edit and expand the wiki. I added basic led on/off example with Synaser. You are free to add sensor examples with TLazSerial. ---------------------------------------------------------------------- microguy · 2017-06-27 19:37 Wow I learn lot. I did change the speed on Arduino from 5 to 20. Still not working. Then I add Sleep (1000); before ser.free; Still not working. You suggest me to use terminal. I use Bray Terminal. Nice program. It is my first time to use it. I didn't run Lazarus while using terminal. I send no and yes to Arduino and it did turn on and off . No light blink. When I use Lazarus program, I didn't run terminal on it. When I click on and light went on just fine and no blink at first. When I click off and it did blink off once then back stay on. When I click on again it did blink and stay on. I went back to use terminal. Send on and it went on. Send again on and it did not blink. So seem something wrong with Lazarus program or synaser. I tried to use terminal with Lazarus program.  It didn't work and sometime Terminal crash or freeze. I send see anything comes up on terminal when I use Lazarus program. I did use USB plug to Arduino and unplug and still same. I don't know if I am doing the right way to use terminal with Lazarus. ---------------------------------------------------------------------- avra · 2017-06-29 13:17 Quote from: microguy on June 27, 2017, 09:37:22 pmI send no and yes to Arduino and it did turn on and off.This tells us that Arduino part is correctly interpreting commands, your serial link is fine, and you succeeded in using terminal correctly. Looks like Lazarus part is having problems. I will check to see what's wrong. Quote from: microguy on June 27, 2017, 09:37:22 pmI tried to use terminal with Lazarus program.  It didn't work and sometime Terminal crash or freeze.This is normal. Using serial port is exclusive, and normally only one application can talk to single COM port at a time. This can be solved in code by checking first if COM port is available before using it, but such simple demo didn't bother with details. More complex demo should cover that, if someone writes it. Alternative to this is to study Synaser documentation on your own and always use defensive programming techniques, which means to always assume that something can fail and program ahead against failures so your code catches all possible runtime anomalies. ---------------------------------------------------------------------- microguy · 2017-07-03 03:00 Arduino IDE is working fine with me. I can turn the light on and off at no problem but I still can't figure out how to get Lazarus working with Arduino Mega board. I don't know what next. ---------------------------------------------------------------------- avra · 2017-07-03 10:40 Quote from: microguy on July 03, 2017, 05:00:25 amI can turn the light on and off at no problem but I still can't figure out how to get Lazarus working with Arduino Mega board.Sorry for the delay. I was a little busy. I have just simulated your environment by creating virtual COM3 and COM4 on my pc and pairing them internally. That way everything sent to COM3 shows on COM4 and vice versa. Lazarus application sends data to COM3, while terminal acts as Arduino and waits for data to show on COM4. Next I have followed the wiki and everything works as advertized. You can see that in attached screenshot. In short, when I press one button Lazarus demo application sends 'on' to COM3 which shows in terminal attached to COM4, and when I press the other button Lazarus demo application sends 'off' to COM3 which again shows correctly in terminal attached to COM4. I have attached this ProjectFollowingWiki.zip for you to try on your pc. Just remember to change COM3 in button click events to your COM port number. I have also made ProjectAlternative.zip with an alternative COM port creation and destruction. That might help if you have some strange and specific USB COM port. Try and report. I also advise you to update your USB COM driver to the latest you can find on the internet. ---------------------------------------------------------------------- Almir.Bispo · 2017-07-03 16:28 The solution is easy.I had made so many times.Just follow steps: 1)Install Lazarus 2)Download and Install 5dpo serial component http://wiki.freepascal.org/5dpo (*Lazarus IDE will be rebuild with Serial Component) 3)Create a Lazarus application.Put form,2 buttons and Serial component (on Tab 5dpo) 4)Confiure the COM ,baud rate of component SdpoSerial1.(object Inpector) Double click on button1 to open code editor and write code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin   SdpoSerial1.open;  SdpoSerial1.Active := true;   SdpoSerial1.WriteData('This is my string ');   SdpoSerial1.Active := false;  SdpoSerial1.close;end;  To read file from COM,just do on OnRXdata event (select SdpoSerial1 and look object Inspector,tab event,double click) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.SdpoSerial1RxData(Sender: TObject);beginform1.caption:= SdpoSerial1.ReadData;end;                                 If can't do it,call me by email http://adltecnologia.blogspot.com.br ---------------------------------------------------------------------- jb007 · 2017-08-25 17:05 Sadly, I noticed these posts just lateley... Sound good! Gonna read etc it next week! For now: have a nice weekend there's a party waiting! Kind regards! ---------------------------------------------------------------------- donagin · 2021-02-02 17:07 Did anyone figure out how to make this work in linux?  I have been trying to communicate with lazarus and an arduino (raspberry pi, mint on my laptop, etc) off and on for several years, and I keep giving up.  The arduino end is fine,  I can communicate arduino to arduino, or even arduino to other chips.  I can even bit- bang a serial communications protocol from scratch.  But I can't ever get lazarus to send a serial message that is intelligible on the other end.  I have tried synaser, sdpo, TLazSerial, etc.  Following this thread and the associated WIKI (thanks to all who built and helped), I have the arduino working.  Using Arduino's serial monitor, I can turn the light off and on.  I even echoed the messages to an LCD so I can see them as they come in.  Nothing echoable to the screen is coming in - but garbage is clearly being transmitted, as the TX and RX leds on the arduino light up when I try to press the on/off buttons.  BTW, my lazarus program is exactly the same as the example, and is using the same port that is working on arduino serial uploads and communication. Very frustrated - and if anyone has figured out how to make this simple example work, I would appreciate knowing how. ---------------------------------------------------------------------- MarkMLl · 2021-02-02 17:57 I use the standard serial.pp and have no problems at all. I'm not volunteering anything else since you say absolutely nothing about the sort of problems you're experiencing. MarkMLl ---------------------------------------------------------------------- ccrause · 2021-02-02 19:39 Quote from: donagin on February 02, 2021, 06:07:58 pmDid anyone figure out how to make this work in linux? Quote from: MarkMLl on February 02, 2021, 06:57:43 pmI use the standard serial.pp and have no problems at all. I'm not volunteering anything else since you say absolutely nothing about the sort of problems you're experiencing. I also use the basic low level serial unit of FPC with success with AVR controllers.  There are lots of other serial libraries/components, have a look at the wiki examples: https://wiki.freepascal.org/Hardware_Access#Serial_Communication Again, difficult to help if you don't describe your setup, code attempts and errors encountered. ---------------------------------------------------------------------- donagin · 2021-02-06 02:05 Sorry about the lack of details on the post - but I do believe I did specify the type of problems I was having.  Specifically I noted that after copying the exact code in the example and verifying the Arduino side with the serial monitor as suggested, the TX and RX lights on the Arduino light up when pressing the buttons on the Lazarus side (verifying some sort of transmission is occurring), but no ASCII recognizable data is coming through. Luckily, my department recently added a microcontroller programmer, and he looked at my code and identified the problem:  not enough time between initializing the port and attempting to write.  Perhaps my off-brand Arduino has a slower port.  Perhaps my 2011 computer has a slower port.  Adding a longer Sleep didn't seem to help, but the "alternate example" posted by avra initializing the port on form create did solve the problem.  Using this same strategy, I can also make the SDPO unit work just as it should.  I have made a simple bi- directional SDPO based program, and it is working well for me. Thanks for the help.  I know that troubleshooting on forums like this is a pain in the butt, but it really helps those of us that are trying very hard to break into a world that we were not trained to be in. -Don ---------------------------------------------------------------------- donagin · 2021-02-06 04:05 I have updated the wiki page with a bidirectional example based on SDPO.  Its a little more involved than the original example, but hopefully informative for someone like myself.  Those of you with much more experience should feel free to look it over and make any changes they see fit.  (Isn't that the point of a wiki?) -Don ---------------------------------------------------------------------- MarkMLl · 2021-02-06 09:28 Quote from: donagin on February 06, 2021, 03:05:48 amPerhaps my off- brand Arduino has a slower port. Or a faster crystal, or you're telling the Arduino IDE and libraries that it's the wrong kind of hardware. That's one reason why it's a good idea to start off on the traditional 1 Hz blink with any unknown device: I've seen "Arduino" boards shipped with this and flashing at 2 Hz at which point it stands to reason that all the delays- plus possibly also the BPS ("Baud") setting is wrong... hence https://github.com/MarkMLl/ping-arduino-loader MarkMLl