Go Down

Topic: Processing to mega 2560 over USB serial (Read 1 time) previous topic - next topic

justincaselton

Hello All!

I am having some problems when trying to get my Mega 2560 to read data sent to it over the USB serial connection from Processing 3.

I am using SainSmart Mega 2560 board.

I have managed to send data from the Mega to Processing without issue, but reading data doesn't seem to work.

I have been using the Dimmer example program found in the Communication example folder (also see attached text file).

When I upload the Arduino code to the Mega and run the Processing program, the RX light starts flashing indicating its receiving serial data.  However for some reason the on-board LED on pin 13, which I was intending to use as the dimmer LED remains on constantly while the Processing program is running.
 
Therefore I changed the code so that the dimmer LED is on another digital pin (50 for example) and connected an oscilloscope to that the pin to observe any voltage changes.

However, this did not make a difference, the value of the assigned digital pin did not change value regardless of the mouse position when executing the Processing program.  So it seems that whilst the board acknowledges that data is being sent to it, it's clearly not reading the sent data.  Could this perhaps have something to do with the loop that checks to see if data has been received?

i.e.   if (Serial.available()) {

        }

Also the on-board LED on Pin 13 remained constantly on as before.

In case this was caused by a power issue I have tried using an adaptor to power the Mega, whilst running the program and it made no difference. 

I have also tried using different USB ports with all other USB devices removed and again it made no difference.

Perhaps there is some fault on my Mega 2560 board?

Any help would be greatly appreciated!   






   

PaulS

You can use Serial.print() on the Mega, to echo what you read.

You can define a function, serialEvent(Serial aPort), to deal with the serial data coming from the Arduino.

In that function, you can read the serial data, and use print() or println() to print to Processing's window, so you can see what you sent.
The art of getting good answers lies in asking good questions.

Robin2

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data on an Arduino.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

justincaselton

Hi Thanks for your response.

Unfortunately PaulS the Mega's serial monitor can not be used when the Processing program is running, as both the Processing sketch and serial monitor use the same coms port, so I am unable to use Serial.print() on the Mega to see what its reading while the Processing sketch is running.

However I will look into using the Serial.Event() function and see if that makes a difference.



 

justincaselton

Success!

Have managed to get the Arduino to read and send data to and from Processing!

Thanks for everyone's help!

Once I realised what PaulS meant about using the serial.println in the Arduino code to display a message in the Processing program, it became much easier to understand what was happening!


rva1945

Success!

Have managed to get the Arduino to read and send data to and from Processing!

Thanks for everyone's help!

Once I realised what PaulS meant about using the serial.println in the Arduino code to display a message in the Processing program, it became much easier to understand what was happening!


Hi, I have that problem. I can't get the Mega to receive the char I send. The port and everything is ok.
Can you please tell me how you fixed it?

Thanks!

PaulS

Quote
I can't get the Mega to receive the char I send.
And yet you failed to post the code that sends the data or the code that receives the data. I assumed that you wanted help. I must have assumed incorrectly.

Quote
The port and everything is ok.
If EVERYTHING was OK, you wouldn't have a problem. So, clearly, this statement is nonsense.

Quote
Can you please tell me how you fixed it?
OP used his brain.
The art of getting good answers lies in asking good questions.

Go Up