Go Down

Topic: encoder (Read 17414 times) previous topic - next topic

mingki

Hello,.
Hopefully, I want to use encoder with arduino.
I've learned that incremental type encoder puts out pulse signals and ansolute type encoder puts out binary signals.
I want to use either type of encoders and use arduino to receive those signal and do something motional(controlling on/off of motors or solenods) when the encoder is reached to a certain position or signal.
what kind of programing language can I utilize in order to control motor(or solenoid) using encoder signal?
frankly, it's difficult to follow this tutorial http://www.arduino.cc/playground/Main/RotaryEncoders
please advise me gentlemen, then it will be highly appreciated

mingkimingki@gmail.com

Cheater

What rotary encoder are you trying to develop for exactly?

Its certainly possible to use them with the Arduino but specifics will depend on the actual encoder.

mem

And it will depend on your actual application. Do you have a specific problem you are trying to solve or are you just interested in gaining practical experience with encoders?

mem

Mingki, I am not clear on what you want to do and it is easier to advise about implementation with a clearer picture of the physical movement you want to detect.

I think you want to light an LED when you detect when something moves a certain distance (or perhaps angle). How is the object you want to detect moving, is it rotating?

mingki

thank you, mem.
i am very sorry for my lack of explanation on my question. i haven't bought any encoder yet to test it for myself. I will get my own encoder soon.
yes, when i rotate encoder, i want arduino to read pulse from encoder and i want to make one of arduino's digital pin to be in a HIGH state when arduino receive 10th pulse from encoder.
Ultimately, i want arduino to read encoder's pulse all the way to the tenth pulse(where digital pin goes in a high state) while bypassing 1th, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th pulses.

mingkimingki@gmail.com

Cheater

Just so you know, some encoders have over 500 pulses per revolution.
Turning on a LED after every 10 will make it look always on. ;)

Is there a URL for the encoder your looking at?

mingki

Hi, I am trying to figure out the purpose of below programing.
does anyone know what this commend for? Especially the commends in bold letters.
void loop() {
n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
    Serial.print (encoder0Pos);
    Serial.print ("/");
  }
  encoder0PinALast = n; }

mingkimingki@gmail.com

mem

#7
Feb 03, 2008, 12:08 pm Last Edit: Feb 03, 2008, 12:56 pm by mem Reason: 1
Quote
Hi, I am trying to figure out the purpose of below programing.
does anyone know what this commend for? Especially the commends in bold letters.
void loop() {
n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
    Serial.print (encoder0Pos);
    Serial.print ("/");
  }
  encoder0PinALast = n; }

// encoder0Pos          holds the position for encoder0
// encoder0PinA         is the pin that encoder0 is connected to
// encoder0PinALast   is the last processed state of encoder0

void loop() {
n = digitalRead(encoder0PinA);   // n is current state of encoder0PinA pin
  if ((encoder0PinALast == LOW) && (n == HIGH)) {   // check if encoder0PinA pin has changed state
    if (digitalRead(encoder0PinB) == LOW) {  
         encoder0Pos--;   // if it has changed and its now low decrement  encoder0Pos;
    } else {
     encoder0Pos++;   // if it has changed and its now high, increment encoder0Pos
    }
    Serial.print (encoder0Pos);
    Serial.print ("/");
  }  
  encoder0PinALast = n; }   // set the variable holding the previous state to the value n read above


mingki

#8
Feb 04, 2008, 01:25 pm Last Edit: Feb 04, 2008, 01:48 pm by mingki Reason: 1
thank you very much for your answer.
i still having some trouble understanding some of the program. sorry.
Please help me to understand some points.
Quote
Quote
    }
    Serial.print (encoder0Pos);
    Serial.print ("/");
  }  
  encoder0PinALast = n; }   // set the variable holding the previous state to the value n read above

Do i need to use Serial.print commend in order to take puls signals(using arduino) from encoder in real time?
could you tell me what ("/") does for?
i hope i could get some more explination on this quote.
Quote
Quote

encoder0PinALast = n; }   // set the variable holding the previous state to the value n read above



mingkimingki@gmail.com

mem

I assume the author of that code was using the serial port to display the status of the encoder. You don't need to send this data to the serial monitor but it is useful to see what is happening.

Anyway, the variable encoder0PinALast is used to remember if the previous state of the encoder sensor pin was high or low. The code uses this to determine the direction the encoder is rotating.

The variable encoder0Pos contains a count of the encoder position and you would use this value in your application. By the way, what is your application?  It would be easier to guide you knowing a little more about what you are trying to achieve.

If you don't have a specific application in mind and just want to learn about encoders, then have a search on google for some tutorials on the use of phototransistors. Also have a search on any tutorials on the innards of mechanical mice, they are a good source of cheap (free?) encoders to play with if you have an old one lying around.

mem

You don't say what programming experience you have but assuming you are just beginning to learn, I suggest you start with a simple sketch that detects the presence or absence of light on a phototransistor. You should be able to find a number of tutorials on doing this with the arduino by searching google.

Then enhance that sketch with functionality to count the number of times the sensor has changed state (i.e. has changed from light to dark) and send the count to the serial monitor.

Or are you already comfortable with the skills necessary to write and debug this kind of functionality?

mem

Ladyada's tutorials are highly regarded so thats a good place to start:
http://www.ladyada.net/learn/arduino/

there isn't one on encoders yet but it will help you to get comfortable with the basics.  

mingki

thanks for the advise.
I've choosen an encoder which is a type of line driver.
http://www.flickr.com/photos/23525729@N06/2243426483/
http://www.flickr.com/photos/23525729@N06/2244219512/
i followed this http://www.arduino.cc/playground/Main/RotaryEncoders tutorial to receive pulse signals from encoder when it's rotating in cw or in ccw.
http://www.flickr.com/photos/23525729@N06/?saved=1
my question is, how can i send real time pulse signal from encoder to arduino and monitor them as ASCII?


mingkimingki@gmail.com

mem

#13
Feb 05, 2008, 12:58 pm Last Edit: Feb 05, 2008, 01:06 pm by mem Reason: 1
If you have run that tutorial then you should be seeing the encoder pulse counter value as ascii on the serial monitor seperated by the '/' character.

Are you able to see that?

If you see nothing on the serial monitor, check that your baud rate in the serial monitor is set for 9600.

If that doesn't solve the problem then you may want to get the communication example sketch asciitable running to make sure you have the serial monitor configured correctly.


mingki

yes, i see serials on serial monitor.
i see below numbers.

start   1  2  3  4  5  6  7........65535  65534  65535  65534   65535   65534  65534  65534

too many numbers are appeared. but those numbers aren't coming from the rotational movement of encoder. they just gradually appeared and increased in numbers once the encoder, arduino's connection is made.
is my hardware connection correct?
i made a connection like this.
              encoder                 arduino digital pin
          A phase(red)                       #2
          B phase(green)                   #4
          Z phase(yellow)                  #0
the connection table is shown here http://www.flickr.com/photos/23525729@N06/2244219512/sizes/l/

mingkimingki@gmail.com

Go Up