Go Down

Topic: Problem with bilateral communication between Arduino and Processing (Read 3278 times) previous topic - next topic

Kyle3194

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.

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
Two or three hours spent thinking and reading documentation solves most programming problems.

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

Kyle3194

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.

Kyle3194

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).

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Kyle3194

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: https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing

PaulS

Quote
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?

Quote
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.
The art of getting good answers lies in asking good questions.

Kyle3194

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.

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

Kyle3194

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.

PaulS

Quote
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!
The art of getting good answers lies in asking good questions.

Kyle3194

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.

Kyle3194

Same one I had earlier, that you ignored. POST YOUR CODE!
Here is the link to our GitHub that has all of our code:

https://www.github.com/aperez41907/LM-Autonomous-Vehicle

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up