Forum > Embedded - AVR

How to get data from Arduino

(1/1)

microguy:
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:
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

microguy:
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:

--- Quote from: microguy on May 31, 2021, 05:08:47 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.
--- End quote ---
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.


--- Quote from: microguy on May 31, 2021, 05:08:47 am ---I see that Synapse is one-way communication.  I hope it is not true.
--- End quote ---
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


--- Quote from: microguy on May 31, 2021, 05:08:47 am ---I did not want to download another serial application.
--- End quote ---
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.

Navigation

[0] Message Index

Go to full version