After completing my Arduino clock build, I became curious about using the WIFI module option in place of the DS3231 RTC board. I have never used an ESP8266 before, but did a bit investigating and decided to purchase this model, an ESP-12E NodeMCU clone. From what I have read, all of the boards use the same ESP8266 chip, with differences in the IO lines that are broken out, integrated USB<>serial interface for programming and 5>3.3 volt regulator options, as well as memory variations. This module has a built-in 3.3 voltage regulator and USB port for easy Arduino programming, plus loads of IO lines broken out for experimentation. It is probably overkill for this application, but still quite cheap.
I also bough a few inexpensive logic level shifter boards that each have 4 bidirectional channels. I believe the bidirectional feature is needed for I2C, unlike the SPI interface, where I have used simple diode/pullup level conversion in the past.
Looking through the latest 1.04 code for the ESP8266, I think this module will work with a few simple changes:
- This module has its LED at pin 2 instead of pin 0, so I think I would need to change "#define blueLedPin 1" to "#define blueLedPin 2".
- I believe almost any pins can be defined as the I2C SDA and SCL pins, as they are bit-banged. The current code has "Wire.begin(0, 2); // SDA = 0, SCL = 2", which I think sets up the I2C pins. Because of the change in the builtin LED pin, I believe I would need to change the SCL pin to another, perhaps " "Wire.begin(0, 1); // SDA = 0, SCL = 1"?
- The board definitions in the Arduino for this board allow setting up the flash size and split at "4M (3M SPIFFS)" or "4M (1M SPIFFS)". Should either work?
- I can also set the clock speed, which I see in the code comments should be 80MHz.
- I can also set the upload speed to "115200".
- There are some other options in the code comments that I can't set in the board definitions: "Generic ESP8266 Module, 80MHz, 80MHz, DIO, 115200, 1M (64k SPIFFS), ck, Disabled, none". Can I safely ignore these?
I think I will need pullup resistors on the SCL/SDA lines, as the ESP8266 and the Atmega do not have them. I think they are installed on the DS3231 module.
Other than these adjustments, I think the module should work fine. Suggestions?
9 months 3 days ago - 9 months 3 days ago#7866by Froula
I am answering my own question, but I wanted to report back that the ESP8266 ESP-12E NodeMCU module I referenced works fine with a few minor code modifications.
The board has silk-screened pin designations on the top which appear to be Arduino D0, D1, D2, etc. pin designations, but they are NOT. The latest Arduino IDE board files (available from GiHub) use the GPIO numbers rather than these NodeMCU numbers to map to Arduino pins. These GPIO numbers are silkscreened on the bottom of the board. The blue LED on this module is at GPIO02, which is marked as NodeMCU "D4" on the top of the board. Could it be any more confusing????!!!
I chose GPIO4 and GPIO5 for the SDA/SCL I2C pins as they seemed the most "in the clear" non-dual-purpose pins available on the module. These are marked on the top of the board as NodeMCU pins "D2" and "D1".
The specific code changes in WifiTimeProviderESP8266.ino, version 1.0.4 needed to use the module are:
- Line 33: #define blueLedPin 2
- Line 140: Wire.begin(4, 5); // SDA = 4, SCL = 5
Use the latest ESP8266 board definitions from:
Be sure to run the latest Arduino IDE before installing the board defs, per instructions.
Select "NodeMCU 1.0 (ESP-12E Module)" from the Tools menu in the IDE.
Select Flash Size: "4M (1M SPIFFS)"
Select CPU Frequency: "80 MHz"
Select Upload Speed: "115200"
Be sure to install the correct driver package for the USB/Serial chip on the board. I used the drivers in the CP210x_Windows_Drivers.zip file I downloaded on the Web. Install the drivers prior to plugging in the WIFI board.
Plug in the board and determine virtual serial port assigned to the ESP8266 NodeMCU board. Compile and upload the sketch as if using a normal Arduino board. I did not need to use either the flash or reset buttons on the module, The code simply uploaded.
After uploading the code, the blue LED on the module should flash rapidly. Disconnect the module from the USB port of the PC.
Wire the module to the clock through a bidirectional interface board. The one I mentioned earlier works great and is inexpensive.
- Connect the +5volts from the clock module to both "HV" on the converter and "Vin" (3.3 regulator input) on the ESP-12E module.
- Connect Gnd from the clock module to "Gnd" on the high side of the converter and also to one of the "Gnd" pins on the ESP-12E.
- Connect "Gnd" on the low side of the converter to another "Gnd" pin on the ESP-12E.
- Connect "LV" on the converter to "3.3v" on the ESP-12E.
- Connect "GPIO4" ("D2") on the ESP-12E to "LV1" on the converter.
- Connect "GPIO5" ("D1") on the ESP-12E to "LV2" on the converter.
- Connect "HV1" on the converter to "SDA" on the clock board.
- Connect "HV2" on the converter to "SCL" on the clock board.
I found NO I2C SCL/SDA pullups required on the HV or LV side of the converter as they are built into the board!
Whew. That's it.
Power-up the clock. The blue LED on the ESP-12E should flash rapidly, indicating the module is in "Infrastructure" mode and ready to be programmed with your WIFI network info.
It sounds complicated, but after thinking through the connections and code changes, it worked the first time for me! I was a bit disappointed that the ESP-12E code did not use regular NTP protocol to retrieve time from the web, but setting a small server in the house that references my Stratum 0 NTP server on the home LAN should be easy. Instructions for doing so are in the "WiFi Time Provider v1 for Arduino Nixie Clock" manual.
It is probably much simpler just to buy the pre-programmed board from Ian, if somewhat less exciting!
9 months 3 days ago - 9 months 3 days ago#7867by Froula
ESP8266 12E NodeMCU module on left, wired to tiny logic level converter board on right, with pullup resistors on the 5 volt I2C side. The module is nice as it has its own 5>3.3 volt regulator so it can be powered from 5 volts as well as supply the required 3.3 volts output for the converter board.
In addition, it has an integrated USB<>serial converter and a great set of board definition files for the Arduino IDE. It can be programmed with no additional hardware.
I found NO I2C SCL/SDA pullups required on the HV or LV side of the converter as they are built into the board as part of the conversion circuitry!
I had never heard of the ESP8266 before a few days ago, but like most things Arduino, some very talented people have made it drop-dead simple to work with. I am quite enthralled with that module, and glad I picked up an extra to play with!
The hard part was figuring out the whole pin-mapping thing, as the NodeMCU module is intended for another development environment.
Getting the entire clock on an ESP8266 would be a neat trick! It seems kind of IO limited, but with a shift-register or two.......
Don, have a look at the "new" ESP32 chip. It has tons more I/O than its predecessor the ESP8266. SparkFun has a dev board for it that's vaguely similar to an ESP-12. I have one, it works, haven't had time to do much with it beyond making it blink the onboard LED in response to incoming UDP packets.
There are not nearly as many boards available for the ESP32 as there are for the ESP8266 (yet?) and development system support is only slowly improving. There is limited support in the Arduino environment, if you are interested I'll dig up and post links to where I got the board definitions and whatnot.
Look into it later when the dust is clearing off the crater.
First let me make something clear: nothing in this post should be interpreted as any sort of endorsement of SparkFun electronics! I have no quarrel with their products but I do disapprove strongly of their CEO's political alignment and his tendency to blather on about it in public. I avoid giving the company any of my money but in the case of the ESP32 dev board I could find no viable alternative to the SparkFun board.(EDIT: no viable alternative at the time. I see Olimex and a few others now have dev boards for sale.)
I see that they still have not gotten Bluetooth support and analog output support worked out for Arduino, and that's a bit disappointing because it has been a long time since they said it's coming real soon. Considering that it's Espressif (maker of the ESP line of chips) that runs the repository I would have to assume the project is only delayed, not abandoned.
If you feel real adventurous, I believe the native SDK supports all the things that are presently missing from Arduino. I have not messed with it but from what I've heard the SDK is basically a bunch of C libraries and some rather sketchy translated documentation. It's here:
Going way off topic... I just wanted to mention that I'm enjoying the telecom videos on your YouTube channel. I'm fascinated with the subject but have little actual knowledge.
Look into it later when the dust is clearing off the crater.