Is there an assembly drawing somewhere which shows how to attach the encoders to the DFRobot 4WD With Encoders platform? I have looked at the picture on the main sales page for this robot, but I’m still a little uncertain how all the pieces go together.
Coleman,
Thanks for the installation guide. I'll try it now using these pictures.
Thanks,
Dexter
I installed the encoders and now I need to know how to correctly plug their wires into the Romeo controller. I bought the encoders from Robotshop with the wiring sockets already attached to both ends of the wires. I attached the white socket to the encoder, but into where should I plug the black socket on the Romeo? The black socket has 3 wires (a black, a red, and a green) coming out of it.
Hey Coleman,
Thanks for the info on the LOW and HIGH returns. I hooked up the left encoder to digital pin 4 and the right encoder to digital pin 2. I then loaded the code below into the Romeo. I got the code from the DR Robot Forum website. When I turned on the DF Robot, nothing happened to the robot's motors. Did I do something wrong? Should this code make the wheels turn and count the rotations? Thanks, Dexter
const byte encoder0pinA = 2;//A pin -> the interrupt pin 0
const byte encoder0pinB = 4;//B pin -> the digital pin 4
byte encoder0PinALast;
int duration;//the number of the pulses
boolean Direction;//the rotation direction
void setup()
{
Serial.begin(57600);//Initialize the serial port
EncoderInit();//Initialize the module
}
void loop()
{
Serial.print(“Pulse:”);
Serial.println(duration);
duration = 0;
delay(500);
}
void EncoderInit()
{
Direction = true;//default -> Forward
pinMode(encoder0pinB,INPUT);
attachInterrupt(0, wheelSpeed, CHANGE);
}
void wheelSpeed()
{
int Lstate = digitalRead(encoder0pinA);
if((encoder0PinALast == LOW) && Lstate==HIGH)
{
int val = digitalRead(encoder0pinB);
if(val == LOW && Direction)
{
Direction = false; //Reverse
}
else if(val == HIGH && !Direction)
{
Direction = true; //Forward
}
}
encoder0PinALast = Lstate;
if(!Direction) duration++;
else duration–;
}
Coleman,
Thanks for that advice...I'll try it out.
Much thanks,
Dexter
Coleman,
Thanks for that advice...I'll try it out.
Much thanks,
Dexter
Coleman,
Thanks for that advice...I'll try it out.
Much thanks,
Dexter
Hi Dexter,
The sensor returns a 0 or 1 (LOW or HIGH) and therefore needs to be connected to a digital pin with the included cable. Only one orientation will work.
Sincerely,
Hi Dexter,
Since you are new to encoders, we suggest building up your own code in order to gain experience. Try the following:
Set one motor to rotate slowly and simply count the encoder on/off. Once you can do that, have your program stop the motor at a set count. Once you are able to do that, extend the same functionality to two motors, and work your way up to more and more complex code.
Hope this helps,