I became obsessed last week with the thought that the very cheap ESP8622 could be useful if it did not have RF consuming so much power.

Crazy? Probably: but playing around with the idea and finding a very easy mechanism for disabling the RF section to drop the power consumption, I am now finding that a non-RF ESP8622-12E module in the NodeMCU form factor is only taking 20mA at 80MHz and under 40mA (30'ish) at 160MHz. That is pretty remarkable for the cost.

The specific unit I am using in my test is this one - excepting that I paid $3.11 with free shipping.

So what kind of performance does $3 and pennies provide? I am working on more examples, but I took an STM32duino example I ported from the 8-bit AVR world which was written by the renown Nick Gammon and I ported the STM32 port to ESP8266. Adding a single unsigned long var to time a single pass of the program, this is the results on the STM32duino Maple Mini with bootloader 2.0 and the power consumption was 40+mA

Code: Select all

```
Prime Number Generator
Number of primes in prime table = 53
Last prime in table = 251
Calculating primes through 63001
Total microseconds = 199887 uS
```

Code: Select all

```
@80MHz
Prime Number Generator by Nick Gammon
ESP8266 port by Ray Burnette
Number of primes in prime table = 53
Last prime in table = 251
Calculating primes through 63001
Starting uS timer now... uS = 3619257
Sketch terminating.
```

Code: Select all

```
@160MHz
Prime Number Generator by Nick Gammon
ESP8266 port by Ray Burnette
Number of primes in prime table = 53
Last prime in table = 251
Calculating primes through 63001
Starting uS timer now... uS = 1813374
Sketch terminating.
```

But, one must remember that the ESP8266 has significantly more RAM and flash; therefore, less expensive with fair performance may mean that an RF disabled ESP8266 may find it's way into a future project.

STM32duino:

Sketch uses 14,508 bytes (11%) of program storage space. Maximum is 122,880 bytes.

Global variables use 2,632 bytes of dynamic memory. (Bootloader 2.0 leaves 20K available)

ESP8266-duino:

Sketch uses 232,782 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.

Global variables use 31,995 bytes (39%) of dynamic memory, leaving 49,925 bytes for local variables. Maximum is 81,920 byte

Very interesting, I think. I am still attempting to validate the remarkable performance of the STM32F103 at less than 0.2 seconds. At first, I thought maybe micros overflowed, but repeated testing using millis() yielded 200. Can it be that much faster? I think so.

Ray

ESP8266 test code

Code: Select all

```
/*
PrimeNos: by Nick Gammon
ESP8266 Arduino port m. ray burnette
OS version Linux Mint 17.3 32-bit tested on 20160419
Compiled under Arduino 1.6.8
Sketch uses 232,782 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 31,995 bytes (39%) of dynamic memory, leaving 49,925 bytes for local variables. Maximum is 81,920 bytes.
PUBLIC DOMAIN EXAMPLE
RF sleep reference: https://github.com/esp8266/Arduino/issues/460#issuecomment-168970936
*/
extern "C" {
#include "user_interface.h"
}
#include <ESP8266WiFi.h> // for the low power function
#include <Streaming.h>
#define BOARD_LED_PIN 2
#define FREQUENCY 80 // valid 80, 160
// just add more primes to the prime table for larger search
// byte data type to save memory - use a larger datatype with prime table entries above 255 :)
byte primes[]= {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
102, 107, 109, 113, 127, 131, 137 , 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197,
199, 211, 223, 227, 229, 233, 239, 241, 251 };
// if you change the datatype of primes array to int, change next line to
// "const int TopPrimeIndex = (sizeof(primes)/2) - 1;"
const unsigned int TopPrimeIndex = sizeof(primes) - 1;
const unsigned long TopPrimeSquared = (long)primes[TopPrimeIndex] * (long)primes[TopPrimeIndex];
int primeFlag;
unsigned long t = 0;
void setup()
{
WiFi.forceSleepBegin(); // turn off ESP8266 RF
delay(1); // give RF section time to shutdown
// yield(); // generally same as delay(1) but inconsistent
system_update_cpu_freq(FREQUENCY);
pinMode(BOARD_LED_PIN, OUTPUT);
Serial.begin(115200);
Serial << endl << endl;
Serial << "Prime Number Generator by Nick Gammon\r\n";
Serial << "ESP8266 port by Ray Burnette\r\n\r\n";
Serial << "Number of primes in prime table = ";
Serial << TopPrimeIndex << endl << endl;
Serial << "Last prime in table = ";
Serial << (unsigned int)primes[TopPrimeIndex] << endl;
Serial << "Calculating primes through ";
Serial << TopPrimeSquared << endl << endl;
Serial << "Starting uS timer now... ";
t = micros();
}
void loop()
{
for (long x = 1; x < TopPrimeSquared; x+=2) // skips even numbers, including 2, which is prime, but it makes algorithm tad faster
{
for (long j=0; j < TopPrimeIndex; j++){
primeFlag = true;
if (x == primes[j]) break;
if (x % primes[j] == 0){ // if the test number modolo (next number from prime table) == 0
primeFlag = false; // then test number is not prime, bailout and check the next number
break;
}
delay(0);
}
if (primeFlag == true) // found a prime
{
digitalWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));
yield();
// Serial.println(x);
}
}
Serial << "uS = " << micros()-t << endl;
Serial << "Sketch terminating. Press Reset to rerun." << endl;
for(;;) yield() ; // infinite loop with yield to prevent WDT
}
```