Blynk Board Arduino Development Guide

Pages
Contributors: Jimb0
Favorited Favorite 0

Introduction

After successfully provisioning a SparkFun Blynk Board, and exhausting all of the examples in the Blynk Board Project Guide, you may be asking yourself: “What’s next?” The answer to that question is: “It’s completely up to you!” Now that you’re a professional Blynker, you have all of the tools necessary to create a Blynk project of your own!

alt text

This tutorial demonstrates how to add Blynk Board support to the Arduino IDE, so you can get started writing and uploading Blynk firmware of your own. If you really liked the BotaniTweet project from the Project Guide, but just wanted to tweak a few things, this tutorial will provide you with the tools necessary to start down that road.

The Blynk Board Tutorial Trilogy

This tutorial is structured as a follow-up to the Blynk Board Project Guide, which is itself a sequel to the Getting Started With the Blynk Board tutorial.

Uploading new code to the Blynk Board will (at least temporarily) remove the pre-loaded Blynk Board projects from the board. It will also remove provisioning functionality.

The firmware is open-source, however. So if you want to get the Blynk Board's default firmware loaded back up, all you have to do is load it back on!

Install FTDI Drivers

The Blynk Board uses a specialized chip called an “FTDI” to convert USB data to a more simple serial interface. It’s over this serial interface that the Blynk Board downloads new code.

If you’ve never used an FTDI-based device before, you’ll probably need to install drivers on your computer. Our How to Install FTDI Drivers tutorial should help get your drivers installed, whether you’re on a Mac, Windows, or Linux machine.

Install FTDI Drivers

Once you’ve installed the drivers, your Blynk Board should show up on your computer as either COM# (if you’re on a Windows machine) or /dev/tty.usbserial-######## (if you’re on a Mac/Linux computer), where the #’s are unique numbers or alphabetic characters.

Install the Blynk Board Arduino Addon

To use the Blynk Board in Arduino, you’ll need to install a few additional files on top of the core Arduino program. Fortunately for us, Arduino’s new Board Manager feature makes that just a few copy/pastes and button-clicks away!

Download, Install Arduino

If you've never used an Arduino Board, or the Arduino IDE before, we apologize in advanced for potentially feeding a new addiction.

Arduino is an open-source development environment for embedded microcontrollers. But, beyond that, it's a simplified programming language, standardized hardware layout, and a helpful community.

Download Arduino!

Head over to Arduino.cc to download the software. It'll run on Windows, Mac, Linux – almost anything you can throw at it!

Install the Blynk Board Addon

We’ll use the Arduino Board Manager feature to help set the IDE up for the Blynk Board. Follow the steps below to instill the IDE with Blynk Board compatibility.

Step 1: Give Arduino the Link

To tell Arduino where to get the board definitions from, open the Arduino preferences, which you’ll find under the File > Preferences menu.

Opening arduino preferences

Then copy this URL:

https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json

And, paste it into the “Additional Board Manager URLs” text box.

Board definition location

Step 2: Install the Definitions

With the link pasted, hit OK in the preferences box. Then navigate to Tools > Board > Boards Manager….

Opening the boards manager

In the window that pops open next, search for “Blynk”. The “SparkFun ESP8266 Boards” menu entry should be the only survivor.

alt text

Select that, and click Install. The process may take a couple minutes to download, as the tools are about 100MB.

Step 3: Select the Blynk Board

After the board manager successfully grabs the Blynk Board definitions, look under the Tools > Board menu again – you should see a menu entry for SparkFun Blynk Board.

alt text

Select that, and you’re just about there. Time to load some Blynk code!

Get a Blynk Auth Token

The Blynk Board Arduino addon includes the Blynk Arduino library, so you should have almost everything you need to start Blynking.

Almost…

Every Blynk project is assigned a unique 32-byte string called the “auth token”, which allows your hardware communicate with a specific project in the app. When you upload a new program to the Blynk Board, you need to program the auth token into it on top of any other code you may want to add.

To get a new Blynk auth token, you have two options: use the same project from before, or create a new project.

Option 1: Getting the Code From a Previously Created Blynk Project

Reusing a Blynk project is a great way to save energy, as long as you don’t mind deleting or modifying a few widgets.

To find an existing Blynk project’s auth token, stop the project, then hit the hexagon-shaped nut in the upper right corner to open the project settings.

Opening settings

On the settings page, scroll down a bit to find the “Auth Token” section, where you’ll find a long, incomprehensible 32-character string and a couple handy buttons. Tap the E-MAIL button, to have the code e-mailed to your Blynk-connected email address.

Email the blynk auth token

Turn your computer towards your inbox, and look for an email from dispatcher@blynk.cc.

alt text

Keep the auth token handy! You can hit “OK” (iOS) or the upper-left back arrow (Android) to exit your project’s settings page.

Option 2: Create a New Blynk Project

If you want to start fresh, with a new Blynk project, begin by backing out to the Blynk project navigator screen – hit the upper-left “back” button if you’re in a project.

Next, scroll as far to the right of the project navigator screen as you can, and find the Create New Project button.

alt text

Clicking that will lead you to the “Project Settings” page. Name your project, and set the Hardware Model to SparkFun Blynk Board.

alt text

Most importantly on this screen, tap E-Mail under the Auth Token to send yourself a copy of the 32-byte string.

Finally, tap Create Project to find yourself on a blank Blynk project.

Set Up the Blynk Project

This example Blynk program only specifies functionality for the RGB LED, but you can use any of the hardware pins regardless of what the firmware specifies.

Configure the Button, LED, and ADC

You can use the button widget to drive the tiny, blue, pin 5 LED. Configure it as either push or pull; just make sure the pin is set to 5.

Configure the Button widget

The Blynk Board’s physical button can trigger a value widget. Set the widget’s pin to 0.

Configure a value widget to read the button

Finally, you can use either a gauge or value widget to display the value of the ADC. Just make sure to set the pin to ADC.

Configure the gauge widget to read the ADC

Configure the zeRGBa

To use the zeRGBa widget, add it, set the switch to Merge and set the pin to V0.

zeRGBa configuration

Your project may look a little something like this when it’s all configured:

Example project layout

Load an Example Program

With the Blynk auth token at hand and the project set up, you’re armed with all of the information you’ll need to get your board Blynking again.

Configure the Code

Copy and paste this code into your Arduino IDE, but don’t upload it yet!

language:c
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoPixel.h>

////////////////////
// Blynk Settings //
////////////////////
char BlynkAuth[] = "Your_Auth_Token";
char WiFiNetwork[] = "Your_WiFi_Network";
char WiFiPassword[] = "Your_WiFi_Password";

///////////////////////
// Hardware Settings //
///////////////////////
#define WS2812_PIN 4 // Pin connected to WS2812 LED
#define BUTTON_PIN 0
#define LED_PIN    5
Adafruit_NeoPixel rgb = Adafruit_NeoPixel(1, WS2812_PIN, NEO_GRB + NEO_KHZ800);

BLYNK_WRITE(V0) // Handle RGB from the zeRGBa
{
  if (param.getLength() < 5)
    return;

  byte red = param[0].asInt();
  byte green = param[1].asInt();
  byte blue = param[2].asInt();

  uint32_t rgbColor = rgb.Color(red, green, blue);
  rgb.setPixelColor(0, rgbColor);
  rgb.show();
}

void setup()
{
  // Initialize hardware
  Serial.begin(9600); // Serial
  rgb.begin(); // RGB LED
  pinMode(BUTTON_PIN, INPUT); // Button input
  pinMode(LED_PIN, OUTPUT); // LED output

  // Initialize Blynk
  Blynk.begin(BlynkAuth, WiFiNetwork, WiFiPassword);
}

void loop()
{
  // Execute Blynk.run() as often as possible during the loop
  Blynk.run(); 
}

Before uploading the code, you’ll need to adjust three variables towards the top of the sketch:

  1. Paste your Blynk auth token over Your_Auth_Token, setting the BlynkAuth variable.
  2. Paste your WiFi network name over Your_WiFi_Network, setting the WiFiNetwork variable.
  3. Paste your WiFi password over Your_WiFi_Password, setting the WiFiPassword variable
    • If the network is open, leave the string empty ("").

Upload the Code

Before uploading, you’ll need to configure the serial port – the “COM#” or “/dev/tty.usbserial-########” number you discovered way back at the FTDI driver-installation phase. Knowing that, navigate to Tools > Port, and select your port number.

Serial port selection

We also suggest increasing the upload rate to 921600. You’ll find that setting under the Tools > Upload Speed option.

This is the moment of truth! Once the code has been configured, hit the Upload button (the right-pointing arrow).

Your computer may take a minute-or-so to compile the code and send it over to the Blynk board. Arduino should inform you if the upload was successful or not. If not – double check the board and port settings, and give it another try. Sometimes that’s all it takes.

Check the Serial Monitor

If the code successfully uploads, open the serial monitor – the magnifying glass icon, in the upper right portion of the Arduino IDE.

This window will pass some handy debug information. It’ll tell you if the Blynk Board successfully connected to your WiFi network and the Blynk server.

alt text

If you see a “Ready” message – you should be good to Blynk! Do some zeRGBa'ing, press some buttons, and adjust some analog inputs! You’re well on your way to making your own Blynk projects.

Resources and Going Further

Now that you have an Arduino-programmable, Blynking Blynk Board, what new amazing IoT project are you going to make? Need some inspiration? Check out some of these tutorials:

LED Cloud-Connected Cloud

Make an RGB colored cloud light! You can also control it from your phone, or hook up to the weather!

Blynk Board Project Guide

A series of Blynk projects you can set up on the Blynk Board without ever re-programming it.

Blynk Board Bridge Widget Demo

A Blynk project that demonstrates how to use the Bridge widget to get two (or more) Blynk Boards to communicate.

Blynk Board Washer/Dryer Alarm

How to configure the Blynk Board and app to notify you when your washer or dryer is done shaking.

If you need general Blynk Board or Blynk App resources, these may help:


If you need any technical assistance with your Blynk Board, don’t hesitate to contact our technical support team via either e-mail, chat, or phone.