Bitbull Tech Notes - home of free minds ...

Getting started with ESP8266 ESP01 and Arduino IDE 1.6

Hi there

Today I started programming the tiny low cost chip ESP8266.
First I ordered some ESP-01 variants to get my Arduino Projects communicating wireless.
By waiting for delivery I started reading about the chip-set, and it is amazing what you can do with it!

ESP-01 Variant has the following specifications:
It’s running at 80MHz
32KBytes of instruction RAM
96KBytes of data RAM
64KBytes boot ROM
It has a Winbond W25Q40BVNIG SPI flash with 1024kB Flash (old blue version has 512kB)
It’s a RISC architecture
The core is a 106micro Diamond Standard core (LX3) made by Tensilica
2 GPIO Pins
http://www.addicore.com/ESP8266-ESP-01-p/130.htm

As far as I know you can program it with the following code/IDE:

I tested programming it with Arduino IDE and it worked like a charm out of the box:

  • Integrate ESP8266 Boards into Arduino IDE
    https://github.com/esp8266/Arduino
  • Tools > Board > Generic ESP8266 Module
  • File > Examples > ESP2866WebServer > AdvancedWebserver
  • Edit SSID and WPA_Secret
  • Connect Serial Console (to get IP when booting)
  • Compile and Upload

All you need is:

 

 

 

 

Arduino Birdhouse

 Few weeks ago I built a birdhouse with my kids for playing.

But what is the worth of a birdhouse without a bird???

Here we go: all you need is a ProMini an piezo speaker... :-)

 

int piezopin = 2;  // select the input pin for the speaker
int ledpin = 13;
int ledstate = LOW;
int counter = 0; 
unsigned long mydelaySing = 180000;
unsigned long mydelayLED = 1000;
unsigned long currentMillis = 0;
unsigned long previousMillisSing = 0;
unsigned long previousMillisLED = 0;

void setup() {
  pinMode(ledpin, OUTPUT);     
  pinMode(piezopin,OUTPUT);
  Serial.begin(9600);
  sing();
  sing();
}

void loop() {
  currentMillis = millis();
  
  if(currentMillis - previousMillisSing > mydelaySing) {
    sing();
    previousMillisSing = currentMillis;  
  }
  if(currentMillis - previousMillisLED > mydelayLED) {
    if (ledstate == LOW) {
      ledstate = HIGH;
    }else{
      ledstate = LOW; }
    digitalWrite(ledpin, ledstate);
    previousMillisLED = currentMillis;  
  }
}


void sing() {
  Serial.print(mydelaySing);
  Serial.print(" ");
  Serial.print(currentMillis);
  Serial.println(" Sing");
  for(int i = 0; i<random(1,2); i++ ){
    counter = random(2,4);
    //makes the sound according to: intensity, varies: normally 5. number of times: how many times tweets, rormally 3-6
    highChirp(random(3,6),random(4,9));
    delay(100);
    lowChirp(random(10,20),2);
    delay(100);
    tweet(counter,random(1,3));
    //delay between the closer tweets
    delay(random(100,400));
  }
}
void highChirp(int intensity, int chirpsNumber){
  int i;
  int x;
  for(int veces=0; veces<=chirpsNumber; veces++){
    for (i=100; i>0; i--)
    {
      for  (x=0; x<intensity;  x++)
      {
        digitalWrite (piezopin,HIGH);
        delayMicroseconds (i);
        digitalWrite (piezopin,LOW);
        delayMicroseconds (i);
      }
    }
  }
}

void lowChirp(int intensity, int chirpsNumber){
  int i;
  int x;
  for(int veces=0; veces<=chirpsNumber; veces++){
    for (i=0; i<200; i++)
    {
      digitalWrite (piezopin,HIGH);
      delayMicroseconds(i);
      digitalWrite(piezopin,LOW);
      delayMicroseconds(i);
    }
    for (i=90; i>80; i--)
    {
      for  ( x=0; x<5;  x++)
      {
        digitalWrite (piezopin,HIGH);
        delayMicroseconds (i);
        digitalWrite (piezopin,LOW);
        delayMicroseconds (i);
      }
    }
  }
}

void tweet(int intensity, int chirpsNumber){
  int i;
  int x;
  for(int veces=0; veces<chirpsNumber; veces++){
    for (int i=80; i>0; i--)
    {
      for  (int x=0; x<intensity;  x++)
      {
        digitalWrite (piezopin,HIGH);
        delayMicroseconds (i);
        digitalWrite (piezopin,LOW);
        delayMicroseconds (i);
      }
    }
  }
  delay(random(100,1000));
}


Pseudo Clock with millis()

Hi,
I needed a clock like function for plant watering and growing light.
But I did not need to have accurate time, so I decided to program this clock.
And hey ... it does work like a charm!

#include <EEPROM.h>

// ---------- GLOBAL VARS ----------  ---------- ---------- ----------
unsigned long currentMillis;

// ---------- EEPROM SPACE FOR BOOT PERSISTENT VARS ----------
#define timeHourEE     1
#define timeMinEE       2 

// ---------- PSEUDO CLOCK VARS ----------  ---------- ---------- ----------
int timeHour = EEPROM.read(timeHourEE);
int timeMin  = EEPROM.read(timeMinEE);
unsigned long timeShift = 0;
unsigned long previousMillisTime = 0;
unsigned long currentMillisTime = 0;

void setup() {    
  // ---------- GLOBAL SETUP ----------
  Serial.begin(9600);
  // ---------- WAIT FOR HUMAN TO SETTLE UP SERIAL CONSOLE ----------
  delay( 2000 );
  Serial.println(F("INFO: Arduino is online")); 
}

void loop(){ 

  // ---------- PSEUDO CLOCK ----------  ----------  ---------- 
  currentMillisTime=millis();
  if(currentMillisTime - previousMillisTime >= 60000UL ) {   // is last check more than 1min ago
    timeShift = (currentMillisTime - previousMillisTime) / 60000UL ; // how many minutes are gone?
    previousMillisTime = previousMillisTime + ( timeShift * 59900UL ) ;  // adjust last check time stamp (adjust clock speed here)
    timeMin = timeMin + (int)timeShift;
    EEPROM.write(timeMinEE, timeMin);
    Serial.print(F("DEBUG: ")); 
    Serial.print(timeHour); 
    Serial.print(F(":")); 
    Serial.println(timeMin);
    if (timeMin >= 60) {
      timeHour++; 
      if (timeHour >= 24) { 
        timeHour = 0; 
      }
      EEPROM.write(timeHourEE, timeHour);
      timeMin = timeMin - 60;
    }
  }
}

 

 

Home