Pro Trinket 3V, ESP8266 Problem
Posted: Mon Dec 07, 2015 10:37 pm
Hello everyone! I have a Pro Trinket 3V hooked up to a ESP8266 but am having trouble getting anything to work on the wifi side of things. Here's how I have the two connected:
(Trinket -> ESP8266)
3V -> 3V and CHPD
GND -> GND
RX -> TX
TX -> RX
And my code. I'm using blinks to tell me success or fail. I get 3 blinks that tell me Trinket starts up, 5 blinks when resetModule() runs successfully, and 6 blinks when connectWiFi() supposedly runs successfully. However, when I run my connectService() function I get fast 7 blinks meaning failed. Here's the code:
My hunch is that I'm not actually connected to wifi since I can't see the device connected to my network via my router's web tool. I also couldn't see the ESP8266 wifi network I setup when testing it out as an access point. I tried 9600 baud but then can't get past the resetModule() function.
Thanks so much everyone!
~ Kevin
(Trinket -> ESP8266)
3V -> 3V and CHPD
GND -> GND
RX -> TX
TX -> RX
And my code. I'm using blinks to tell me success or fail. I get 3 blinks that tell me Trinket starts up, 5 blinks when resetModule() runs successfully, and 6 blinks when connectWiFi() supposedly runs successfully. However, when I run my connectService() function I get fast 7 blinks meaning failed. Here's the code:
Code: Select all
#define SSID "..." // your wifi ssid here
#define PASS "..." // your wifi wep key here
void setup() {
pinMode( 3, OUTPUT );
pinMode( 13, OUTPUT );
blinker( 3, 250 ); // blink led13 to indicate power up
digitalWrite( 3, HIGH );
Serial.begin( 115200 ); // 115200 max
Serial.setTimeout( 5000 );
delay( 250 );
// Attempt to reset the module
while( !resetModule() );
// Connect to Wifi.
while( !connectWiFi() );
}
void loop() {
// function to check server for data
connectService( "google.com", 80 );
delay( 10000 );
}
boolean resetModule() {
// test if the wifi module is ready
Serial.println("AT+RST");
while( !Serial.available() ) {}
if( Serial.find("ready") ) {
blinker( 5, 250 );
delay( 1000 );
return true;
} else {
blinker( 5, 100 );
digitalWrite( 3, LOW );
delay( 500 );
digitalWrite( 3, HIGH );
delay( 500 );
return false;
}
}
boolean connectWiFi() {
Serial.println( "AT+CWMODE=1" );
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
Serial.println(cmd);
while( !Serial.available() ) {}
if( Serial.find("OK") ) {
blinker( 6, 250 );
delay( 2500 );
// set the single connection mode
Serial.println( "AT+CIPMUX=0" );
while( !Serial.available() ) {}
if( Serial.find( "OK" ) ) {
return true;
} else {
return false;
}
} else {
blinker( 6, 100 );
delay( 1000 );
return false;
}
}
boolean connectService( String service, int port ) {
String serviceConnect = "AT+CIPSTART=\"TCP\",\"" + service + "\"," + port;
Serial.println( serviceConnect );
while( !Serial.available() ) {}
delay(300);
if( Serial.find( "Linked" ) ) {
blinker( 7, 250 );
return true;
} else {
blinker( 7, 100 );
delay( 1000 );
return false;
}
}
void blinker( int repeat, int speed ) {
for( int i=0; i<repeat; i++ ) {
digitalWrite( 13, HIGH );
delay( 100 );
digitalWrite( 13, LOW );
delay( speed );
}
}
My hunch is that I'm not actually connected to wifi since I can't see the device connected to my network via my router's web tool. I also couldn't see the ESP8266 wifi network I setup when testing it out as an access point. I tried 9600 baud but then can't get past the resetModule() function.
Thanks so much everyone!
~ Kevin