Hello,
I have made an robot and have a controller for it,
I made the remote and use serial communication.
It all work, but now i want to test the robot with my computer.
but nothing works, I think the problem is that I can’t send my command’s fast enough …
my remote has the following code :
#include <Wire.h>
#define MD03_1 0x58
#define MD03_2 0x59
#define CMD_reg 0x00
#define SPEED_reg 0x02
#define ACC_reg 0x03
int joyFB = A1 ; //joystick forward and backward
int joyLR = A2 ; //joystick left and right
int valueFB = 500; //variable value forward backward
int valueLR = 500; //variable value left right
void setup()
{
Serial.begin(115200);// begin the serial communicaton
pinMode(joyFB,INPUT);
pinMode(joyLR,INPUT);
}
void loop()
{
valueFB = analogRead(joyFB);// read the first joystick
valueLR = analogRead(joyLR);//read the second joystick
Serial.println(1066);// send a code that anounces that valueFB is comming
Serial.println (valueFB); // send valueFB to rx arduino
delay(80);// wait
Serial.println(1065);// send a code that anounces that valueLR is comming
Serial.println (valueLR); // send valueLR to rx arduino
delay(80);// wait
}
the beginning of the programm of the reciever is also easy to explain :
#include <Wire.h>
#define MD03_1 0x58
#define MD03_2 0x59
#define CMD_reg 0x00
#define SPEED_reg 0x02
#define ACC_reg 0x03
int valueFB = 500; //variable value forward backward ( I use 500 because otherwise it would set of if i didn’t send any value )
int valueLR = 500; //variable value left right
unsigned long speed1;
unsigned long speed2;
int speed;
int recievedChar = 0;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(115200);// begin the serial communicaton
}
void loop()
{
recievedChar =Serial.parseInt();
if (incoming > 0)
{
if(recievedChar==1066){// if it sees 1066 then it knows that valueFB is comming
valueFB = Serial.parseInt(); //Reads integers as integer rather than ASCI. Anything else returns 0
Serial.println(valueFB);// prints valueFB so I could see it int the serial monitor
}
if(recievedChar==1065){// if it sees 1066 then it knows that valueLR is comming
valueLR = Serial.parseInt(); //Reads integers as integer rather than ASCI. Anything else returns 0
Serial.println(valueLR);// prints valueLR so I could see it int the serial monitor
}
}