Problem with encoder EMG49

Hello all,

I have a little problem with EMG49 and driver MD49.

I want to know the number of cicles where the motor is:

Firstable I try to set to 0 the encoder data with:

if (reset_enc==0) { Serial.write(CMD); Serial.write(0x35); delay(50); reset_enc=1; }

Then I read the data of the encoders:

[code] Serial.write(CMD);
Serial.write(GET_ENC1); // Recieve encoder 1 value
delay(50);
if(Serial.available() > 3)
{
enc1a = Serial.read();
enc1b = Serial.read();
enc1c = Serial.read();
enc1d = Serial.read();

result = enc1a << 24ul;
result += enc1b << 16ul;
result += enc1c << 8ul;
result += enc1d;
}[/code]

First problem: I think Serial.write(0x35); is not working, because I have a random number in the encoder:

Second one: I dont know what the numbers of the encoder means. Pulses? Position?

I read in robotshop.com/en/devantech-m … river.html

“Encoder: Processes quadrature encoder inputs of 588 counts per wheel turn from the” but the number of the encoder is no lineal, I cant do: (current_input-start_input)%588 = 1 cycle more

Alsi, if I observe the wheel, is not 588 per cycle, more or less 1000.

Thanks you very much!

Do you have the second block of code inside your main loop() function? The serial protocol might be become unsynched, and that can be cause of the gibberish…

I would recommend trying something like this:

while (Serial.available()) {
  Serial.read(); // empty the input buffer
}
Serial.write(CMD);
Serial.write(GET_ENC1);   // Recieve encoder 1 value
while (Serial.available() < 3) {
  // wait for all 4 bytes
}
  enc1a = Serial.read();
  enc1b = Serial.read();
  enc1c = Serial.read();
  enc1d = Serial.read();
   
  result = enc1a << 24ul;
  result += enc1b << 16ul;
  result += enc1c << 8ul;
  result += enc1d;

The number should indeed be pulses. We checked the specs, and the EMG49 motors actually have 980 pulses per rotation, not 588, so your observations are correct and we’ve updated our product page. The pulses should however be observed increasing linearly, but this might be a side effect of the serial communication problem. Please try the code above and let us know if it improves.

Hope this helps,

Done. Now works perfect.

I have the code inside the loop, and now is working. But in your code you have to add a delay after Serial.write(GET_ENC1); if don’t, doesn’t work.

Thank you!!

Great, thanks for letting us know!