Skip to main content

Grove - Optical Rotary Encoder(TCUT1600X01)

pir

The Grove - Optical Rotary Encoder(TCUT1600X01) is a transmissive sensor that includes an infrared emitter and two phototransistor detectors. Usually, the infrared emitter emits infrared rays, the phototransistor detectors receives the infrared rays, then the phototransistor is turned on, both of the output is High, the on-board LED indicators light up. When there is an obstacle blocking, the phototransistor can not receive the infrared rays, so the phototransistor will be turned off and both of the output will be Low, the on-board LED indicators fade away.

You can use this sensor as a rotary encoder to detect the speed or rotation, and thanks to the two phototransistor detectors, you even can detect the rotation direction.

pir

Features

  • Double phototransistor detectors, can determine the direction of rotation
  • On-board LED indicators
  • Grove Interface

Specification

ItemValue
Operating voltage3.3V / 5V
Operating temperature-40°C to +105°C
Storage temperature Range-40°C to +125°C
Emitter wavelength950 nm
Gap3 mm
InterfaceDigital

Applications

  • Automotive optical sensors
  • Accurate position sensor for encoder
  • Sensor for motion, speed, and direction
  • Sensor for “turn and push” encoding

Hardware Overview

Pin Map

pir

Schemaitc

Power

pir

The typical voltage of TCUT1600X01 is 5V, so we use the MP3120 current mode step-up converter to provide a stable 5V. The input of MP3120 ranges from 0.8V to 5V, so you can use this module with your Arduino both in 3.3V and 5V.

pir

When the phototransistor detectors receive the infrared signal, the output should be High, and when the obstacle blocks the infrared, the OUT1 and OUIT2 should be Low. However due to the leakage current, it won't be 0V. The leakage voltage varies with the input voltage.

Mechanical Drawing

pir

Directional Detection

pir

tip
Thanks to the two phototransistor detectors, we can detect the moving direction. If the obstacle moves from the left to right, The output states change should be **11 --> 01 --> 00 --> 10**; in the same way, if the obstacle moves from the right to left, it should be **11 --> 10 --> 00 -->01**.

Platforms Supported

ArduinoRaspberry Pi

pir

pir

caution
The platforms mentioned above as supported is/are an indication of the module's software or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Getting Started

Play With Arduino

Hardware

Materials required

Seeeduino V4.2Base ShieldGrove - Optical Rotary Encoder

pir

pir

pir

Get One NowGet One NowGet One Now
note
**1** Please plug the USB cable gently, otherwise you may damage the port. Please use the USB cable with 4 wires inside, the 2 wires cable can't transfer data. If you are not sure about the wire you have, you can click [here](https://www.seeedstudio.com/Micro-USB-Cable-48cm-p-1475.html) to buy

**2** Each Grove module comes with a Grove cable when you buy. In case you lose the Grove cable, you can click [here](https://www.seeedstudio.com/Grove-Universal-4-Pin-Buckled-20cm-Cable-%285-PCs-pack%29-p-936.html) to buy.
  • Step 1. Connect the Grove - Optical Rotary Encoder to the D5 port of the Base Shield.

  • Step 2. Plug Grove - Base Shield into Seeeduino.

  • Step 3. Connect Seeeduino to PC via a USB cable.

pir

note
    If we don't have Grove Base Shield, We also can directly connect this module to Seeeduino as below.
SeeeduinoGrove - Optical Rotary Encoder
5VRed
GNDBlack
D6White
D5Yellow

Software

note
    If this is the first time you work with Arduino, we strongly recommend you to see [Getting Started with Arduino](https://wiki.seeedstudio.com/Getting_Started_with_Arduino/) before the start.
  • Step 1. Install the Encoder Library in the Arduino IDE. You can find this library by the following path: Sketch-->Include Library-->Manage Libraries

pir

Then search for the encoder in the pop-up window. Find the Encoder by Paul Stoffregen, choose the Version1.4.1, then click Install.

pir

When the library is installed you will see INSTALLED , click Close then.

pir

Thanks for Paul for his splendid library.

  • Step 2. Restart the Arduino IDE. Open the example, you can open it in the following three ways:

    1. Open it directly in the Arduino IDE via the path: File --> Examples --> Encoder --> Basic.

    pir

    1. Open it in your computer by click the Basic.pde which you can find in the xxxx\Arduino\libraries\Encoder\examples\Basic, XXXX is the location you installed the Arduino IDE.

    pir

    1. Or, you can just click the icon

      pir

      in upper right corner of the code block to copy the following code into a new sketch in the Arduino IDE.

/* Encoder Library - Basic Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/

#include <Encoder.h>

// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(5, 6);
// avoid using pins with LEDs attached

void setup() {
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}

long oldPosition = -999;

void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}
tip
You can change two numbers to the pins connected to your encoder, for the Best Performance: both pins have interrupt capability, so you can change the code line 13 into <mark>Encoder myEnc(2, 3);</mark>, meanwhile, you should connect this sensor to the **D2** of the baseshield.
  • Step 4. Upload the demo. If you do not know how to upload the code, please check How to upload code.

  • Step 5. Open the Serial Monitor of Arduino IDE by click Tool-> Serial Monitor. Or tap the ++ctrl+shift+m++ key at the same time. Set the baud rate to 9600.

tip
 If every thing goes well, you will get the result. When you move the obstacle from left to right, the count value will increase by 1; when you move the obstacle from right to left, the count value will be decremented by 1.
Basic Encoder Test:
0
1
2
3
4
3
2
1
0
-1
-2
-3
-4

Play With Raspberry Pi (With Grove Base Hat for Raspberry Pi)

Hardware

  • Step 1. Things used in this project:

    Raspberry piGrove Base Hat for RasPi Grove - Optical Rotary Encoder
  • Step 2. Plug the Grove Base Hat into Raspberry.

  • Step 3. Connect the Grove - OLED Display 1.12'' to I2C port of the Base Hat.

  • Step 4. Connect the Raspberry Pi to PC through USB cable.

Software

  • Step 1. Follow Setting Software to configure the development environment install the grove.py to your raspberry pi.
  • Step 2. Excute below commands to run the code.
# virutalenv for Python3
virtualenv -p python3 env
source env/bin/activate
#enter commmand
grove_optical_rotary_encoder

Following is the grove_optical_rotary_encoder.py code.


'''
This is the code for
- Grove - Optical Rotary Encoder(TCUT1600X01) <https://www.seeedstudio.com/Grove-Optical-Rotary-Encoder-TCUT1600X0-p-3142.html>`_

Examples:

.. code-block:: python

from grove.grove_button import GroveButton
import time, sys

# connect to pin 5 (slot D5)
PIN = 5
encoder = GroveOpticalRotaryEncoder(PIN)

# Read the value every second and detect motion
while True:
print("\rPosition: {0} ".format(encoder.position()), file=sys.stderr, end='')
time.sleep(0.001)

'''
from __future__ import print_function
import time, sys, signal, atexit
from grove.gpio import GPIO

__all__ = ["GroveOpticalRotaryEncoder"]

# The UPM version rotaryencoder has bug result in segment fault.
# This pure python version could work well.
class GroveOpticalRotaryEncoder(object):
'''
Grove optical Rotary Encoder(TCUT1600X01) class

Args:
pin(int): the number of gpio/slot your grove device connected.
'''
def __init__(self, pin1, pin2 = None):
pin2 = pin1 + 1 if pin2 is None else pin2
self.__gpio = GPIO(pin1, GPIO.IN)
self.__gpio2 = GPIO(pin2, GPIO.IN)
self.__gpio.on_event = self.__gpio_event
self._pos = 0

# called by GPIO library
def __gpio_event(self, pin, value):
v1 = self.__gpio.read()
if not v1: return
v2 = self.__gpio2.read()
self._pos += 1 if v2 else -1

def position(self, pos = None):
'''
set or get the position counter

Args:
pos(int):
optinal, the position counter to be set.

if not specified, only get the current counter

Returns:
(int): current position counter
'''
if not pos is None:
self._pos = pos
return self._pos

def main():
from grove.helper import SlotHelper
sh = SlotHelper(SlotHelper.GPIO)
pin = sh.argv2pin()

'''
from upm.pyupm_rotaryencoder import RotaryEncoder as GroveOpticalRotaryEncoder
from mraa import getGpioLookup

mraa_pin1 = getGpioLookup("GPIO%02d" % (pin + 0))
mraa_pin2 = getGpioLookup("GPIO%02d" % (pin + 1))

# Instantiate a Grove Rotary Encoder, using signal pins mraa_pin1 & mraa_pin2
myRotaryEncoder = GroveOpticalRotaryEncoder(mraa_pin1, mraa_pin2);
'''
myRotaryEncoder = GroveOpticalRotaryEncoder(pin)

## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit

# This function lets you run code on exit, including functions from myRotaryEncoder
def exitHandler():
print("Exiting")
sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

# Read the value every second and detect motion
counter = 0
while True:
print("\rPosition: {0} ".format(myRotaryEncoder.position()), file=sys.stderr, end='')
counter += 1
if counter >= 5000:
print("")
counter = 0
time.sleep(0.001)

if __name__ == '__main__':
main()
(env)pi@raspberrypi:~ grove_optical_rotary_encoder
success

When the command runs successfully, it will print out the value every second and detect motion.

# Read the value every second and detect motion
while True:
print("\rPosition: {0} ".format(encoder.position()), file=sys.stderr, end='')
time.sleep(0.001)

You can quit this program by simply press ctrl+c.

Schematic Online Viewer

Resources

Project

This is the introduction Video of this product, simple demos, you can have a try.

Tech Support & Product Discussion

Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.

Loading Comments...