SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By DocWu
#194534
I've Googled my fingers off, but I can't find what I need. I would like some generic and configurable libraries for the ESP8266 module used in the default AT-command mode.

All I find are things pertaining to using the ESP8266 as a stand-alone processor and how to program it.

I have a library from Sparkfun (SparkfunESP8266WiFi.h) and it works so long as you don't stray from the basic examples. It is really made for the shield and while I have that, I can't use it that way.

I had to move up to a Mega2560 from a UNO. It worked well on the UNO, but the pins used for software serial on the UNO won't work that way on the Mega. I breadboarded it and connected the TX/RX to pins 10 and 11 on the Mega which will function as a soft serial port, but the ESP8266 library doesn't seem to have a way to change where it is expecting to find them.

I edited the .h file and changed the pin numbers and that works, but I don't want to keep needing to edit the library if I use the shield on a UNO again.
I tried making a copy and renaming it, but that didn't work at all.

What I would really like is a library for the ESP8266 that allows the input to be configured. Allowing a hardware serial (i.e. Serial1) would be a bonus. It would make it compatible with any version of Arduino board.

In lieu of that, I'd settle for any tips on how to modify the library I have to do that.
User avatar
By exeng
#194543
I use this lib https://github.com/itead/ITEADLIB_Arduino_WeeESP8266 when connecting the Mega to an ESP8266 module https://www.itead.cc/wiki/ESP8266_Serial_WIFI_Module. I did add a few mods to the lib allow for baud rate changes, connect and print methods
to the .cpp file:
Code: Select all
//SJC ADDED
bool ESP8266::sATCIOBAUD(uint32_t baud, uint8_t databits, uint8_t stopbits, uint8_t parity, uint8_t flowctrl)
{
    Serial.print("IN BAUD");
    rx_empty();
    m_puart->print("AT+CIOBAUD=");
    m_puart->print(String(baud));
    m_puart->print(",");
    m_puart->print(String(databits));
    m_puart->print(",");
    m_puart->print(String(stopbits));
    m_puart->print(",");
    m_puart->print(String(parity));
    m_puart->print(",");
    m_puart->println(String(flowctrl));

    Serial.println(" OUT BAUD");

    return recvFind("OK");
}

// Client methods to support ThingSpeak lib
bool ESP8266::connect(String addr, uint32_t port)
{
    return createTCP(addr, port);
}


bool ESP8266::print(const uint8_t *buffer) 
{
    return sATCIPSENDSingle(buffer, strlen(buffer));
}
and in the .h file
Code: Select all
//SJC ADDED
// Client methods to support ThingSpeak lib
bool connect(String addr, uint32_t port);
bool print(const uint8_t *buffer); 

//SJC ADDED
bool sATCIOBAUD(uint32_t baud, uint8_t databits, uint8_t stopbits, uint8_t parity, uint8_t flowctrl);
Note that the ESP8266 module is a 3.3V device. So power and I/F to the Mega must be handled accordingly. I use Serial1 for comm to the ESP8266 module. I also made an adapter board for the ESP8266 to bring out the connections and provide a reset button and drop the TX line from the Mega to 3.3V. The ESP8266 is powered by a separate 3.3v supply.
By DocWu
#194552
Thank you. I will look at that and see if it will do what I want. If you have used it on a Mega on Serial1, it will probably work for me.

I'm currently hacking a ESP8266 shield to use with the different pinouts. It has the power supply and buffers already, but I also have a bare module I might use. I know I will need to provide 3.3v power and level shifting.

Thanks again...