Recent

Author Topic: Lazarus control Arduino Nano with Enc28J60  (Read 25159 times)

microguy

  • New Member
  • *
  • Posts: 49
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #30 on: June 27, 2017, 09:37:22 pm »
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

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #31 on: June 29, 2017, 03:17:37 pm »
I 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.

I 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.
« Last Edit: June 29, 2017, 03:20:26 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

microguy

  • New Member
  • *
  • Posts: 49
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #32 on: July 03, 2017, 05:00:25 am »
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

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #33 on: July 03, 2017, 12:40:46 pm »
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.
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.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Almir.Bispo

  • Jr. Member
  • **
  • Posts: 91
  • CSV Comp DB is the Best NoSQL
    • CSV Comp DB (NoSQL)
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #34 on: July 03, 2017, 06:28:22 pm »
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][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.    SdpoSerial1.open;
  4.   SdpoSerial1.Active := true;
  5.    SdpoSerial1.WriteData('This is my string ');
  6.    SdpoSerial1.Active := false;
  7.   SdpoSerial1.close;
  8. end;
  9.  

To read file from COM,just do on OnRXdata event (select SdpoSerial1 and look object Inspector,tab event,double click)
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SdpoSerial1RxData(Sender: TObject);
  2. begin
  3. form1.caption:= SdpoSerial1.ReadData;
  4. end;                                
  5.  

If can't do it,call me by email
http://adltecnologia.blogspot.com.br
CSV Comp DB Developer {Pascal Lover}

jb007

  • Full Member
  • ***
  • Posts: 145
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #35 on: August 25, 2017, 07:05:11 pm »
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!
to DIY or not to DIY

donagin

  • Newbie
  • Posts: 5
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #36 on: February 02, 2021, 06:07:58 pm »
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

  • Hero Member
  • *****
  • Posts: 6676
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #37 on: February 02, 2021, 06:57:43 pm »
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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ccrause

  • Hero Member
  • *****
  • Posts: 845
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #38 on: February 02, 2021, 08:39:32 pm »
Did anyone figure out how to make this work in linux?
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.
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

  • Newbie
  • Posts: 5
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #39 on: February 06, 2021, 03:05:48 am »
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

  • Newbie
  • Posts: 5
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #40 on: February 06, 2021, 05:05:42 am »
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

  • Hero Member
  • *****
  • Posts: 6676
Re: Lazarus control Arduino Nano with Enc28J60
« Reply #41 on: February 06, 2021, 10:28:25 am »
Perhaps 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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018