ESP8266 on Arduino Nano

Trying to get Arduino Nano to work with ESP8266 (ESP-01). The Nano won’t power the ESP8266 from it’s onboard 3.3V power like the Uno does. The red power light and blue comm light on the ESP board blink for a split second, then it goes dark. Many sources say you need a dedicated power supply or you risk damaging both the Arduino and ESP boards. These boards are cheap, so I’m trying everything. Even more sources say to be careful not to connect 5V to the ESP board. Well, this is what I’m doing. It is working so far, but I noticed the ESP board is pretty hot to the touch. It has been running my test program, which makes repeated HTTP requests as fast as the board can execute them, for about 30 minutes. In other words, it is taxing the ESP board pretty hard. That said, I’ve seen zero errors. While this is probably bad for the board, 5V could work for some applications. At least this way there are fewer components. I guess I’ll leave it running a while and see if it gets fried.

IMG_7100[1]

Connections:
ESP8266 <--> Nano
GND <--> GND
VCC <--> 5V
CH_PD <--> 5V
RX <--> D10
TX <--> D11

Using SoftwareSerial on pins 10/11.

/* SETUP WIFI - ESP8266 (ESP-01)

http://www.ebay.com/itm/221589414331?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

http://www.ebay.com/usr/worldchips?_trksid=p2047675.l2559

1
#include
SoftwareSerial softSerial(10, 11); // RX, TX
String WSSID = "xxxxxxxxxxxx";
String WPASS = "xxxxxxxxxxxx";
bool r;

void setup() {
/* SETUP SERIAL COMMUNICATION */
espSerialSetup();
delay(2000); // Without this delay, sometimes, the program will not start until Serial Monitor is connected
r = espSendCommand( "AT+CIFSR" , "OK" , 5000 );
if( !r ) {
r = espSendCommand( "AT+CWMODE=1" , "OK" , 5000 );
r = espSendCommand( "AT+CWJAP=\""+WSSID+"\",\""+WPASS+"\"" , "OK" , 15000 );
}
}

void loop(){

r = espSendCommand( "AT+CIPSTART=\"TCP\",\"108.59.11.102\",80" , "OK" , 5000 );
String getRequest = "GET /shiznic/ HTTP/1.1\r\nHost: www.rootpower.com\r\n";
int getRequestLength = getRequest.length() + 2; // add 2 because \r\n will be appended by SoftwareSerial.println().
r = espSendCommand( "AT+CIPSEND=" + String(getRequestLength) , "OK" , 5000 );
r = espSendCommand( getRequest , "+IPD" , 15000 );
//r = espSendCommand( getRequest , "world" , 15000 ); // page should respond with Hello, world.
if( !r ) {
Serial.println( "Something wrong...Attempting reset...");
espSendCommand( "AT+RST" , "ready" , 20000);
espSendCommand( "AT+CWMODE=1" , "OK" , 5000 );
espSendCommand( "AT+CWJAP=\""+WSSID+"\",\""+WPASS+"\"" , "OK" , 15000 );
}

delay(3000);

}

void espSerialSetup() {

// change baud rate so SoftwareSerial works better -- need a certain version of ESP for this to work and be retained after power cycle
// make sure Serial Monitor port speed is set to 9600
softSerial.begin(115200); // default baud rate for ESP8266
delay(1000);
softSerial.println("AT+CIOBAUD=9600");
delay(1000);
softSerial.begin(9600);
Serial.begin(9600);

}

bool espSendCommand(String cmd, String goodResponse, unsigned long timeout) {
Serial.println("espSendCommand( " + cmd + " , " + goodResponse + " , " + String(timeout) + " )" );
softSerial.println(cmd);
unsigned long tnow = millis();
unsigned long tstart = millis();
unsigned long execTime = 0;
String response = "";
char c;
while( true ) {
if( tnow > tstart + timeout ) {
Serial.println("espSendCommand: FAILED - Timeout exceeded " + String(timeout) + " seconds" );
if( response.length() > 0 ) {
Serial.println("espSendCommand: RESPONSE:");
Serial.println( response );
} else {
Serial.println("espSendCommand: NO RESPONSE");
}
return false;
}
c = softSerial.read();
if( c >= 0 ) {
response += String(c);
if( response.indexOf(goodResponse) >= 0 ) {

execTime = ( millis() - tstart );
Serial.println("espSendCommand: SUCCESS - Response time: " + String(execTime) + "ms");
Serial.println("espSendCommand: RESPONSE:");
Serial.println(response);
while(softSerial.available() > 0) {
Serial.write(softSerial.read());
}
return true;
}
}
tnow = millis();
}
}

ESP8266 ESP-12 Getting Started w/ Arduino Uno

Had trouble finding a complete guide to get my new ESP8266 / ESP-12 going. Lots of information out there but much conflicting info and most guides are missing something.

Here’s what worked for me with this particular ESP-12 board.

http://www.ebay.com/itm/281601716541?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

If the Ebay listing is dead, the seller name is tomyuen007.

Plugged in the Arduino and uploaded the BareMinimum sample sketch.

On the ESP12 board, connect GPIO15 to GND. Then connect GPIO0, GPIO2, and CH_PD to VCC.

I used a two tiny breadboards because of the awkward spacing of the pins on the board.

ESP12_arduino-2

Connected ESP TX to Arduino TX.
Connected ESP RX to Arduino RX.

Opened Arduino Serial Monitor and set line ending to “Both NL & CR” and set baud to 115200.

Connected ESP12 GND to Arduino GND
Connected ESP12 VCC to Arduino 3.3V (Many sources say you need a dedicated power supply, but I didn’t have one and this is working so far.)

The ESP12 booted up immediately and I got a “ready” message, preceded by some gibberish.

arudino_esp12

I tried every baud rate and only 115200 gave me the ready message. All other settings gave me only gibberish.

More to come…

AT+GMR
AT version:0.21.0.0
SDK version:0.9.5
OK

Was going to check Wi-Fi settings on my phone and use them to configure the ESP when I noticed it was set up as an access point by default with SSID: AP-THINKER_FE2B43

Connected with Windows and checked IP address: 192.168.4.3 with gateway 192.168.4.1

Tried HTTP browser connection to 192.168.4.1 but connection refused.

AT Commmands to get going…

AT+CWMODE=1 – This changed the mode from AP to Sta
OK

AT+CWLAP – Lists access points. Before setting CWMODE, this would return error
+CWLAP:(3,”cowabunga”,-68,”f8:35:dd:75:12:1b”,1)
+CWLAP:(0,”cowabunga_guest”,-69,”fa:35:dd:75:12:1c”,1)
+CWLAP:(2,”hauntedpants”,-92,”00:18:e7:e7:1d:2c”,2)
OK

AT+CWJAP=”cowabunga_guest”,””
OK

AT+CWJAP?
+CWJAP:”cowabunga_guest”
OK

AT+CIFSR=?
OK

AT+CIFSR
+CIFSR:STAIP,”192.168.1.43″
+CIFSR:STAMAC,”18:fe:34:fe:2b:43″
OK

AT+CIPSTART=”TCP”,”rootpower.com”,80
CONNECT
OK

Activity Logging

Setting up a system to prompt for a record of my activity each hour. This PHP scrip cron job will send an email to me each hour during my normal waking hours. My iPhone has push notifications enabled for email so the phone will buzz each time it needs an update and I will simply reply to the email. This way to don’t have to actively remember to record the information. After some, I’ll be able to analyze the data and see what it reveals. This is a pretty crude system, but the key thing for me is having the system actively prompt for the data in a way that makes it easy to respond. Another thought on tuning the system. I wear a Garmin Vivofit to track physical activity and sleep. If the Vivofit would actively report when “sleep” mode has initiated, an API call to Garmin Connect could be used to determine whether or not to send the activity prompt.

The email forwards to a Gmail account and the messages were initially going into SPAM.

activity_logging_cron_job

35 18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9 * * * /usr/local/bin/php /home/hunter92/activity_log_record_request.php

PHP script for cron job