Skip to content

Wireling Kickstarter Starter Kit Tutorial

Gif demonstrating the behavior of the Wirelings with the program included in the tutorial running.

If you backed the Wireling Kickstarter for the Starter Kit, and selected a WirelingZero, there is already code loaded onto the Tiny processor. To see what it does, follow this scheme for plugging in the Wirelings:

Wireling Port Assignments
Port 0 0.42" OLED
Port 1 RGB LED
Port 2 TOF Sensor
Port 3 Color Sensor

Plug in the rechargeable battery to the battery port. (You may need to charge the battery, to do so just plug it into the WirelingZero and plug the Wireling in somewhere with a MicroUSB cable)

The screen on Port 0 will display the RGB values read from the color sensor, and will also display the distance detected by the TOF sensor Wireling in mm. The RGB LED Wireling will be updated to the RGB values read by the color sensor.


If you did not select the WirelingZero, or you were not a backer, the rest of this page is a tutorial for uploading the same program to any Wireling platform!

This tutorial shows you how to use four of the Wirelings included in the Wireling Kickstarter Basic Kit in one program! Before proceeding, it is recommended that you have already gone through at least the setup tutorial of the WirelingZero or Wireling Arduino Shield to ensure you have any software this program depends on.


Materials

In order to interface with any Arduino-based board, you'll need the Arduino IDE.

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
*TinyDuino and USB TinyShield Wireling Adapter TinyShield
*TinyZero Wireling Adapter TinyShield
*TinyScreen+ Wireling Adapter TinyShield
WirelingZero N/A
*RobotZero N/A
Arduino Wireling Arduino Shield
Raspberry Pi Wireling Pi Hat

* 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).

The table below details which Wirelings are used on each port. The tutorials and libraries for each of these Wirelings are also included.

Wireling Learn Library
Port 0 0.42" OLED 0.42" OLED TinierScreen and GraphicsBuffer
Port 1 RGB LED RGB LED FastLED
Port 2 TOF Sensor TOF Sensor VL53L0X
Port 3 Color Sensor Color Sensor Adafruit_TCS34725

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 Wirelings to the following Ports:

Wireling Port Assignments
Port 0 0.42" OLED
Port 1 RGB LED
Port 2 TOF Sensor
Port 3 Color Sensor

If you want to change which ports these are, there is a section above the setup() routine in the program that contains the port and pin definitions, you can change these values to suit your needs.


Software setup

If you have not already, download the libraries found under the Materials section above. If you have never installed an Arduino library, check out our Library Installation Help Page for some quick how-to information.

Then, make the correct Tools selections for your development board. If you are unsure what to select, you can double check the Help page that mentions the Tools selections needed for any TinyCircuits processor.


Upload Program

Upload the program to your development board of choice!

Download Arduino Sketch

Wireling Program
/************************************************************************
 * Wireling Starter Kit Shipment Program
 * This program uses four of the Wirelings included with the Starter Kit:
 * Port 0: 0.42" OLED Screen Wireling
 * Port 1: RGB LED Wireling
 * Port 2: TOF Sensor Wireling
 * Port 3: Color Sensor Wireling
 * 
 * When plugged in according to the above mapping, the 0.42" Screen will 
 * display the RGB values read from the color sensor, and will also display 
 * the distance detected by the TOF sensor Wireling in mm. The RGB LED
 * Wireling will be updated to the RGB values read by the color sensor.
 *
 * Hardware by: TinyCircuits
 * Written by: Hunter Hykes for TinyCircuits
 *
 * Initiated: 12/18/2019 
 * Updated: 12/19/2019
 ************************************************************************/

#include <Wire.h>               // For I2C communication with sensor
#include <Wireling.h>
#include <TinierScreen.h>       // For interfacing with the 0.42" OLED
#include <GraphicsBuffer.h>     // For building a screen buffer for the 0.42" OLED
#include <FastLED.h>            // For interfacing with the RGB LED
#include "VL53L0X.h"            // For interfacing with the Time-of-Flight Distance sensor
#include <Adafruit_TCS34725.h>  // For interfacing with the Color Sensor

// Make compatible with all TinyCircuits processors
#if defined(ARDUINO_ARCH_AVR)
#define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#endif

/* * * * * * * * * * 0.42" OLED * * * * * * * * * */
#define OLED_042_PORT 0 // use Port 0 for screen
#define OLED_042_RESET (int) A0 // use Port 0 reset pin
#define OLED_042_WIDTH 72
#define OLED_042_HEIGHT 40
TinierScreen display042 = TinierScreen(TinierScreen042);
GraphicsBuffer screenBuffer042 = GraphicsBuffer(OLED_042_WIDTH, OLED_042_HEIGHT, colorDepth1BPP);

/* * * * * * * * * * * RGB LED * * * * * * * * * * * */
#define NUM_LEDS 1 //this is the number of LEDs in your strip
#define DATA_PIN (uint8_t) A1
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int brightness = 20; //value from 0-255 to manipulate brightness

/* * * * * * * * * * TOF Sensor * * * * * * * * * * */
#define TOF_PORT 2 // use Port 2 for TOF sensor
VL53L0X distanceSensor;

/* * * * * * * * * * Color Sensor * * * * * * * * * */
#define TCS_PORT 3 // use Port 3 for color sensor
#define TCS_LIGHT 9 // analog pin on Wireling connector for powering white LEDs
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_24MS, TCS34725_GAIN_1X);
uint16_t r, g, b, c, colorTemp, lux; // Variables to hold the values the sensor reads

void setup(void) {
  SerialMonitorInterface.begin(115200);
  Wire.begin();
  Wireling.begin(); // Enable power & select port
  delay(200); // boot sensor

  /* * * * * * Screen Stuff * * * * */
  Wireling.selectPort(OLED_042_PORT);
  display042.begin(OLED_042_RESET);
  if (screenBuffer042.begin()) {
    //memory allocation error- buffer too big!
  }
  screenBuffer042.setFont(thinPixel7_10ptFontInfo);

  /* * * * * RGB LED Stuff * * * * */
  FastLED.addLeds<WS2812B, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(brightness);
  pinMode(DATA_PIN, OUTPUT);
  pinMode(TCS_LIGHT, OUTPUT);


  /* * * * * TOF Stuff * * * * */
  Wireling.selectPort(TOF_PORT);
  distanceSensor.init();
  distanceSensor.setTimeout(500);
  distanceSensor.setMeasurementTimingBudget(200000);
  distanceSensor.startContinuous();

  /* * * * * Color Sensor Stuff * * * * */
  Wireling.selectPort(TCS_PORT); //The port is the number on the Adapter board where the sensor is attached
  tcs.begin();
  LEDon(); // turn on color sensor Wireling LEDs
}

int x, y;
String distance;

void loop(void) {
  Wireling.selectPort(TCS_PORT);
  tcs.getRawData(&r, &g, &b, &c);
  //colorTemp = tcs.calculateColorTemperature(r, g, b);
  //lux = tcs.calculateLux(r, g, b);

  updateRGBLED(r, g, b);
  delay(10);
  getTOFdistance();

  printRGBtoOLED();
  printTOFdistance();
  display042.writeBuffer(screenBuffer042.getBuffer(), screenBuffer042.getBufferSize()); // write buffer to the screen
}

void updateRGBLED(uint16_t red, uint16_t green, uint16_t blue) {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB(green, red, blue); // GRB
    FastLED.show(); //update the LEDs
  }
}

// print color sensor info to TinierScreen
void printRGBtoOLED() {
  Wireling.selectPort(OLED_042_PORT);           // select the Wireling screen port
  screenBuffer042.clear();                  // clear old screen contents
  screenBuffer042.setCursor(x = 24, y = 0);  // set cursor to (0, 0)
  screenBuffer042.print("R: " + String(r)); // print Red Value
  screenBuffer042.setCursor(x, y += 8);     // advance to next line (font height is 7 so use 8)
  screenBuffer042.print("G: " + String(g)); // print Green Value
  screenBuffer042.setCursor(x, y += 8);     // advance to next line
  screenBuffer042.print("B: " + String(b)); // print Blue Value
}

void getTOFdistance() {
  Wireling.selectPort(TOF_PORT);
  distance = String(distanceSensor.readRangeContinuousMillimeters());
}

void printTOFdistance() {
  Wireling.selectPort(OLED_042_PORT);           // select the Wireling screen port
  //screenBuffer042.clear();
  screenBuffer042.setCursor(x = 10, y = 24); // hard-coded to be last line
  screenBuffer042.print("Dist: " + distance + "mm");
}

// print color sensor info to SerialMonitorInterface
void printRGBReading() {
  SerialMonitorInterface.print("Color Temp: "); SerialMonitorInterface.print(colorTemp); SerialMonitorInterface.print(" K, ");
  SerialMonitorInterface.print("Lux: "); SerialMonitorInterface.print(lux, DEC); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("R: "); SerialMonitorInterface.print(r, DEC); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("G: "); SerialMonitorInterface.print(g, DEC); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("B: "); SerialMonitorInterface.print(b); SerialMonitorInterface.print(", ");
  SerialMonitorInterface.print("Clr: "); SerialMonitorInterface.print(c, DEC);
  SerialMonitorInterface.println(" ");
}

// Turn Wireling LEDs on
void LEDon() {
  tcs.setInterrupt(true);
}

// Turn Wireling LEDs off
void LEDoff() {
  tcs.setInterrupt(false);
}

You may notice in the Wireling Variables section above the setup() loop that there are a mix of PORT and PIN definitions. The majority of Wirelings use port definitions because they use I²C to communicate with the processor, other Wirelings just need an Input/Output pin. These differences are something to keep in mind as the 0.42" Screen, Color Sensor, and TOF Sensor are I²C devices, while the RGB LED Wireling just uses Input/Output pins A0-A3.


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!