Forum >How to connect encoders to romeo???
RoboticsGeneral

How to connect encoders to romeo???

userHead SuperMiguel 2012-04-07 12:38:49 7710 Views5 Replies
Hey guys i purchased a HCR-Mobile robot platform a bit ago from you guys, and I'm trying to connect the encoders to an DFRduino Romeo V1.0 that i got from you guys few months ago.. But i can't figure out how to do it.. The only guide you guys have is: [url=http://www.dfrobot.com/wiki/index.php?title=HCR-Mobile_robot_platform_(SKU:ROB00021)#Encoder_Connection_Diagram_V2]http://www.dfrobot.com/wiki/index.php?title=HCR-Mobile_robot_platform_(SKU:ROB00021)#Encoder_Connection_Diagram_V2[/url] but it only shows how to connect it to the regular arduino no the Romeo…

Please explain how to do it.. ANd if you have some sample code of how to use the encoder i would love to see it
2012-09-22 07:08:17 [quote="SuperMiguel"]
nvm got it
[/quote]

Would love to see the code you got working.
userHeadPic jtilghman
2012-04-09 18:40:24 Cool,


Glad you got it working.
userHeadPic Hector
2012-04-07 12:53:22 nvm got it userHeadPic SuperMiguel
2012-04-07 12:52:06 i kinda figure how to connect them.. I did:

Green to GND
Blue to VCC
Yellow to D4
White to D1

Tried this code:

[code]
const byte encoder0pinA = 2;//A pin -> 6
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--;
}
[/code]

but the motors wont move...
userHeadPic SuperMiguel
2012-04-07 12:41:47 Note I have the new style of encoders wires: White, Yellow, Green, Blue userHeadPic SuperMiguel