Summary of Using the tymkrs “Turn Me” with an Arduino
This article explains how to use the tymkrs “Turn Me” rotary encoder with Arduino, emphasizing its push-down switch feature. It provides references to Fritzing parts, projects, and an Arduino sketch that handles rotary position counting and push button detection, including rollover limits between 0 and 255. The included code reads encoder signals, updates position values for both rotation and push states, and outputs these via serial communication.
Parts used in the tymkrs “Turn Me” Rotary Encoder Project:
- tymkrs “Turn Me” Rotary Encoder with Knob (Fritzing part: Rotary Encoder with Knob bth.fzpz)
- Arduino Board (compatible with Arduino 1.5 or newer)
- Push-down rotary encoder switch
Here is a quick write up on how to use the tymkrs “Turn Me” rotary encoder. This supports the “push down” feature of the tymkrs kit.
Fritzing Rotary Encoder Part: Rotary Encoder with Knob bth.fzpz
Fritzing Project: RotaryEncoderDemo.fzz
Arduino (1.5) project: RotaryEncoderDemo.ino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | /* Read Quadrature Encoder * Connect Encoder to Pins encoder0PinA, encoder0PinB, and +5V. * Sketch by max wolf / www.meso.net * v. 0.1 - very basic functions - mw 20061220 * Sketch updated by Brooke Hedrick / www.millamilla.com * v. 0.2 - Added the "S" pin for encoders with push-down support - bth 09292013 * - Put a limit of 255 and 0 in place. It rolls over automatically at the limits - bth 09292013 * */ int val; int encoder0PinA = 3; int encoder0PinB = 4; int encoder0PinS = 5; int encoder0PosUp = 0; int encoder0PosDown = 0; int encoder0PinALast = LOW ; int n = LOW ; int encoder0UpDown = LOW ; void setup () { pinMode (encoder0PinA, INPUT ); pinMode (encoder0PinB, INPUT ); pinMode (encoder0PinS, INPUT ); Serial.begin (9600); } void loop () { encoder0UpDown = digitalRead (encoder0PinS); n = digitalRead (encoder0PinA); if ((encoder0PinALast == LOW ) && (n == HIGH )) { //Serial.print("up down:"); //Serial.println(encoder0UpDown); if ( digitalRead (encoder0PinB) == LOW ) { if (encoder0UpDown == LOW ) { encoder0PosUp--; if (encoder0PosUp < 0) { encoder0PosUp = 255; } } else { encoder0PosDown--; if (encoder0PosDown < 0) { encoder0PosDown = 255; } } } else { if (encoder0UpDown == LOW ) { if (encoder0PosUp > 255) { encoder0PosUp = 0; } } else { encoder0PosDown++; if (encoder0PosDown > 255) { encoder0PosDown = 0; } } } Serial.print(encoder0PosUp); Serial.print( " " ); Serial.println(encoder0PosDown); } encoder0PinALast = n; } |
For more detail: Using the tymkrs “Turn Me” with an Arduino