Hi Guys,
I have a rotary encoder connected to my T4 and for some reason it's losing a few steps / causing a noise. I made a simple sketch and I tested the T3.6 vs T4.0, and the 3.6 doesnt have the miss-steps.
Please see attachment for a quick chart.
Here is the Sample Sketch:
I have a rotary encoder connected to my T4 and for some reason it's losing a few steps / causing a noise. I made a simple sketch and I tested the T3.6 vs T4.0, and the 3.6 doesnt have the miss-steps.
Please see attachment for a quick chart.
Here is the Sample Sketch:
Code:
#include "USBHost_t36.h" //5V Activation
USBHost fivevolts;
const int encoderPinA = 8; // Green - pin 2 - Digital
const int encoderPinB = 7; // White - pin 3 - Digital
volatile unsigned int temp;
volatile unsigned int encoder_pos = 0;
volatile unsigned int rev_count_time = 0;
String data;
/*************************************VOID SETUP***************************************/
void setup()
{
Serial.begin(115200); //USB Baud Rate
fivevolts.begin(); //Activate 5V
//Encoder
pinMode( encoderPinA, INPUT_PULLUP );
pinMode( encoderPinB, INPUT_PULLUP );
attachInterrupt(encoderPinA, encoder_position_A, RISING );
//attachInterrupt(encoderPinB, encoder_position_B, RISING );
}
/*************************************VOID LOOP****************************************/
void loop() {
if (encoder_pos != temp)
{
//rev_count_time = micros();
data = String(encoder_pos) + "," + String(rev_count_time);
Serial.println (data);
temp = encoder_pos;
}
}
void encoder_position_A()
{
rev_count_time = micros();
if(digitalRead(encoderPinB)==LOW)
{
if (temp >= 1199) {encoder_pos = 0;}
else{ encoder_pos++; }
}
else
{
if (temp == 0) {encoder_pos = 1199;}
else{ encoder_pos--;}
}
}
void encoder_position_B()
{
rev_count_time = micros();
if(digitalRead(encoderPinA)==LOW)
{
if (temp == 0) {encoder_pos = 1199;}
else{ encoder_pos--;}
}
else
{
if (temp >= 1199) {encoder_pos = 0;}
else{ encoder_pos++; }
}
}