I am trying to set up my 50:1 Metal Gearmotor 37D*54L mm with 64 CPR Encoder. The purpose of this project is to have this motor turn at a desirable speed, stop, and reverse to a desired position using a motor driver. I am currently just trying to understand how to use PWMs and the encoder.
I have started with the basics and messed with LEDs, buzzers, and servos to understand the coding a bit. I am new to this so be kind .
I am having trouble started. I am manipulating the code to try to read the encoder but no luck. This is my code but it is not reading the PWMs how I've seen them. This code is just writing the text in the Serial Monitor even if the pins are not in. HELP!!
int pinA = 10;
int pinB = 9;
The encoder outputs pulses that the Arduino must count. Your code is not even close. There are a ton of encoder tutorials. Google "Arduino encoder tutorial".
Hi, please use code tags to post your code.
First problem is you need to declare what pins are input.
Then you need to digital.Read, not Write.
I'm not sure if you know how an encoder works, it outputs a series of pulses that are dependent on speed and direction of rotation of the encoder shaft.
If you use the Search Arduino box in the top of this page and search for reading encoders you will find lots off posts that have found the solution you are looking for.
Can you post a copy of your circuit diagram, either CAD or picture of hand drawn will be okay, by the way to you have a digital mutlimeter to help you trouble shoot your project.
Hoping to help, Tom.....
Thanks groundfungus I’m currently watching a video hopefully this one gives me more insight.
Tom I will figure out the code tag for next time sorry about that but thanks. I have an idea of what an encoder should put out but from what I have seen its been tutorials that use potentiameters and use a seperate motor that outputs this http://d32zx1or0t1x0y.cloudfront.net/2011/06/atmega168a_pwm_02_lrg.jpg . I am not sure if I need a certain software to read the PWMs from the encoder but I’ve searched for it on google and no luck there so I figure an A and B output on the screen monitor is enough. I will be sure to continue searching more into the reading encoder posts. My weak attempt of a drawing is attached to the post, so far I am just trying to understand the encoder and coding so I have not tried to use the motordriver to change direction, and I don’t have a multimeter. Thanks for your time Tom
Tom I will figure out the code tag for next time sorry about that but thanks.
You can figure it out now - just select "modify" on your previous posting, highlight the code part, and click on the "code" button with the hash ("#") symbol to put the tags on, and save it.
The encoder is not (I hope!) PWM (Pulse Width Modulation) though there is one type that is that has been brought here previously. You do not want that one.
It should be a quadrature encoder - two signals that change alternately and the direction can be determined by which one leads the other.
Pololu - 50:1 Metal Gearmotor 37Dx54L mm 12V with 64 CPR Encoder (No End Cap) Is this the motor and encoder that you have. The output of the encoder is NOT PWM. It a series of pulses at 64 pulses per revolution of the motor. Depending on motor speed the pulses will be very brief. Usually the pulses are fed to an interrupt pin and counted for a fraction of a second then the count and gate times (fraction of second) are used to determine motor speed.
Pololu - 50:1 Metal Gearmotor 37Dx54L mm 12V with 64 CPR Encoder (No End Cap) Is this the motor and encoder that you have?
It certainly looks like it.
The colours and description do match the diagram above.
One thing I note - while the encoder is rated to be powered by 3.3 to 20 volts, it should not be powered from the 3.3V output on the Arduino, but by the 5V supply so that its output voltages match the Arduino without problems.
Equally importantly, the motor itself cannot be connected directly to the Arduino, but must be driven by a motor driver circuit rated for the nominal stall current (5A). So that diagram is somewhat misleading but I notice that the need for a driver was acknowledged.
Yes that is the motor and encoder that I have to mess around with. I also will be using the motor driver that I attached to the post. I’m trying to bypass the motor driver to figure out and understand the encoder. Now I am not sure if it is possible even though I know I cannot change directions yet.
instruction-manual-rs011mc.pdf (1.42 MB)
Yes Tom something like this is what I was hoping to get. (attached to post)
I’m trying to bypass the motor driver to figure out and understand the encoder.
Just as long as you do not connect the motor itself to the Arduino - that will cause problems.
Run it from a separate supply or the supply that you use to feed “Vin” on the Arduino if that can supply a couple of amps at least (and is reasonably regulated).
The encoder will work perfectly well with the Arduino, powered from the 5V line. You need to look up some code for a quadrature encoder; I haven’t that on hand myself however.