Taming the ESP8266 with Arduino IDE

mrburnette
Thu Jul 02, 2015 1:36 pm
I posted about my success with the ESP8266-01 viewtopic.php?f=45&t=385&p=3546#p3546
using this core:
https://github.com/sandeepmistry/esp8266-Arduino

I have also used the parent to that distribution with the Board Manager in the 1.6.5r2 from Arduino.cc

Available:
I’m publishing my efforts on my project blog: http://www.hackster.io/rayburne/esp8266 … rduino-ide

Previous attempts to use “AT” commands and a separate Arduino to parse is a P-I-T-A. Big capitals… BIG pain.
Users using LUA have reported SRAM leaks and issues… I did not even go there as there are too many gyrations to jump through.

However, the Arduino flavor core seems to manage the ESP8266 well. Using a clean, stable power supply is key. Other things to note:

Do NOT take GPIO0 directly to Gnd to activate program mode! Rather,
power-off,
pull-down GPIO0 using a 330 Ohm resistor,
power-on,
program*,
power-off,
remove the GPIO0 from the pull-down and connect as sketch requires (or leave floating.)
The 330 Ohm resistor will prevent any damage to the uC should the pin be driven accidently to a HIGH state.

* ONLY use a 3.3V serial-USB module. Never use a 5V serial converter.

Use a quality electrolytic as close to the ESP8266 board as practical… I’m using 100uF

Do use 1.8K Ohm resistors to 3.3V as I2C pull-ups

The code is not complete, but the attached ZIP contains the Arduino sketch to:

  • Init the OLED on I2C**
    Scan the local WiFi area
    Match SSID to “home” SSID
    If home SSID found,
    Connect,
    Attempt login
    DHCP
    Display IP address

** Note:
My OLED states 0x78 on the back side of the display. In AVR it tests at 0x78. For the ESP8266, it only works at default address 0x3C
You have been warned.
Unzip the archive into a single directory… the project is a multi-tab sketch.
The includes are part of the ESP8266 core files:

  • #include “ESP8266WiFi.h”
    #include <Wire.h>

See Credits_Notes.h for OLED connections to the ESP8266 module.

Ray


zoomx
Thu Jul 02, 2015 1:57 pm
My OLEd too has written the 0x78 but with a search for I2C address on a UNO I found 0x3C. Never tested with other libraries or MCU.

martinayotte
Thu Jul 02, 2015 3:04 pm
0x78 = (0x3C << 1) ;)
So, maybe Chinese people been confused by I2C addressing … :lol:

mrburnette
Thu Jul 02, 2015 3:19 pm
zoomx wrote:My OLEd too has written the 0x78 but with a search for I2C address on a UNO I found 0x3C. Never tested with other libraries or MCU.

martinayotte
Thu Jul 02, 2015 5:18 pm
Crazy, but I tested with the Arduino Nano (clone) and 0x78 works!

In such case, there is maybe a discrepancy between Maple Wire and Arduino Wire librairies, the shifting by 1 in addressing is to leave place for the R/W bit.
We should narrow it down, otherwise, people will always faced that with any I2C devices.


RogerClark
Thu Jul 02, 2015 10:26 pm
Martin

The I2C code is bit banged, and is relatively easy to read ( the code), but i nave next to zero knowledge on I2C, so perhaps someone with more I2C knowledge could take a look ?


mrburnette
Thu Jul 02, 2015 10:39 pm
[quote=”martinayotte”
In such case, there is maybe a discrepancy between Maple Wire and Arduino Wire librairies, the shifting by 1 in addressing is to leave place for the R/W bit.
We should narrow it down, otherwise, people will always faced that with any I2C devices.[/quote]

Just a reminder, I am discussing the ESP8266 uC, not the STM32F1xx. Likely there is a discrepancy with the Wire library for the ‘8266. My bet is that the Nano is working correctly as it corresponds to the manufacturer’s silkscreen.

Ray


martinayotte
Fri Jul 03, 2015 2:16 am
Personally, I don’t have any I2C addressing issues on STM32.

So, it is maybe related the OLED lib mentioned above.

The I2C address is 7bits, it is shifted by 1 and added (ORed) with R/W state. Some libraries take that in account, some others don’t … :(

So, the bug is somewhere in this discrepancy …


zoomx
Fri Jul 03, 2015 2:12 pm
I started with Adafruit_SSD1306, used 0x78 address and got no result. So I used the sketch for discovering I2C addresses, the one published in the Arduino Playground, and found 0x3C. Using 0x3C with Adafruit library worked for me.
U8glib works too without defining any address.

martinayotte
Fri Jul 03, 2015 4:29 pm
Hi Ray,
Just a reminder, I am discussing the ESP8266 uC, not the STM32F1xx
I’ve looked at my ESP8266 Sketch_Buffet, and I don’t see any discrepancy there either. The MCP23017 is really at 0x20 (not shifted to 0x40) and the 24C64 EEPROM is at 0x50 (not shifted to 0xA0). So, the discrepancy must be really into that specific library.

mrburnette
Fri Jul 03, 2015 4:37 pm
From the github pages: https://github.com/esp8266/Arduino

Libraries that don’t rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work:

arduinoWebSockets – WebSocket Server and Client compatible with esp8266 (RFC6455)
aREST REST API handler library.
Blynk – easy IoT framework for Makers (check out the Kickstarter page).
DallasTemperature
DHT11 – Download latest v1.1.0 library and no changes are necessary. Older versions should initialize DHT as follows: DHT dht(DHTPIN, DHTTYPE, 15);
NeoPixelBus – Arduino NeoPixel library compatible with esp8266.
PubSubClient MQTT library by @Imroy.
RTC – Arduino Library for Ds1307 & Ds3231 compatible with esp8266.
Souliss, Smart Home – Framework for Smart Home based on Arduino, Android and openHAB.

Of course, the appropriate break-out board must be used to secure access to the necessary uC pins!
Image

In addition to the below common modules, Adafruit is now in the game with Huzzah.
Image
Ray


Leave a Reply

Your email address will not be published. Required fields are marked *