Skip to content

Rotary Switch Wireling Tutorial

TinyCircuits Rotary Switch Wireling product photo

This Wireling features a 10 position Rotary Encoder. This board is a great choice for discrete setting adjustments and other forms of input for your project.

Technical Details

SH-7010TA Rotary Encoder Specs

  • 10 Position Switch
  • I2C Semtech SX1505 I/O Expander

    TinyDuino Power Requirements

    • Voltage: 3.0V - 5.5V 
    • Current: 1.0uA (Normal Mode).  Due to the low current, this board can be run using the TinyDuino coin cell option

    Pins Used

    • A5/SCL - I²C Serial Clock line
    • A4/SDA - I²C Serial Data line

    Dimensions

    • 16mm x 10mm (.630 inches x .393 inches)
    • Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 7.50mm (0.30 inches)
    • Weight: 1 gram (.04 ounces)

    Materials

    To interface with any TinyCircuits Arduino board, you will need the Arduino IDE and a Micro USB Cable

    There are multiple processor/adapter combinations that can be used with Wirelings. Use the following table to find the combination that works for you.

    Processor Adapter
    * and
    *
    *
    N/A
    * N/A
    Arduino
    Raspberry Pi

    * These processors have a 32-pin connector and can have multiple Wireling Adapter TinyShields stacked to increase the number of Wireling ports up to a maximum of 32 total Wireling ports.

    In order to interface with Wirelings, you'll need the appropriate number of Wireling Cables and the Wireling.h Library (You can download this from GitHub as linked, or from the Library Manager in the Arduino IDE).

    You will also need the Rotary Switch Wireling and the included example Arduino sketch.

    Wireling Code
    Port 0

    Hardware Assembly

    Depending on the development system you choose, you will need to put together a TinyDuino stack using the 32-pin tan connectors, or you will just need to plug in your Wireling to Port 0 using a Wireling Cable. (You can change this port in the included Arduino Sketch using the Wireling.selectPort() function)

    NOTE: Be mindful when inserting Wireling Cables - the connector pins inside the 5-pin connectors on Wirelings can be bent when cables are inserted at an angle.

    Hardware Assembled


    Software Setup

    If you have not already done so, download the Rotary Switch Example Sketch and open it in the Arduino IDE.

    You will need to download and install the SX1505 Library for this example:

    To install an Arduino library, check out our Library Installation Page.

    Make the correct Tools selections for your development board. If unsure, you can double check the Help page that mentions the Tools selections needed for any TinyCircuits processor.


    Upload Program

    Upload the program and open the Serial Monitor to see the direction of the joystick (up, down, left, right) printed when pressed.

    Code
    /*
      Rotary Example
      Prints the value of the direction the rotary arrow is pointing 0-9
      to the Serial Monitor
      Written by: Laveréna Wienclaw for TinyCircuits
      https://TinyCircuits.com
    */
    
    #include <Wire.h>
    #include <Wireling.h>
    #include <SX1505.h>            // For interfacing with Joystick and Rotary Switch Wirelings
    
    // Universal Serial Monitor Config
    #if defined (ARDUINO_ARCH_AVR)
    #define SerialMonitorInterface Serial
    #elif defined(ARDUINO_ARCH_SAMD)
    #define SerialMonitorInterface SerialUSB
    #endif
    
    /* * * * * * * * * * Rotary * * * * * * * * * */
    #define ROT_PORT 0 
    TinyRotary rotary = TinyRotary(); 
    uint8_t rotaryValue;
    
    void setup() {
      Wire.begin();
      Wireling.begin();
    
      /* * * * * * Rotary Init * * * * */
      Wireling.selectPort(ROT_PORT); 
      rotary.begin(); 
    
      SerialMonitorInterface.begin(9600);
      delay(500);
    }
    
    void loop() {
      rotaryValue = rotary.getPosition();
      writeToMonitor();
    }
    
    void writeToMonitor() {
      SerialMonitorInterface.println("Rotary: " + String(rotaryValue) + "\t");
      delay(100);
    }
    

    After uploading, open the Serial Monitor for feedback as you change the position of the rotary switch. The number the arrow on the rotary switch is pointing is what will be printed. Note: to turn the rotary switch you will likely want something thin to insert into the arrow slit for a more permanent usage.


    Bonus Screen Example

    There is an extended example that uses the 0.42" OLED Screen, and Rotary Switch in addition to the Joystick. This program will display the number the rotary switch is point to, and an arrow in the direction of the joystick:

    You will need to download and install the TinierScreen Library and GraphicsBuffer Library for this example:

    After uploading, either look to the Serial Monitor or 0.42" OLED Screen Wireling for feedback as you change the position of the rotary switch. The number the arrow on the rotary switch is pointing is what will be printed.


    Downloads


    Contact Us

    If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

    Thanks for making with us!