$5 WiFi module

This forum is for posts that might be considered off-topic but that may be useful or interesting to members. Examples include posts about electronics or programming in general, other microcontrollers or interesting devices, useful websites, etc.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: ESP8266

Post by dkinzer »

twesthoff wrote:Pins 1-4 are self explanatory, how should I connect the other pins?
The others pins have the pullup/pulldown already so it should run fine with nothing connected. However, you will need to make some connections in order to download code. The simplest strategy is to use the "manual reset protocol". To do so, when you're ready to download ground GPIO0 and then momentarily ground RST. When the ESP boots up it sees that GPIO0 is grounded and it enters the "command mode". At that point, you can press F7 in the ZBasic IDE and it will begin the download. While the download is proceeding, remove the ground from GPIO0. The device should begin running that downloaded app when the download completes. If not, give it a reset.

It is probably more convenient to use one of the "automatic reset protocols" that will allow the IDE to get the ESP into download mode and then download. The one that I would suggest is the one called "DTR Only" (in the ZBasic for ESP8266 manual). The pullup resistors shown should already be on the device so all you need is a capacitor (100nF ceramic should work) and a diode (small signal silicon like the 1N914 or, better, a Schottky diode like the BAT42).

Looking at your pin list again, I believe that it is incorrect. The ESP-01 module that I have has the pinout shown in the image of the third post in this thread.
- Don Kinzer
twesthoff
Posts: 247
Joined: 17 March 2006, 6:45 AM
Location: Fredericksburg, VA

Post by twesthoff »

Don,
You were right on the pin information. Several were NOT correct. I copied and pasted them from the sellers website where they were wrong. I sent the seller a message about the error. Lucky for me I used the picture you mentioned when I wired up my board. It now works for me using the "AT" commands.

For some reason I missed the part in the ZBasic for ESP8266 manual that I was supposed to add the automatic reset circuits myself. I thought it said that some boards already had that circuitry on them and I didn't have a schematic for my board. I will add the circuit and try it.

Am I right in assuming that once I download a Zbasic program, the original code for the "AT" commands will be overwritten?
Tom W
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

twesthoff wrote:I thought it said that some boards already had that circuitry on them [...]
Some boards do but I've not seen an ESP-01 that does. One board that has an automatic reset circuit is the NodeMCU Amica development board. It is essentially an ESP-12e mounted on a board with other circuitry, e.g. USB interface, voltage regulator and reset circuitry.
twesthoff wrote:Am I right in assuming that once I download a Zbasic program, the original code for the "AT" commands will be overwritten?
Yes. The AT command interpreter is just another downloaded program. You can restore it by re-flashing it. You can use the esp_tool utility (part of the ZBasic install) or one of the other ESP Flash utilities to do that.
- Don Kinzer
twesthoff
Posts: 247
Joined: 17 March 2006, 6:45 AM
Location: Fredericksburg, VA

Post by twesthoff »

Don,
In the manual you wrote for the ESP8266 you mentioned that the Zbasic program will be essentially be a subroutine that will called every so often by the ESP8266 chip. As mentioned, that will require the programmer to make sure their program will execute in less than 30 ms.

How do we know when the program segment reaches 30ms? If we were to print a lot of characters to the serial port that might easily exceed 30ms. I really don't have a feel for how much code can be executed in 30ms.

I think a good way to write a complicated program would be to use a state machine and make sure any state executes in less than 30ms.

If any of the above seems like I don't understand, I would appreciate some clarification. I'm not sure how one should use "Yield" in a longer program, would we just insert "Yield" inline whenever a section of the program might take more than 30ms?

Tom W
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

twesthoff wrote:In the manual you wrote for the ESP8266 you mentioned that the Zbasic program will be essentially be a subroutine that will called every so often by the ESP8266 chip.
That is correct. If you are familiar with the Arduino's setup() and loop() functions, the "UserInit" function (see Option UserInit) is analogous to the former and the Main() is analogous to the latter. The main difference is that the "OS" of the ESP needs to process wireless and network tasks and if the Main() takes too long the OS can fall behind. That's what gives rise to the approximate 30mS time span. Occasional longer execution time (say, up to 50mS or more) probably won't be noticed but, in general, shorter passes are to be preferred.
twesthoff wrote:How do we know when the program segment reaches 30ms? If we were to print a lot of characters to the serial port that might easily exceed 30ms.
If you enable the RTC (see Option RTC) you could use the Register.RTCStopWatch value to time a sequence. Even if you don't enable the RTC, you can use Register.FRC2_COUNT in a similar fashion to measure elapsed time. That 32-bit value changes at a 5MHz rate giving you 200nS resolution for timing needs. (You can find an XML file giving all of the available ESP8266 registers in the file xml/xtensa/esp8266.xml relative to the installation directory.)

Writing to the serial port might not take as long as you expect since the output characters are queued up. If the queue is full, the queue handling code calls Yield() to allow the OS to run and then tries again, repeating until all of the requested characters are added to the queue. Specifying a larger output queue for Com1 might be desireable - see Option TxQueueSize.
twesthoff wrote:I think a good way to write a complicated program would be to use a state machine and make sure any state executes in less than 30ms.
I agree. You may have noticed that all of the example apps that we provide for the ESP8266 are implemented exactly that way.
twesthoff wrote:I'm not sure how one should use "Yield" in a longer program, would we just insert "Yield" inline whenever a section of the program might take more than 30ms?
Just so. Calling Yield() is the equivalent of returning from Main() and then resuming at the point of interest when Main() is called again.

One caveat is that Yield() is effective only in an execution thread arrived at directly via Main(). There are some APIs that allow the specification of a callback (see, for example, Net.SetCallback()). The execution of such a callback does not derive directly from Main(). Rather, the OS invokes the callback asynchronously with respect to Main(). You can call Yield() from such a callback but it will do nothing.
- Don Kinzer
twesthoff
Posts: 247
Joined: 17 March 2006, 6:45 AM
Location: Fredericksburg, VA

$5 WiFi module

Post by twesthoff »

Don,

Thanks for the great explanation on how the ESP8266 works.  I am not very familiar with the Arduino, but have read about it some. The ESP8266 seems to work the reverse other systems I have used, those let you write a program of most any length and the network service routine just periodically interrupts the main program loop in the background.

Concerning the ESP8266, as I understand it, if the "Main" routine is longer than 30ms then it just delays the normal WiFi processing tasks the ESP8266 operating system does.  If it gets too long, on the order of a few seconds, then a watchdog timer resets the chip. Is this correct?

I see in your LED blink example you count how often Main is called to control the blink rate.  Is this time a consistent value that can be used in our programs, or does it fluctuate depending on what the ESP8266 chip is doing? Perhaps it takes longer when sending or receiving data packets?

Although I can certainly write a program under these constraints, it does take a lot of thought and possibly would confuse some people since it isn't like a typical "ZBasic" program.
Just a thought, but I would think you could , for the sake of making life simple, make some kind of framework that works behind the scenes and automatically would break up a long program and insert the "Yield" statement as needed.  Then the programmer would not have to deal with the complexities of keeping program execution in pieces less than 30ms. It would make your Zbasic ESP8266 environment one of the easiest development platforms to use.

I'm getting excited to start on my first ESP8266 application with Zbasic as soon as I figure out how to send and receive data packets. First I'll jet try various things and get the hang of it.

Tom W
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: $5 WiFi module

Post by dkinzer »

twesthoff wrote:If it gets too long, on the order of a few seconds, then a watchdog timer resets the chip. Is this correct?
That is mostly correct as I understand it. The ESP8266 actually has two watchdogs: a SW watchdog and a hardware watchdog. The SW watchdog has a shorter period - on the order of seconds. You can stave off the expiration of the SW watchdog timer by calling the ZBasic routine WatchDog(). The hardware watchdog has a longer period, I seem to recall a reference to tens or hundreds of seconds. I have read that even if you keep feeding the SW watchdog via WatchDog(), the HW watchdog will eventually fire, resetting the chip.

You could devise some experiments to confirm what the periods of the two watchdog timers are.
twesthoff wrote:I see in your LED blink example you count how often Main is called to control the blink rate.  Is this time a consistent value that can be used in our programs, or does it fluctuate depending on what the ESP8266 chip is doing?
I believe that the latter is correct. The loop time is partly controlled by the Sleep() call and partly controlled by the OS overhead. For the purposes of the "blink" example the difference is immaterial by observation.

If you needed more precise timing you could use Register.RTCStopwatch or Register.FRC2_COUNT as described earlier. It should be noted, however, that using those values to regulate timing will only ensure that the elapsed tims is at least the desired value. There isn't a way to ensure that the elapsed time is no more than a given value since one can't control the system overhead. You could get closer by creating an ISR for Timer1 of the on-board RTC but there will still be some "jitter" due to non-maskable interrupts and interrupt latency.
twesthoff wrote:Although I can certainly write a program under these constraints, [...]
I think you may be worrying too much about the 30mS guideline. I would suggest writing the program to do the required work in "smallish" chunks and see how it works. If network performance seems sluggish you could add some measuring code and break the more time-consuming chunks into smaller pieces.
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Post by dlh »

Here's another Basic (it's a work in process) for the ESP8266.
http://www.esp8266basic.com/

They have an NodeMCU development board with their Basic interpreter preloaded. All coms are via WiFi.
http://www.esp8266basic.com/store/p1/ES ... Board.html

The ESP8266-01 is now available for $2 with free (slow boat from China) shipping.
http://www.ebay.com/itm/ESP8266-Serial- ... Sw-vlVhBXf

Probably, the $2 price is because there's a new version of the ESP8266-01 with twice the memory. Black PCBs are the newer ones. See...
http://www.banggood.com/search/esp8266.html

While a bit tricky, you can upgrade the flash on the older version.
http://www.picbasic.co.uk/forum/showthread.php?t=20180
twesthoff
Posts: 247
Joined: 17 March 2006, 6:45 AM
Location: Fredericksburg, VA

Temperature sensing

Post by twesthoff »

How hard would it be to make a wifi temperature sensor. Can the esp8266 handle the 1-wire temp sensors? I need a wifi temp sensor in two day. I probably can't get this to work that fast...
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Re: Temperature sensing

Post by dlh »

twesthoff wrote:How hard would it be to make a wifi temperature sensor. Can the esp8266 handle the 1-wire temp sensors? I need a wifi temp sensor in two day. I probably can't get this to work that fast...
http://www.esp8266basic.com/ds18b20-wif ... ostat.html
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Temperature sensing

Post by dkinzer »

twesthoff wrote:Can the esp8266 handle the 1-wire temp sensors?
The Arduino-ESP8266 code base has the Wire library for 1-Wire operations and the ZBasic System Library 1-Wire routines also work for the ESP8266.
- Don Kinzer
twesthoff
Posts: 247
Joined: 17 March 2006, 6:45 AM
Location: Fredericksburg, VA

Post by twesthoff »

My need for this came up suddenly and I will not have time to develop it now. I will have to buy something this time. I can probably buy the cheapest WiFi thermostat at Home Depot and use that.

I don't have time for mail order this time. I do hope to have time to make one with Zbasic later when I have more time.

To start with I'll just have it show the temp in a big font centered on the screen.

All - Thanks for the other ideas...
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Re: Temperature sensing

Post by dlh »

twesthoff wrote:How hard would it be to make a wifi temperature sensor. Can the esp8266 handle the 1-wire temp sensors? I need a wifi temp sensor in two day. I probably can't get this to work that fast...
While this is too late for your current project, this board will do what you need (and much more). You would need the generic license (or use Arduino code).
https://www.tindie.com/products/ceech/w ... mega328p/#
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Re: Temperature sensing

Post by dlh »

twesthoff wrote:How hard would it be to make a wifi temperature sensor. Can the esp8266 handle the 1-wire temp sensors? I need a wifi temp sensor in two day. I probably can't get this to work that fast...
While far too late to meet your Dec 3 deadline, there is a fairly simple plug-in solution using ZBasic for ESP8266 and the new WeMos D1 mini plus a WeMos temperature/humidity shield which can plug into the D1 mini. The mini has an onboard voltage regulator and CH340G USB-SER chip.
http://www.wemos.cc/wiki/doku.php?id=en:d1_mini
http://www.wemos.cc/wiki/doku.php?id=en:shields
Voila! We have a no-wire temperature/humidity sensor with 4MB flash, at $6 (mini + shield), with pins to spare and that can be powered from a 5V wall transformer with micoUSB plug.
http://www.aliexpress.com/store/product ... 50299.html

The WeMos website (wiki) has CH340G drivers (i.e. virtual COM port) for Windows and OSX.
http://www.wemos.cc/wiki/doku.php?id=en:ch340g

And, while their lots of Shields link currently leads to only three shields, I find "lots" to be encouraging given that the mini was only introduced about 6 weeks ago.
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

Hello, all... long time since I've been here. Been busy writing STM32F4xx C code in my consulting work. Love those processors.. much better than Freescale ARM Cortex.

On the hobby front: I've bought and played with, so far:

New Teensy Low Cost (LC). OK if you are a Teensy devote' which I was at one time. Not now.

Two ESP8266 - Adafruit's boards rather than the too cheap china ones. One is SMT, the other is pinned for breadboards. Comes with Lua interpreter pre-installed. I tried to like Lua, but no. So I reflashed it to use GCC and C/C++. Overall, I much prefer the new small/low cost RPi Zero board to the ESP8266. Adafruit's website getting started/examples are excellent. Remotes talk to an XBee piggyback board on the RPi Zero (or older RPi 2's). Or a PC's serial port.

Espruino Pico - Javascript interpreter. Nifty. Has ESP8266 piggback board.

Particle io board with WiFi. Best of the lot, so far. I've done C and microPython. Fun, but since these are sub-megabyte boards, there are lots of compromises. Uniquely small board but WiFi makes it bigger. Second choice to the RPi Zero, below.

Raspberry Pi Zero, the amazing and small $5 board. I was lucky to get one from the December build of 10,000. More in Jan or Feb. It's my favorite because of size, price and it runs full Linux so no compromises needed as in the others, above. Simplest too. Using a $7 WiFi USB dongle. That lets the Zero access my terabyte NAS for storage and run python code that lives on the NAS, not the RPI. Runs headless with VNC for remote access from my laptop/desktop PCs. Edit on my desktop PC using VNC. The Zero has just 5V (USB plug), and the WiFi dongle. Don't need the HDMI or USB keyboard/mouse connections. Sweet.

For I/O data control and acquisition, I'm (still) using XBee Series 1 without need for a microprocessor mated to it. The XBee's firmware options, remotely configurable over the air, lets me set these up to do most work without having to put code out there where these go- often outdoors. No over the air reprogramming firmware code needed. Does Analog to digital at modest sample rates, multiple channels. Digital input and output. Aggregate samples and send as a batch in one packet every x mSec. Sleep for battery powered projects, wakeup on timer or DIO event.


I'm writing apps on the Zero in Python 2.7 with, e.g., Pyserial and GPIO. I've long conquered Python's learning curve and now it's fun whereas C/C++ is tedium. Can use IDLE on the Zero via VNC, or use Komodo Edit on my desktop to edit python code that lives on the Zero's SD card or code stored on the NAS that the Zero executes.
Post Reply