hi
I have an analog require encoder I mean that the channels of the encoder must be connected to the analog pins of the Arduino board, I know that there is a library <Encoder.h> but I want to read the pulses of the encoder by writing code and I won't use this library because I want to extend this code to the other software
I have an analog require encoder I mean that the channels of the encoder must be connected to the analog pins of the Arduino board
Can you attach the document, or provide a link to the data sheet for this encoder?
Well that's just a normal encoder, use the normal logic.
- If output1 has changed and output 2 is the same, count one click in one direction.
- If output1 has changed and output 2 is different, count one click in the other direction.
I don't see anything in the datasheet which would cause you to say
I have an analog require encoder I mean that the channels of the encoder must be connected to the analog pins of the Arduino board,
In fact Note 1 says
1.The output signal is open collector structure
This would indicate a digital input with a pull-up resistor to Vcc.
Please explain why you think this encoder must be connected to the analog pins of the Arduino.
koronus:
hi
I have an analog require encoder I mean that the channels of the encoder must be connected to the analog pins of the Arduino board, I know that there is a library <Encoder.h> but I want to read the pulses of the encoder by writing code and I won't use this library because I want to extend this code to the other software
It just struck me though, there's no actual question in there. So what is it you need help with, if anything?
I test the encoder with encoder library in the Arduino software, when I use digital pins for encoder the pulses had 0 values and when I connect the encoder pins to the analog pins of the Arduino the pulses had correct values, and my question is how to write a code to read the pulses of the analog pins without using Encoder library and I just have analogRead(A0) and analogRead(A1) how I could write a code to convert this reading of the analog pins to the pulses of the encoder?
koronus:
I test the encoder with encoder library in the Arduino software, when I use digital pins for encoder the pulses had 0 values and when I connect the encoder pins to the analog pins of the Arduino the pulses had correct values
I'd be keen to see the sketch/es and the connections for those two scenarios, along with the output.
I wonder if you had pullups on the digital pins, either external or pinMode()-ed?
I have written this code:
#include <Encoder.h>
Encoder myEncoder(A0,A1);
double Position;
int t;
void setup() {
Serial.begin(250000);
Serial.println("DC POSITION.");
}
long oldPosition = -999;
void loop() {
long newPosition = myEncoder.read();
if (newPosition != oldPosition) {
oldPosition = newPosition ;
}
Serial.print("t");
Serial.println(t);
Serial.print("Position = ");
Serial.println(newPosition);
analogWrite(5,60);
digitalWrite(8,LOW);
t=millis();
if (t<2000){
digitalWrite(7,HIGH);
}
else if(t>=2000 && t<4000){ digitalWrite(7,LOW);
digitalWrite(8,HIGH);
}
else{ digitalWrite(8,LOW);
}
}
and the pulses had correct values and as I said I have used the ENCODER LIBRARY but I don't want to use this library, I want to write the other code to read the pulses of the encoder
let me ask my question clearly
when we use this code:
# include <Encoder.h>
Encoder one(pina,pinb);
void loop {
a=one.read()};
what is this library and encoder reading doing?
(what is the source code of the Encoder Library?)
koronus:
let me ask my question clearly
You mean:
let me ask my **[new, totally different]**question clearly
koronus:
(what is the source code of the Encoder Library?)
Check the .h file in the encoder folder in your sketchbook/libraries.
koronus:
I want to write the other code to read the pulses of the encoder
.... and I explained how to do that in #3.
And btw you still didn't show the connections and code for when it didn't work on the digital pins.
edit: and since the analog pins are digital pins anyway, when you used the encoder library with pins A0 and A1, you were actually using digital pins; the library won't have been doing anything different.
Willpatel_Kendmirez:
.... and I explained how to do that in #3.
ok thank you I will write the code as:
count=0;
a0=analogRead(A0);
a1=analogRead(A1);
if (a0 !=a0 && a1=a1){
count=count+1;}
else if (a0 !=a0 && a1 !=a1){
count=count-1}
}[\code]
is it correct?
is it correct?
How can something not be equal to itself?
if (a0 !=a0...
You need the StateChangeDetect example I'd say.