GPIO driver for Rotary Encoders

Introduction

This Rotary Encoder driver can be used in conjunction with an incremental hardware rotary encoder. A rotary encoder, also called a shaft encoder, is an electro-mechanical device that converts the angular position or motion of a shaft or axle to analog or digital output signals.


Driver Parameters

The Rotary Encoder has three parameters that need to be configured:

CLK Pin

This pin provides the clock line from the rotary encoder. Any pin is suitable.

DT Pin

This pin provides the data line from the rotary encoder. The signal occurs either before or after the clock signal determining the direction the rotary encoder is turned. Any pin is suitable.

BTN Pin

This is the pin that transfers the signal when the rotary encoder is pushed on top. Any pin is suitable.


Wiring

Example

The GP0, GP1 and GP2 pins of the Builder Base are connected to the Clock, Data and Switch pin of the rotary encoder. The GND and V+ pins of the rotary encoder are then connected to the GND and 3.3V ports on the Builder Base respectively.

Breadboard 

Schematic 

Used Pins

Used Pins

Description

Used Pins

Description

GP0 (Can be any GP pin)

The clock line

GP1 (Can be any GP pin)

The data line

GP2 (Can be any GP pin)

The switch line

3.3V 

This pin provides the power

GND

This pin provides the GND


How to write an App

Navigate to the App Builder and create a new application. You can find the “Light” code object under the “Hardware” Tab in the object drop down menu on the left, or you can also use the search bar.

 

 

 

Drag the “Rotary Encoder” object onto the canvas.

The rotary encoder has three ports. First port is the “Increment” port. By rotating the encoder in the clockwise direction we can increase something. It depends on the parameters. Same with the “Decrement” port. Rotating the encoder in the counter clockwise direction we are going to decrease. The “Button” port can be used by pushing on the rotary encoder. We can use the button to start or shut down something for instance.

For an example we will use the rotary encoder to control a dc motor. The dc motor can be used to power a fan. When connecting the “Increment” port with the “Clockwise” port of the motor we can adjust the speed of the fan in the clockwise direction. Using the “Decrement” port connected to the “Counter Clockwise” port we can decrease the speed of the fan or even let the fan spin in the counter clockwise direction.


How to create a firmware

Navigate to the Firmware Builder and create a new firmware file.

Click the “+ Add Hardware” button which will open a modal window. Scroll down in the list to find the “Electrical” section and select the “Light” hardware option.

Give your device a name, and click “Add Hardware”

 

 

Next, select the “Rotary Encoder” driver under the driver dropdown menu.

 

 

 

 

For this example we select:

CLK Pin: GP0

DT Pin: GP1

BTN Pin: GP2

 

You may now save your firmware file and upload it to one of your clients.

 

 

 


Supported Hardware

  • Rotary Encoder

Downloads

Apps

 

Firmware

Assets