0
Offline
Sr. Member
Karma: 0
Posts: 378
mingki
|
 |
« on: January 31, 2008, 11:32:16 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 0
Posts: 593
|
 |
« Reply #1 on: February 01, 2008, 12:33:40 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #2 on: February 01, 2008, 01:28:37 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #3 on: February 01, 2008, 11:36:34 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 378
mingki
|
 |
« Reply #4 on: February 01, 2008, 07:22:58 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 0
Posts: 593
|
 |
« Reply #5 on: February 01, 2008, 08:47:36 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 378
mingki
|
 |
« Reply #6 on: February 03, 2008, 05:22:36 am » |
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; }
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #7 on: February 03, 2008, 06:08:52 am » |
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
|
|
|
|
« Last Edit: February 03, 2008, 06:56:45 am by mem »
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 378
mingki
|
 |
« Reply #8 on: February 04, 2008, 07:25:20 am » |
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. } 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. encoder0PinALast = n; } // set the variable holding the previous state to the value n read above
|
|
|
|
« Last Edit: February 04, 2008, 07:48:47 am by mingki »
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #9 on: February 04, 2008, 08:56:00 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #10 on: February 04, 2008, 12:18:06 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #11 on: February 05, 2008, 01:42:27 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #13 on: February 05, 2008, 06:58:35 am » |
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.
|
|
|
|
« Last Edit: February 05, 2008, 07:06:57 am by mem »
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 378
mingki
|
 |
« Reply #14 on: February 05, 2008, 10:05:12 pm » |
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/
|
|
|
|
|
Logged
|
|
|
|
|
|