Skip to main content
18 votes
Accepted

Reading several rotary encoders

Library and schematics are at https://github.com/maxgerhardt/rotary-encoder-over-mcp23017. To read a rotary encoder (i.e., detect state changes of the knob), there are two possible implementations: ...
Maximilian Gerhardt's user avatar
11 votes

How to design and debug a custom I2C master-slave system?

This tutorial I gave at the Embedded Linux Conference tries to answer the questions, providing links to more detailed description of the topics addressed and using the practical example of driving a ...
Igor Stoppa's user avatar
  • 2,125
6 votes

How to detect the direction of a rotary encoder?

I have a page about rotary encoders - in that I show how you can detect encoder changes (and direction) using one interrupt pin and another pin, like this: // Wiring: Connect common pin of encoder to ...
Nick Gammon's user avatar
  • 38.4k
3 votes

How to detect the direction of a rotary encoder?

Using polling to read multiple encoders may work if you program quite carefully and if you dedicate the processor just to reading encoders; but generally, interrupt-driven encoder processing has a ...
James Waldby - jwpat7's user avatar
3 votes
Accepted

Interfacing pc mouse (serial port DB-9)

A serial mouse is designed to connect to a PC's true serial port - it's an actual RS-232 device using ±5V. As such it won't connect directly to the Arduino's RX/TX pins, you'll have to go through an ...
John Burger's user avatar
  • 1,875
3 votes
Accepted

Interfacing with an SSI sensor?

It's just SPI. SPI.begin(); SPI.setDataMode(SPI_MODE2); // ... uint8_t h = SPI.transfer(0x00); uint8_t l = SPI.transfer(0x00); delayMicroseconds(20); // Indicate EOT uint16_t v = (h << 8) | l;...
Majenko's user avatar
  • 105k
3 votes

Will a simple RC filter work with my mechanical rotary encoder, or do I need a Schmitt trigger?

Having just chased a problem using a software based debounce for several days, what I'll add is that for the encoders I was using (green no-name Chinese ones), if you put 10mA though the contacts then ...
MikeDB's user avatar
  • 131
3 votes

How to sample incoming 600khz pin and divide it by 4 and generate low frequency signal at output pin of arduino

This is probably too fast to have have software involved in the loop. You should try to use a hardware-only solution. Note the Arduino timers should be usable as hardware frequency dividers: ...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

Unexplainable int behavior in encoder/LED project

Here: CRGB leds[NUM_LEDS]; you are defining an array of NUM_LEDS objects of the CRGB type. Valid indices for this array range from 0 to NUM_LEDS-1. Here: for (int i = 0; i <= NUM_LEDS; i++) { ...
Edgar Bonet's user avatar
  • 43.3k
3 votes

How do you determine Lead Screw position using Absolute Encoder?

The encoder attaches to the motor (or other) shaft and sends a 10-bit rotational position for a precision of 0.35 deg, and a claimed accuracy of +/- 0.7 degrees. It will be up to the application to ...
JRobert's user avatar
  • 15.3k
3 votes
Accepted

Change Interrupts on the ATTiny 88

Interrupt types One source says there are only two interrupt pins, ... There are two "external interrupt" pins; that is the term you'll find in the chip's datasheet. This is the term that ...
timemage's user avatar
  • 5,299
2 votes

How do I read a sub-degree angle?

Try a spirit level (also called bubble level) app on your phone or tablet. It can get to sub-degree accuracy, but it is relative and not absolute accuracy. If that is good enough for you, then you ...
Jot's user avatar
  • 3,246
2 votes

How do I read a sub-degree angle?

I've looked at rotary encoders, but even those with no detents have about 24 pulses per rotation. It sounds like you have been looking at encoders intended for user input controls. Optical Rotary ...
Chris Stratton's user avatar
2 votes
Accepted

Why is my code only reading the change of the encoder's pin A?

You're confusing interrupt events and pin states here. A pin can be either HIGH or LOW. Never anything else. An interrupt can trigger on one of four events: The pin transitions from HIGH to LOW (...
Majenko's user avatar
  • 105k
2 votes

Arduino Rotary Encoder Pulses?

Add Serial.begin(115200); in setup() and use Serial.println() or Serial.print() to print to Serial. In Arduino IDE open Serial Monitor and set baud rate to 115200. EDIT: The question turned out to ...
Juraj's user avatar
  • 18k
2 votes
Accepted

Problem in reading data from encoder with arduino

In my experience (industrial encoders and PLCs) when the output don't change when the motor shaft is rotated its usually one of the following: The set screw connecting the motor shaft to the encoder ...
MrFixIt87's user avatar
  • 102
2 votes

Optical Rotary Encoder Index issue

In your onReset() function you have an assignment instead of a comparison: if (i = 1) // This is always true { encoder0Position = 0; } i = 1 should be i == 1
Craig's user avatar
  • 2,120
2 votes

Will a simple RC filter work with my mechanical rotary encoder, or do I need a Schmitt trigger?

The answer seems to be no. I added the RC filter suggested by the manufacturer and the results still jump around (The values sometimes increase by several steps at once, or decrease even when turning ...
Duncan C's user avatar
  • 5,702
2 votes
Accepted

How to add numbers to a position when controlling a seven-segment display

In your code, you call: newPos = encoder.getPosition(); which grabs the absolute position of the encoder. When you rotate this one step, the value of newPos goes up (or down) by one. Then, you make ...
jose can u c's user avatar
  • 6,974
2 votes

Undocumented industrial servo with 8-wire encoder: how to read this encoder?

I had some trouble figuring this out too. I did some more googling and found this site below via an Arduino forum post: 8 wire connection for quadrature encoder, differential wiring Here is what they ...
knightridar's user avatar
2 votes
Accepted

KY-040 rotary encoder skipping steps

I applaud you for your tenacity with the "debouncing" idea, but there is an excellent library for this rotary encoder, and the author has also written an article about it: Ben Buxton - rotary encoders ...
VE7JRO's user avatar
  • 2,558
2 votes
Accepted

Is it possible to get which pin generated interrupt?

It is not possible to know which interrupt caused the ISR to be called. The INTFx flag gets cleared when the interrupt routine is called, so you lose that information (which is a shame). The closest ...
Majenko's user avatar
  • 105k
2 votes
Accepted

Basic doubt regarding encoders with Arduino

You code counts pulses just fine when tested here. Fan/motor tachometer outputs and encoders frequently are set to switch your signal contact to ground, either with a transistor or mechanically. When ...
timemage's user avatar
  • 5,299
2 votes
Accepted

Multi turn potentiometer are a pain should I use a incremental encoder instead?

Yes, you can use a rotary encoder. However, there are two kinds of rotoary encoder: absolute, and relative. Relative encoders are the small common ones you find being used for things like volume ...
Majenko's user avatar
  • 105k
2 votes
Accepted

Setup Due counter

You need to pick a timer that isn't being used for anything else and configure it as a simple counter with the clock source set to the external clock pin for that timer. At block level, input clock ...
Majenko's user avatar
  • 105k
2 votes

I want a Rotary Encoder to make 10 steps at once, but my code isn't working. What am I doing wrong?

This is not an answer to the question, but a tip about simplifying your code. This is a snippet of your code. void loop() { // some more code here int encoder1State = encoder1.get_change(); ...
jsotola's user avatar
  • 1,515
2 votes
Accepted

Rotary encoder weird values

There are several problems happening here. Since your code only covers one input pin, I'm going to talk about input A. This pin is left floating! When you turn the dial, the brush connects A and/or B ...
AJ_Smoothie's user avatar
2 votes
Accepted

Encoder giving value between steps

This is the kind of thing that can happen when you buy cheap parts that come with no documentation whatsoever: you don't know how they are supposed to work! Many rotary encoders have two detents per ...
Edgar Bonet's user avatar
  • 43.3k
1 vote

ESP8266 Arduino and Rotary Encoder

The ESP8266 doesn't know what a "LOW" interrupt is. You will have to change your code to use FALLING, RISING or CHANGE interrupts only.
Majenko's user avatar
  • 105k

Only top scored, non community-wiki answers of a minimum length are eligible