Recent

Author Topic: How to get data from Arduino  (Read 2623 times)

microguy

  • New Member
  • *
  • Posts: 49
How to get data from Arduino
« on: May 30, 2021, 02:12:16 am »
I am using synaser as a serial. I was able to send data to Arduino from Lazarus, but I could not figure out how to get data from Arduino. I have several Hall Effect Sensors and buttons on Arduino Nano. I was able to get data using Serial Monitor from Arduino IDE on Arduino Nano. Can someone give an example code that we can read data from D4 to D12 that I use for buttons and Hall Effect Senors.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: How to get data from Arduino
« Reply #1 on: May 30, 2021, 03:20:06 pm »
You mays send data periodically from Arduino side and parse input on pc side, or send a request for specific data, parse that request on Arduino side, and send reply from Arduino which again needs parsing on pc side.

Your boolean data can be packed into bytes or words on Arduino side and then unpacked on pc side, or you can have a single request for each boolean data. It's up to you.

Not exactly what you need, but you might find necessary bits of information here: https://wiki.freepascal.org/Arduino

If you need something more standard (so other devices can talk to your Arduino), then it would be a good idea to use something like MODBUS RTU:
https://sourceforge.net/projects/mbutils/?source=navbar
https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

microguy

  • New Member
  • *
  • Posts: 49
Re: How to get data from Arduino
« Reply #2 on: May 31, 2021, 05:08:47 am »
Avra,

I went to the link that you gave me. I am trying to understand how to PC get data from Arduino. I do find an example for PC to send the data to Arduino. But I could not find any example PC to receive data from Arduino from Synapse. I see that Synapse is one-way communication.  I hope it is not true. I did not want to download another serial application.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: How to get data from Arduino
« Reply #3 on: May 31, 2021, 08:54:42 am »
I went to the link that you gave me. I am trying to understand how to PC get data from Arduino. I do find an example for PC to send the data to Arduino. But I could not find any example PC to receive data from Arduino from Synapse.
I said for that link "Not exactly what you need, but you might find necessary bits of information". You need to dig a little in that link. At the bottom of the linked page there is "External Resources" section. You need to follow first 2 links. Third message in first link will point you to http://wiki.lazarus.freepascal.org/Hardware_Access#Serial_Communication where you will find a SynaSer receive demo, and second link has a zip file with complete send/receive SynaSer application that you can study. Have in mind that Synaser is not async and event based, so if you want that then for your GUI apps you should better try TLazSerial which internally uses SynaSer. Otherwise be prepared to learn multithreading development for anything more then simple communication.

I see that Synapse is one-way communication.  I hope it is not true.
No, it is not true. You also need to learn to read official documentation and navigate through source code. Nobody else can do that for you. Here is a free tip: http://synapse.ararat.cz/doc/help/synaser.TBlockSerial.html

I did not want to download another serial application.
It's up to you. MODBUS is standard and robust protocol which handles everything you need, including error checking and rejecting bad messages. Some much more experienced programmers then you have done the hard work. If you want to reject that and implement everything on your own then you need to be much more proactive then currently.
« Last Edit: May 31, 2021, 09:12:47 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018