Problem with bilateral communication between Arduino and Processing

I am currently working on a project and I am using ardunio and processing. The problem is I have two servos and a lidar sensor both accessing the COMM3 serial port and then sending the data over to processing to display the values. The problem is if I have the code set up, only one will work at a time. If I have the Lidar running, it will display the values just fine. However, once I try to get the servos to function (through a video feed and a mouse) they cannot connect to the COMM3 port since it is in use from the lidar sensor. Is there any way to have them both function together? Thank you.

I can't make sense of your description at all.

How can servos be connected to a USB port?

If the servos and the Lidar are connected to an Uno then they are not using a COM port - only the Uno is using it.

If the Lidar does connect to the PC USB port (without needing an Arduino) then it should be on a different COM port.

Make a simple pencil drawing showing how you have things connected and post a photo of the drawing. Please DO NOT use Fritzing.

...R

The problem is I have two servos and a lidar sensor both accessing the COMM3 serial port

Nonsense. Servos can not access a COM port. I'm not aware of any LIDAR sensors that can, either.

So, you really need to try again. How many Arduinos are connected to the PC via serial ports?

Processing can talk to multiple serial ports at a time. Only one Arduino can be connected to a serial port.

Robin2:
I can't make sense of your description at all.

How can servos be connected to a USB port?

If the servos and the Lidar are connected to an Uno then they are not using a COM port - only the Uno is using it.

If the Lidar does connect to the PC USB port (without needing an Arduino) then it should be on a different COM port.

Make a simple pencil drawing showing how you have things connected and post a photo of the drawing. Please DO NOT use Fritzing.

...R

Let me rephrase. I have ardunio code running the initial setup. The lidar sensor reads the distance and sends it to the serial monitor. That then has to be sent over to processing using the serial library. Both the servos and lidar sensor are just connect to digital and analog pins on the ardunio itself. According to the code I have running in processing, it receives that data over COMM3. Since this is the case, processing can only read either just the lidar distance or just control the servos, not both. I have to just comment out either the lidar or servos to choose which one will work with processing. They issue is getting the data for both servos and the lidar sensor to go to processing at the same time.

PaulS:
Nonsense. Servos can not access a COM port. I'm not aware of any LIDAR sensors that can, either.

So, you really need to try again. How many Arduinos are connected to the PC via serial ports?

Processing can talk to multiple serial ports at a time. Only one Arduino can be connected to a serial port.

Sorry, nothing is actually connected to a physical serial port, I am using the serial library to send the data from ardunio to processing. Both servos and the lidar sensor are just connected to the analog/digital pins on the ardunio. Now, once that code is running, I need to send that data over to a GUI made in processing. I do this by using the serial library which apparently is connect to COMM3. The issue is, only the lidar sensor or the servos can send data, not both at the same time. This is because the serial port is "busy" according to what it is showing me. I just need it to where I can send the servos data and lidar data together to processing and be able to output it on the GUI. Currently, I have it where I have to comment out either the lidar code or servo code depending on what data I want. So, I am able to get the data for them from ardunio to processing l, just not at the same time (which is what I am trying to do).

Kyle3194:
Let me rephrase. I have ardunio code running the initial setup. The lidar sensor reads the distance and sends it to the serial monitor. That then has to be sent over to processing using the serial library. Both the servos and lidar sensor are just connect to digital and analog pins on the ardunio itself.

You need to be much more precise with your descriptions - otherwise you just confuse yourself as well as us.

The Lidar sensor does NOT send anything to the serial monitor. It provides data for the Arduino and the Arduino sends it to the serial monitor.

As you have discovered the Arduino cannot send data to two programs (the Serial Monitor and Processing) at the same time. You must choose one or the other. You can easily write code in Processing to display the data it receives from the Arduino as well as acting on the data.

...R

Robin2:
You need to be much more precise with your descriptions - otherwise you just confuse yourself as well as us.

The Lidar sensor does NOT send anything to the serial monitor. It provides data for the Arduino and the Arduino sends it to the serial monitor.

As you have discovered the Arduino cannot send data to two programs (the Serial Monitor and Processing) at the same time. You must choose one or the other. You can easily write code in Processing to display the data it receives from the Arduino as well as acting on the data.

...R

That isn't the issue. I know you can't send the data to two programs. The issue is to get information from ardunio to processing is you have to send that over by serial. In ardunio I have something along the lines of serial.begin(9600)
serial.write.myLIDARlite.distance()

Something along those lines, don't know the exact code from the top of my head, but the servos work in a similar manner. From what I've seen the only way to get processing and ardunio to "talk" to one is another is to use this serial method. The limitation is you can only have one set of data sent over at a time or else you get a "busy" error. Which means only the lidar or servos can send information from ardunio to processing, not both together. Looking to see if there is a way around this. If it helps, this is the tutorial I followed to get ardunio and processing to communicate with one another: Connecting Arduino to Processing - learn.sparkfun.com

I have something along the lines of

We do NOT deal with "something along the lines of" here. We deal with exact code.

Why are you using Serial.write() to send the data?

Which means only the lidar or servos can send information from ardunio to processing, not both together.

Utter nonsense. Neither a LIDAR or a servo can send data to the serial port. Only the Arduino can.

Post your Arduino code. Post your Processing code. Or take a hike. You choose, but quit spouting nonsense and claiming we don't understand you.

PaulS:
We do NOT deal with "something along the lines of" here. We deal with exact code.

Why are you using Serial.write() to send the data?
Utter nonsense. Neither a LIDAR or a servo can send data to the serial port. Only the Arduino can.

Post your Arduino code. Post your Processing code. Or take a hike. You choose, but quit spouting nonsense and claiming we don't understand you.

I know the lidar does not write to serial. To get any information from ardunio to prcoessing, you have to use the serial library. Even the lidar sample code with just ardunio writes to the serial monitor in the ardunio IDE. I am just speaking generally, I think you're taking what I'm saying too literal. Everything is hooked up to the ardunio and then the ardunio takes that data and sends it to the serial monitor. That is what I mean by the lidar sensor/servos writing to serial, I know technically the ardunio is the one doing this function.

From what I'm seeing so far, the ardunio can only get data from either the lidar or the servos only to send to the serial port to get it sent to processing. I'm trying to see if it's possible to have the data from both the servos and lidar sent over from the ardunio to processing.

From what I'm seeing so far, the ardunio can only get data from either the lidar or the servos only to send to the serial port to get it sent to processing. I'm trying to see if it's possible to have the data from both the servos and lidar sent over from the ardunio to processing.

Yes, it is. IF you write the proper code on the Arduino AND in Processing.

PaulS:
Yes, it is. IF you write the proper code on the Arduino AND in Processing.

I saw something called “hand shaking” but I’m not sure if that is what I am looking for. The way I can think of doing it is only grab the info from ardunio on specific loops, not just all the time, which I currently have it set up. Do you have any tips or ideas on how to make do this more simply? The biggest issue that I’m going to have is that I always need the servos running for the project I’m working on, so the ardunio will constantly be sending that information over to processing.

Do you have any tips or ideas on how to make do this more simply?

Same one I had earlier, that you ignored. POST YOUR CODE!

PaulS:
Same one I had earlier, that you ignored. POST YOUR CODE!

The problem is the code I am running is a modified version of Project Sentry with a ton of comments and such so it may be difficult to decipher exactly what is needed.

I am using this site: http://projectsentrygun.rudolphlabs.com/

Also, it uses an outdated version of processing because some of the libraries don't translate over well to the latest version.

Basically what I am trying to do is just to add a "Distance" label to the processing GUI using the Lidar Lite V3. I already created the label and added the lidar code to it, but it leads to the problems stated above. I would have to try to cut out all the unneeded stuff to just show the part I'm having issues with. I will try to trim down all the excess code and only provide that part once I am able to.

PaulS:
Same one I had earlier, that you ignored. POST YOUR CODE!

Here is the link to our GitHub that has all of our code:

Kyle3194:
From what I'm seeing so far, the ardunio can only get data from either the lidar or the servos only to send to the serial port to get it sent to processing. I'm trying to see if it's possible to have the data from both the servos and lidar sent over from the ardunio to processing.

of course you can send a message that includes data from several sensors.

What I don't understand is why you think it is not possible and if you can explain that we might get somewhere. Clearly there is a mismatch between your understanding of what we are saying and our understanding of what you are saying.

Maybe if you provide a few examples of the typical data that you want to send.

The code in your GitHub link is much too long to study (or I am just lazy).

...R

Robin2:
of course you can send a message that includes data from several sensors.

What I don't understand is why you think it is not possible and if you can explain that we might get somewhere. Clearly there is a mismatch between your understanding of what we are saying and our understanding of what you are saying.

Maybe if you provide a few examples of the typical data that you want to send.

The code in your GitHub link is much too long to study (or I am just lazy).

...R

From my understanding, in order for the ardunio IDE to transmit data to processing you have to use the serial library to do so. So, when I set up the servo on the ardunio board, I have the information that is gathered from the ardunio be sent to the serial monitor. Now, if I don't run the processing code I can simply view the serial monitor on the ardunio IDE and see the correct distance data. However, once I run the processing code, when I go to view the serial monitor I am unable to do so because the serial is "busy" since that information is being sent to processing (from what I understand). So once that is done I am able to get the processing code to read that data that was sent over from the ardunio IDE to be displayed on my GUI perfectly fine on processing. At this point the lidar sensor works perfectly fine. However, in the processing GUI there is connection for the two servo motors that you have to click "connect" and it displays that this is connect through the COM3 port. This is where the issue is. It seems that the lidar data being sent over from ardunio through the serial connection is already in use so the servos are unable to connect (their data from the ardunio board is also being sent to processing via the same serial method as the lidar sensor). Then, once I comment out the lidar code in the ardunio code, the servos will connect perfectly fine and function properly. I'm assuming this is the case because the way I have it set up, multiple data is being sent to that serial port and the ardunio cannot find which data to send. So it will only send the data which I have set up to appear first (not sure if this is the case, just an observation).

This is the part that I am having difficulties with. I know it may be possible to have them both communicate at the same time, but not sure what the best way to go about this is. I'm thinking I would have to be more specific about where the data from the servos and lidar sensor that the ardunio takes in are being sent to prevent this overload through the serial. I'm thinking it's just the way I have it set up currently. Hope this clears it up a bit, thank you for the help.

I can't be sure if you understand that Processing is one PC program and the Arduino Serial Monitor is a different PC program. That is the reason why you can't talk to both of them at the same time.

I can't get my head around this

It seems that the lidar data being sent over from ardunio through the serial connection is already in use so the servos are unable to connect (their data from the ardunio board is also being sent to processing via the same serial method as the lidar sensor).

If the one Arduino is sending Lidar data and receiving servo data I can't understand why there is a problem. Unless of course the code is not written properly to keep track of the different messages.

If you can produce a short program that illustrates the problem I will study it. But the stuff on your Github link would take far too long to figure out.

...R

Robin2:
I can't be sure if you understand that Processing is one PC program and the Arduino Serial Monitor is a different PC program. That is the reason why you can't talk to both of them at the same time.

I can't get my head around this
If the one Arduino is sending Lidar data and receiving servo data I can't understand why there is a problem. Unless of course the code is not written properly to keep track of the different messages.

If you can produce a short program that illustrates the problem I will study it. But the stuff on your Github link would take far too long to figure out.

...R

The ardunio board itself has both the lidar sensor and the two servos connected to it. Then I have code running that runs the servos and the lidar sensor. So basically the ardunio board is taking the servo input and lidar input data and then sending that over to processing to provide the GUI and display everything. I'm thinking, like you said, that I don't have the code written properly to keep track of both these inputs separately, I probably have it set up to where the inputs are both just being sent to the same place so once the ardunio board gets that info and sends it to processing, it can't differentiate between the different data so only either the lidar works or servos work depending on what I have the code set as.

I will try to trim down the code and create a sample program to more clearly show the issue, I realize the current code is a bit much to see the issue.

Have a look at the 3rd example in Serial Input Basics. I know it is intended for receiving data into the Arduino but the same technique can be used in a PC program.

For example you could send something like <123, 45, 67> where 123 is the Lidar value, 45 is the servo1 value and 67 is the servo2 value. The PC program will know which is which by the order in which they are presented. The < and > mark the start and end of the message.

…R

Robin2:
Have a look at the 3rd example in Serial Input Basics. I know it is intended for receiving data into the Arduino but the same technique can be used in a PC program.

For example you could send something like <123, 45, 67> where 123 is the Lidar value, 45 is the servo1 value and 67 is the servo2 value. The PC program will know which is which by the order in which they are presented. The < and > mark the start and end of the message.

…R

Update: We got it to work! Followed this “hand shaking” tutorial and we were missing a function lol. Thank you for your help.