I followed this exact tutorial, but I keep getting the "Failed to connect to ESP8266: Timed out waiting for packet header" error. Also, even before I uploaded or entered the code in IDE, the LED light turned on and doesn't respond at all to the push button when the usb cord is connected. It's just always on. Could it be a hardware issue?
Below is what my wiring looks like (unplugged, obviously). If it matters, I'm using a macbook.
ALSO, I'm VERY new to arduino and circuit/electronic building, so please explain your answers very simply. I just started learning in school.
I don't really want to listen to someone's freaky voice for a few minutes to see if the tutorial is correct.
Please just explain in your own words what you have done.
Did you set up the boards correctly using the boards manager, and have you selected the proper board ?
Have you selected the proper 'COM' port ?
did you hold down the 'flash' button on the board while you reset it to put it into flash-mode ?
Please post the code you are trying to upload within </> code-tags.
Please post a circuit diagram of the connections you make (not a photo and please not fritzing) a hand-draw diagram will do just fine, but i usually use paint (the XP version is actually the best)
I want the LED to light up when the push button is pressed and connect the circuit to the WIFI, essentially.
Did you set up the boards correctly using the boards manager, and have you selected the proper board ? I don't know how to check that, or what even the right boards.
Have you selected the proper 'COM' port ? I'm sorry; I don't know what that means either.
did you hold down the 'flash' button on the board while you reset it to put it into flash-mode ? How do I do that? What's/where's the flash button?
```
#include "config.h"
/************************ Example Starts Here *******************************/
// digital pin 5
#define BUTTON_PIN 5
#define LED_PIN 16
// button state
bool current = false;
bool last = false;
// set up the 'digital' feed
AdafruitIO_Feed *myFeed = io.feed("project-1");
void setup() {
// set button pin as an input
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
// grab the current state of the button.
// we have to flip the logic because we are
// using a pullup resistor.
if(digitalRead(BUTTON_PIN) == LOW){
current = true;
digitalWrite(LED_PIN, LOW);
}else{
current = false;
digitalWrite(LED_PIN, HIGH);
}
// return if the value hasn't changed
if(current == last)
return;
// save the current state to the 'digital' feed on adafruit io
Serial.print("sending button -> ");
Serial.println(current);
myFeed->save(current);
// store last button state
last = current;
}
```
config.h CODE (modified password/credentials for privacy)
```
#define IO_USERNAME "XXX"
#define IO_KEY "aio_XXXXXXXXXXXpSLBaBq"
/******************************* WIFI **************************************/
#define WIFI_SSID "XXX16X"
#define WIFI_PASS "DXXXXE6"
// uncomment the following line if you are using airlift
// #define USE_AIRLIFT
// uncomment the following line if you are using winc1500
// #define USE_WINC1500
// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
defined(ADAFRUIT_PYPORTAL)
// Configure the pins used for the ESP32 connection
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
// Don't change the names of these #define's! they match the variant ones
#define SPIWIFI SPI
#define SPIWIFI_SS 10 // Chip select pin
#define NINA_ACK 9 // a.k.a BUSY or READY pin
#define NINA_RESETN 6 // Reset pin
#define NINA_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/
// the AdafruitIO_FONA client will work with the following boards:
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
/**************************** ETHERNET ************************************/
// the AdafruitIO_Ethernet client will work with the following boards:
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
```
I don't know how to check that, or what even the right boards.
Ok let's start there. We can't tell if there are any issues with the code since you haven't successfully uploaded it yet. (though it does compile, so that is a good thing) Check This tutorial And find instead of 'generic ESP8266' the Huzzah board you think you have (is that a picture of your board ?)
Under Tools->port : you should find a COM port that you can select. If there are multiple options you can try them 1 at a time.
How do I do that? What's/where's the flash button?
If you have an 'adafruit Huzzah feather' there is no need for the flash-mode button it is automatic.
I selected the correct Huzzah Board (also, no it's not a picture of my board, but I have the same exact parts and wiring. The tutorial is made for my class).
I don't see some or the same configuration options in the tutorial you sent. The pic below is what I have under "tools." As you can see, I don't have a COM port.
Oh so you don't have it connected via USB ? hmm well i don't think you should need to try the first 2, i would go for the 3rd option in this menu which has a MAC address. I am not sure OTA uploads work on a Huzzah right out of the box though.
It is connected via USB. By third, did you mean /dev/cu.usbserial? I tried that -- no more error, but it says this below. Also, the LED light turned off, but it still doesn't respond to the button. What's an OTA upload?
Ok great it has at least uploaded. OTA stands for Over The Air. Ok now let's look at the sketch.
It assumes that there is an LED connected to
#define LED_PIN 16
GPIO pin 16, via a current limiting resistor to GND.
and a button #define BUTTON_PIN 5to GPIO 5, with a pullup resistor to 3.3v Have you got that ?
The sketch outputs debugging data via the Serial monitor, can you open the Serial monitor in the IDE and set the BAUD rate to the same as the sketch (right bottom corner) 115200 and press the reset button on the huzzah.
What shows up in the Serial monitor ?
The sketch is rather more complicated than required, due to the logging of data to 'AdafruitIO_Feed'
stripped down it comes down to
#define BUTTON_PIN 5
#define LED_PIN 16
void setup() {
// set button pin as an input
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
/*// start the serial connection
Serial.begin(115200);
while(! Serial); // this may actually be holding up the program
Serial.println();
Serial.println("Program started");*/ // this section is just for the Serial monitor
}
void loop() {
if(digitalRead(BUTTON_PIN) == LOW){
digitalWrite(LED_PIN, LOW);
}
else {
digitalWrite(LED_PIN, HIGH);
}
}
Try uploading this stripped down version and see if the button & LED work.
And what happens shows up when you press the button ? and let go of it again ? Because now it shows that the button is pressed (1 means 'true' )
if(digitalRead(BUTTON_PIN) == LOW){
current = true;
digitalWrite(LED_PIN, LOW);
That should light up the LED if it is connected correctly btw. Is it possible you have the LED the wrong way around ? (the longer pin needs to be at the huzzah, then the resistor to the shorter pin, and that connected to GND. )
And is the pullup resistor connected properly ?
Well the code i posted doesn't have any Serial debugging, so when you upload that we should not expect any response in the Serial monitor.
From the lower picture, i can see that the pullup resistor (the one which should connect the 3.3v+ and the huzzah side of the button) Is not connected to anything. Both legs should probably move 1 hole to the left.
The microswitch has 4 legs, that is actually 2 pairs. As far as i can see the pins on the left and the pins on the right are connected. The connected pins form an arch together if you look at them from the side. And both arches connect when you press.
Let's focus on the switch first. Upload the sketch from the tutorial again after you corrected the position of the resistor. It is strange that it is also wrong in the first picture you posted, which you said was from the tutorial.
Then again open the Serial monitor and press the button and release.