Skip to content

Joystick Wireling Tutorial

TinyCircuits Joystick Wireling product photo

This Wireling features a 4 position digital joystick. This board is great for user input in games or RC (Radio Controller) projects.


Technical Details

This Wireling lets you use a discrete joystick for inputs to your development system of choice! This Up, Down, Left, Right joystick outputs data to an SX1505 I2C I/O expander.

Technical Details

SX1505 Specs

  • 8 Channel GPIO with NINT and NRESET
  • Fully programmable logic functions (PLD)

SKRHABE010 Joystick Specs

  • 4 Directional Digital Joystick
  • Center Pushbutton Input
  • 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 Clock 
    • A4/SDA - I²C Data

    Dimensions

    • 17mm x 10mm (.670 inches x .394 inches)
    • Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 16mm (0.63 inches)
    • Weight: 1 gram (.04 ounces)

    Notes

    • This is not a full range analog joystick. It is a discrete joystick which is essentially 4 buttons mounted sideways at the base of the joystick knob.

    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 Joystick Wireling and the included example Arduino sketch. The sketch is configured to use Port 0, however this can be changed if you'd like.

    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 Joystick Wireling 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
    /*
      Joystick Example
      Prints to the Serial Monitor the direction the joystick is moved in (Up, down, left, right)
      The "up" direction is the direction closest to the 5-pin connector.
      Written by: Laveréna Wienclaw for TinyCircuits
      Last Updated: March 2020
    */
    
    #include <Wire.h>
    #include <Wireling.h>
    #include <SX1505.h>             // For interfacing with Joystick and Rotary Switch Wirelings
    
    // Universal TinyCircuits Serial Monitor Config
    #if defined (ARDUINO_ARCH_AVR)
    #define SerialMonitorInterface Serial
    #elif defined(ARDUINO_ARCH_SAMD)
    #define SerialMonitorInterface SerialUSB
    #endif
    
    /* * * * * * * * * * Joystick * * * * * * * * * */
    #define JS_PORT 0
    TinyJoystick joystick = TinyJoystick(); 
    
    void setup() {
      Wire.begin();
      Wireling.begin();
    
      /* * * * * * Joystick Init * * * * */
      Wireling.selectPort(JS_PORT); 
      joystick.begin(); 
    
      SerialMonitorInterface.begin(9600);
      delay(500);
    }
    
    void loop() {
      joystick.getPosition();
      writeToMonitor();
    }
    
    void writeToMonitor() {
    
      if(joystick.up) {
        SerialMonitorInterface.println("UP (direction facing 5-pin connector)");
      }
      else if(joystick.down) {
        SerialMonitorInterface.println("DOWN");
      }
      else if(joystick.left) {
        SerialMonitorInterface.println("LEFT");
      }
      else if(joystick.right) {
        SerialMonitorInterface.println("RIGHT");
      }
      delay(100);
    }
    

    After uploading, open the Serial Monitor for feedback as you move the joystick. The "up" direction is registered when the joystick is pushed towards the Wireling cable.


    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 move the joystick. The "up" direction is registered when the joystick is pushed towards the Wireling cable. The screen will print directional arrows in respect to the direction read from the joystick.


    Projects

    • It is possible to create multiplayer games with two Joystick Wireling boards! However, it is important to acquire timestamps via the appropriate interrupt pins from each Wireling to make sure inputs are interpreted in the order they are received.

    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!