NYCCNC Thermal Printer Project

Contents

Purpose

High Level Architecture

External Services

Adafruit IO

Create an Account

Create a Feed

Your Adafruit IO Access Key

IFTTT

Create an Account or Just Log In

Create A New Applet

Hardware

Software

Arduino IDE

Install Arduino IDE

Add 8266 Platform Support

Install JSON Message Parsing Library

Install Thermal Printer Library

Thermal Printer Library Modifications

Serial Port Drivers

Update Sketch With Your Information

Program the Huzzah ESP8266 Board

Final Tests

Purpose

Use the If This Then That (IFTTT) service along with Adafruit IO to pass messages from external triggers like Asana events, emails, etc. to an Arduino and have the external messages printed on a thermal printer driven by the Arduino.

High Level Architecture

External Services

Adafruit IO

Create an Account

  • Go to and click “Get Started For Free” in the top right corner
  • Enter the requested information and click “Create Account”
  • Creating the account may take you away from the Adafruit IO site and leave you at the regular Adafruit website. If so, go back to and make sure you are signed in.

Create a Feed

  • Click “Feeds” at the left, then “Create a New Feed” in the Actions dropdown. You will be asked for a feed name and optional description. Spaces, underscores, and mixed case are accepted in the feed name but they will be replaced by dashes and all lower case for the URL used to access the feed. Therefore, you may want to stick with lower case and dashes to begin with so the displayed feed name exactly matches the corresponding URL.

Your Adafruit IO Access Key

  • Instead of entering a password in the conventional sense, accessing Adafruit IO feeds through the REST API makes use of a secret key that is unique to your account. You can view this key via the “View AIO Key” link at the left of the page. You will need this number, along with your username also displayed in the dialog, later when setting up the Huzzah 8266 software.

IFTTT

Create an Account or Just Log In

  • Go to , enter your email address where indicated, and click “Get Started”.
  • Enter a password at the next prompt and click “Sign Up”
  • Alternately to the above, you can just log directly in using your Google or Facebook credentials.

Create A New Applet

  • Click the “My Applets” link at the top of the page then click “New Applet”
  • On the next page, click the “+ this” link
  • You will be presented a large list of trigger sources. Select the source you want to use and configure it as required. As an example we will use and Email trigger.

  • After a trigger source is selected and configured, click “+ that” to configure an action that will be performed when the trigger occurs.
  • A long list of services will again be presented. Type “Adafruit” in the search box and click the Adafruit service.
  • There is only one option available for the Adafruit service, so click “Send data to Adafruit IO” which will then prompt for some configuration. If you used the same email address to join IFTTT as you did for your Adafruit account (highly recommended), it should automatically show your Adafruit IO feeds in the Feed name dropdown. Select the one you want to use. The options available in the Data to save box will likely depend on what trigger source you selected. For our email example, click the “Add Ingredient” button and choose Body. Click “Create action” to complete the applet creation.

Hardware

  • Refer to for information about the Huzzah ESP8266 microcontroller board with included WiFi.
  • Refer to for information about the Adafruit thermal receipt printer.
  • It is important to note that the Huzzah ESP8266 board runs on 3.3V, not 5V. It’s GPIO pins are NOT 5V tolerant, so connecting external devices that apply more than 3.3V to any pin could damage the microcontroller. Since the thermal printer we are using does indeed work with 5V levels for serial communications, we need to add a simple resistor voltage divider to drop the printer’s 5V signal Tx signal down before it reaches the Huzzah board.
  • Obtain a 3.3K resistor and a 2.2K resistor. Connect them together in series.
  • Connect the free end of the 2.2K resistor to GND on the Huzzah board.
  • Connect the free end of the 3.3K resistor to the Tx out wire of the thermal printer.
  • Connect the junction where the two resistors connect together to DIO4 on the Huzzah board. The Arduino sketch provided uses this pin as the serial input pin to the Huzzah.
  • Connect the Rx in wire of the thermal printer to DIO5 on the huzzah board. Even though the printer theoretically works with 5V levels, it will work OK with only 3.3V serial data signals coming into it. As an input to the printer, this connection will not output 5V and so does not require the resistor divider to protect the Huzzah board.
  • Connect the printer power to a 5V-9V supply capable of supplying enough current to operate the printer. The 5V USB power passthrough available on one of the Huzzah pins will not work as most USB ports won’t supply enough current.

Software

Arduino IDE

Install Arduino IDE

  • If you don’t already have the Arduino IDE installed, download the latest version from

Add 8266 Platform Support

  • Install the ESP8266 platform support into the Arduino IDE by following the instructions at . The following couple steps illustrate the process:
  • In the Arduino IDE File menu, select Preferences. In the resulting dialog, enter in the “Additional Boards Manager URL’s” field.

  • Follow the “Installing With Boards Manager” instructions at to add the ESP8266 platform to the Arduino IDE.

Install JSON Message Parsing Library

  • Install the ArduinoJSON library: Open the Library Manager by selecting “Under Sketch->Include Library->Manage Libraries” in the Arduino IDE menus. In the Library Manager, type “ArduinoJSON” in the search box, click the appropriate entry, and click “Install”.

Install Thermal Printer Library

  • Install the Adafruit_Thermal (printer) library: Open the Library Manager by selecting “Under Sketch->Include Library->Manage Libraries” in the Arduino IDE menus. In the Library Manager, type “Adafruit Thermal” in the search box, click the appropriate entry, and click “Install”.

Thermal Printer Library Modifications

  • The Adafruit_Thermal library requires a small modification to work properly with the Huzzah ESP8266 board (and probably other ESP8266 boards). The library implements a delay function used to delay by specific amounts of time while communicating with the printer. This delay function uses a “busy wait” which just sits and wastes processor time for the specified amount of time before exiting. This works fine on most Arduino compatible boards but the ESP8266 platform is a more complex system on a chip which has some additional things going on behind the scenes. Sitting in a “busy wait” loop for too long will prevent some of that background work from happening and the ESP8266 chip will reset itself by way of a watchdog timer. A small modification to the delay function will allow the background work to continue and prevent the reset.
  • Locate the Adafruit_Thermal.cpp file at (on Windows) My Documents\Arduino\Libraries\Adafruit_Thermal. Open the file in your favorite text editor. Locate the function Adafruit_Thermal::timeoutWait()
  • Add a yield() function call in two places as shown here. Be sure to get the spelling exactly correct and add the curly braces and semicolons in the proper places.

Serial Port Drivers

  • The Huzzah ESP8266 board uses a SiLabs CP2104 USB to serial interface chip that does not have built-in support in most operating systems. Install the appropriate drivers for your computer as per the instructions at

Update Sketch With Your Information

  • Open the Thermal_Printer_IoT.ino sketch in the Arduino IDE
  • Enter your own WiFi connection SSID and password and your Adafruit IO username, access key, and feed name as values for the corresponding variables. Remember your Adafruit IO access key can be obtained from the Adafruit IO web page as described earlier in this document.
  • Change the DEBUG_LEVEL value to 0, 1, or 2 as desired. Level 0 results in no output to the serial monitor. Level 1 outputs basic debug information showing the high level steps being performed by the program. Level 2 outputs comprehensive debug information including the entire contents of the HTTP request and response sent and received from Adafruit IO.

Program the Huzzah ESP8266 Board

  • Connect a USB cable from your computer to the Huzzah ESP8266 board.
  • Click the compile+upload button (the circle with right-facing arrow) just under the menu bar of the Arduino IDE. The program should compile without errors (it may take a minute or so depending on the speed of your computer) and then download to the Huzzah board.
  • As the programming process is in progress, open the Serial Monitor from the Tools menu. Ensure it is set to 115200 baud.
  • When the programming process completes, the Huzzah board will begin running the program and if you have enabled any level of debug messages, you should start seeing some output in the Serial Monitor window.

Final Tests

  • Ensure you have the thermal printer connected properly and it is loaded with paper.
  • Ensure the Arduino IDE Serial Monitor is showing that the Huzzah board is running the sketch properly. DEBUG_LEVEL = 2 is preferred for initial testing so you can see exactly what is going on.
  • Trigger your IFTTT Applet however necessary, depending on what you’ve chosen as a trigger. For the email example configured earlier in this document, you would email from the email address you used to create your IFTTT account.
  • After a short time (probably somewhat dependent on trigger source) you should see the Arduino Serial Monitor indicate that a message was pulled from Adafruit IO. At the same time the thermal printer should print the content of that message.
  • You can also use the Adafruit IO dashboard to monitor your feed to verify that messages are reaching the Adafruit IO service. If you do not see anything arriving there, you will need to check that your IFTTT applet and trigger source are properly configured.