FaulHaber magnetic encoder...Help!

Hello everybody,

I am executing a project with FaulHaber motor (pls, see attached files)
But I can not find Pin diagram of the encoder (Vcc, Motor+, Motor-, GND, Channel A/B).
So I don't know how to connect it with Interrupts of Mega 2560.
Anyone can help me with this problem???

This is a simple code to count value from encoder.
int pinA = 52; // 2 pins of motor
int pinB = 53;
long count = 0;
void setup()
{
delay(500);
pinMode(pinA,OUTPUT);
pinMode(pinB,OUTPUT);
Serial.begin(9600);
attachInterrupt(0,Encoder0, CHANGE); // call Encoder0 func every INT0 changes its state
// encoderVal.every(50,updateEncoder,(void*)0);

}

int i=0;
void loop()
{
if (i==0)
{

// run motor
digitalWrite(pinA,LOW);
digitalWrite(pinB,HIGH);
delay(2000);
// stop motor
digitalWrite(pinA,LOW);
digitalWrite(pinB,LOW);
i++;

}
}

void Encoder0()
{
count++;
Serial.println(count);
}

Magnetic Encoder.png

Hello everyone!

I am executing a project with FaulHaber motor 2342L-012CR and a magnetic encoder (pls, see attached files).
However, I don't know pins diagram of the encoder (Vcc, GND, Motor+, Motor-, Channel A/B)
So, I don't know how to connect the encoder to Arduino board correctly.
Anyone can help me???
Below is my simple code to run motor and count value from encoder

int pinA = 52;   // 2 pins of motor
int pinB = 53;


long count = 0;

void setup()
{
  delay(500);
  pinMode(pinA,OUTPUT);
  pinMode(pinB,OUTPUT);
  Serial.begin(9600);
  attachInterrupt(0,Encoder0, CHANGE);  // call Encoder0 func every INT0 changes its state
//  encoderVal.every(50,updateEncoder,(void*)0);
  
}


int i=0;
void loop()
{
  if (i==0)
  {
    
    // run motor
  digitalWrite(pinA,LOW);
  digitalWrite(pinB,HIGH);
  delay(2000);
  // stop motor
  digitalWrite(pinA,LOW);
  digitalWrite(pinB,LOW);
  i++;
  
  }
}

void Encoder0()
{
  count++;
  Serial.println(count);
}

Magnetic Encoder.png

count needs to be volatile, its used in an interrupt handler.

What motor driver are you using?

What is more you can not use serial print inside an ISR

void Encoder0()
{
  count++;
  Serial.println(count);  // Nooooooooooooo!
}

MarkT:
count needs to be volatile, its used in an interrupt handler.

What motor driver are you using?

I use L298N to control the motor.
Now, I don't know how to connect the encoder. I am afraid that it is damaged.

Grumpy_Mike:
What is more you can not use serial print inside an ISR

void Encoder0()

{
  count++;
  Serial.println(count);  // Nooooooooooooo!
}

This is my code with another motor with detail information of encoder.
But with FaulHaber 2342L motor, I can not find the datasheet.
So, anyone done it before, please let me know the diagram of the encoder pin.

Anyone can help me? Please..

The encoder will provide a signal which goes on and off as the motor turns. You set the interrupt routine on the arduino to trigger on each rising or falling edge on the encoder signal. There will be some number of pulses per cycle of the motor, which depends on the number of holes or slots in the spinning wheel attached to the motor shaft.

Can you find anything written on those encoders, identifying them ?

You can find out some more by having a real good look at the traces of that small PCB, but you'll be guessing a bit that way.
I can't see enough detail in those pics to help with that.
(need to see the traces)

It is probably too late but,
in case any one needs the same information i found the fallowing link regarding Faulhaber magnetic encoders...

http://www.fenchurch.org/priv_cgi-bin/ids/albums//Computing/%23001_RobotStuff/Faulhaber_Motor/Faulhaber-Magnetic_Encoder.pdf

Since you are using Faulhaber 2342L, your encoder should be HEM 2338, 2342 ...

Actually what datasheet says is:
Pin 2 : VCC (4.5 - 15 V)
Pin 3/4: Channel A/B
Pin 5: GND

Pin 1 and 6 are for motor itself
You will not need these since "Motors 2342 and larger have seperate motor connections"

Anyway, i hope this will...

Never call delay() or Serial.() in an ISR, the system will hang completely.