Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Alex Glow
Published

Getting Started with the Feather HUZZAH

First steps with Adafruit's ESP8266-enabled wireless board. Ruin your Twitter and FB accounts in one easy project!

BeginnerProtip2 hours15,537
Getting Started with the Feather HUZZAH

Things used in this project

Story

Read more

Code

"Blink" example code

C/C++
Streamlined so that you can change the LED's pin number in just one place. 0 is the big red LED, on the main board; 2 is the little blue one on the ESP module.
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc
  (On the Feather, pin 0 is red, pin 2 is blue.)

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */

const int blinkMe = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 0 as an output.
  pinMode(blinkMe, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(blinkMe, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(blinkMe, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

IFTTT + Twitter code

C/C++
Sends the event "feather_a" to IFTTT.com, so you can trigger actions (such as posting a tweet). Add your own access key and WiFi details.
/*
 Simple HTTP get webclient test
 Modified from https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide#connecting-via-wifi
 */
 
#include <ESP8266WiFi.h>
 
const char* ssid     = "NETWORK";
const char* password = "NET-PASSWORD";
 
const char* host = "maker.ifttt.com";
 
void setup() {
  Serial.begin(115200);
  delay(100);
 
  // We start by connecting to a WiFi network
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
int value = 0;
 
void loop() {
  delay(300000);
  ++value;
 
  Serial.print("connecting to ");
  Serial.println(host);
  
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
  
  // We now create a URI for the request
  String url = "/trigger/feather_a/with/key/MYKEY";
  Serial.print("Requesting URL: ");
  Serial.println(url);
  
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  delay(500);
  
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  
  Serial.println();
  Serial.println("closing connection");
}

Credits

Alex Glow

Alex Glow

149 projects • 1593 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.
Thanks to Drew Alden.

Comments