I can send seamlessly data/commands from vrep to atmega2560 arduino, but can't receive anything back from arduino to vrep using same serial USB communication used for sending. There is a history of this problem, caused by autoreset of atmega by the software package. And a simple solution is either to use 110ohms resistor between 5V and RESET or 220ohms resistor between 5V and RESET or 10microfarad capacitor between GND(-ve) and RESET(+ve).
The Mega has 3 spare HardwareSerial ports - why use pins 0 and 1?
Post your code here to make it easy for people to help you.
And please use the code button </> so your code looks like this and is easy to copy to a text editor
I am using VREP to send commands to arduino and get feedback. I am able to send commands to arduino, but not receive. The problem on searching i figure out should be because of auto-reset functionality of ATMEGa.
I am just send command "R" from vrep and want to receive number 20 from arduino to vrep using below:
void setup()
{
Serial.begin(9600); // baud rate
while(!Serial)
{
; //wait for serial port to connect
}
}
void loop()
{
if (Serial.available())
{
char inp;
// get commands to run
inp = Serial.read();
if (inp == 'R')
{
int count=20;
Serial.println(count);
}
}
}
On vrep side, i send command "R", then i wait for 100 ms or '\n' to receive this 20, but doesnt come.
On starting serial port, i have tried all kinds of delays too.
I don't have a Atmega 2560, but I have no problems sending and receiving from an Arduino Uno.
My LabVIEW opens the serial port to the Arduino Uno.
Then whenever someone clicks a button on the LabVIEW front panel, the text in a text box is sent to the Arduino Uno.
The Arduino Uno's sketch is written to echo each character + 1 so that if LabVIEW sends a 'ACD' then 'BDE' is sent back.
Your code uses the variable inp but it is never set.
It is an ATMEGA issue mostly, it has a history of it. I have posted one such issue in my 1 st post.
Could you tell if my code should work?
(I missed the setting of inp in the code i posted..actually the code is big and i am concerned with only with this part, i have updated the code i posted)
probably you dint get my problem,, i cant receive anything on vrep sent from arduino...Its all nil, even if i send anything in setup or the recursive loop.
I am telling you, mostly this is ATMEGA related issue and the workover is around it...Which several of i tried and unfortunately dint work...
Perhaps you could try this Python - Arduino demo to see if two communication works. It should work on Windows if you put in the appropriate Serial port reference.
If it works you might then usefully compare the way it is structured with the way your VREP program is structured.
In particular your VREP program should keep the serial port open until it is completely finished talking to the Arduino.
dnahar:
probably you dint get my problem,, i cant receive anything on vrep sent from arduino...Its all nil, even if i send anything in setup or the recursive loop.
I am telling you, mostly this is ATMEGA related issue and the workover is around it...Which several of i tried and unfortunately dint work...
Thanks,
Dixit
You could try just a simple terminal program to try to talk to your Atmega.