Skip to content

Wemosd1

Wemos D1 mini

Bajo File -> Preferences agregar un "Boards Manager URL" pegando lo siguiente:

El "boards manager" instala una versión de esp8266 (2.6.1) que ya no tiene el Wemos D1 mini en la lista. Por suerte se puede instalar una versión anterior que si la tiene (2.3.0, 2.5.2, y otras).

Una vez instalada la lista de boards, seleccionar WeMos D1 R1.

20200903-073903.png

Power

  • 5-12 V a través del USB
  • 5 V a través del pin de +5V VCC

Ver: https://docs.zerynth.com/latest/official/board.zerynth.wemos_d1_mini/docs/index.html

Pinout reference

WeMos D1 mini Pin Number Arduino IDE Pin Number


D0 16 D1 5 D2 4 D3 0 D4 2 D5 14 D6 12 D7 13 D8 15 TX 1 RX 3

Referencias:

LED blinker test

/* Blink and wait
 *
 * Blinks the onboard LED, waits for 2 seconds and repeats
 */

// Wait for this many seconds
const int sleepSeconds = 2;

void setup() {
  Serial.begin(9600);
  Serial.println("\n\nWake up");

  pinMode(BUILTIN_LED, OUTPUT);
}

void loop() {
  // LED: LOW = on, HIGH = off
  Serial.println("Start blinking");
  for (int i = 0; i < 20; i++)
  {
    digitalWrite(BUILTIN_LED, LOW);
    delay(100);
    digitalWrite(BUILTIN_LED, HIGH);
    delay(100);
  }
  Serial.println("Stop blinking");

  Serial.printf("Delay for %d seconds\n\n", sleepSeconds);
  delay(sleepSeconds * 1000);
}

Web Server

Actualizar sitio completo automaticamente - JS

References:

Definir el header del HTML al inicio del script:

String html_head = R"=====(
 <head>
  <script>
   function refresh(refreshPeriod) 
   {
      setTimeout("location.reload(true);", refreshPeriod);
   } 
   window.onload = refresh(5000);
  </script>
 </head>
)=====";

Imprimir el header del al cliente (dentro de loop):

  client.println(html_head); // print HTML header

Actualizar una parte automaticamente - AJAX

/*
 * Sketch: ESP8266_Part8_03_AutoUpdate_Javascript_AJAX
 * Intended to be run on an ESP8266
 */

String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";

String html_1 = R"=====(
<!DOCTYPE html>
<html>
 <head>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'/>
  <meta charset='utf-8'>
  <style>
    body {font-size:100%;} 
    #main {display: table; margin: auto;  padding: 0 10px 0 10px; } 
    h2 {text-align:center; } 
    p { text-align:center; }
  </style>

  <script> 
    function updateCount() 
    {  
       ajaxLoad('getCount'); 
    }


    var ajaxRequest = null;
    if (window.XMLHttpRequest)  { ajaxRequest =new XMLHttpRequest(); }
    else                        { ajaxRequest =new ActiveXObject("Microsoft.XMLHTTP"); }

    function ajaxLoad(ajaxURL)
    {
      if(!ajaxRequest){ alert('AJAX is not supported.'); return; }

      ajaxRequest.open('GET',ajaxURL,true);
      ajaxRequest.onreadystatechange = function()
      {
        if(ajaxRequest.readyState == 4 && ajaxRequest.status==200)
        {
          var ajaxResult = ajaxRequest.responseText;
          document.getElementById('count_P').innerHTML = ajaxResult;
        }
      }
      ajaxRequest.send();
    }

    setInterval(updateCount, 5000);

  </script>
  <title>Auto Update Example Using Javascript 2</title>
 </head>

 <body>
   <div id='main'>
     <h2>Auto Update Example Using Javascript 2</h2>
     <div id='count_DIV'> 
       <p id='count_P'>Count = 0</p>
     </div>
     <div>
       <p>Click <a href="">here</a> to refresh.</p>
     </div>
   </div> 
 </body>
</html>
)=====";
#include <ESP8266WiFi.h>

const char* ssid = "SSID";
const char* password = "password";

WiFiServer server(80);

String request = "";
unsigned int count = 0; 

void setup() 
{
    Serial.begin(115200);
    Serial.println();
    Serial.println("Serial started at 115200");
    Serial.println();

    // Connect to a WiFi network
    Serial.print(F("Connecting to "));  Serial.println(ssid);
    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) 
    {
        Serial.print(".");
        delay(500);
    }

    Serial.println("");
    Serial.println(F("[CONNECTED]"));
    Serial.print("[IP ");              
    Serial.print(WiFi.localIP()); 
    Serial.println("]");

    // start a server
    server.begin();
    Serial.println("Server started");

} // void setup()


void loop() 
{
    // Check if a client has connected
    WiFiClient client = server.available();
    if (!client)  {  return;  }

    // Read the first line of the request
    request = client.readStringUntil('\r');

    if ( request.indexOf("getCount") > 0 )
     { 
        count ++;
        client.print( header );
        client.print( "Count = " ); 
        client.print( count ); 

        Serial.print("Count=");
        Serial.println(count);
     }

     else
     {
        client.flush();
        client.print( header );
        client.print( html_1 ); 
        count = 0;
     }

    delay(5);


  // The client will actually be disconnected when the function returns and 'client' object is destroyed
} // void loop()

Servo server

Servo magic: https://znil.net/index.php/ESP8266_Wemos_D1_Mini_mit_Servo_Motor_SG90_Beispiel

Hall Effect Sensor

Sensor: 3144 AA151

La lectura del sensor depende de la orientación del campo magnetico. Al parecer solo se "activa" cuando el imán está del lado "correcto".

20200518-145307.png

Conecté el data pin del sensor a D0 del WeMos y en el Arduino IDE eso corresponde al pin número 16.

// pin D1 is number 5
// pin D0 is number 16
int hall_pin = 16;


void setup() {
  Serial.begin(9600);
  //pinMode(A0, INPUT);
  pinMode(hall_pin, INPUT);

  // Setup LED pin
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, LOW);
}

void loop() {
  //Serial.println(analogRead(A0));
  Serial.println(digitalRead(hall_pin));
  if(digitalRead(hall_pin) > 0){
    digitalWrite(BUILTIN_LED, HIGH);
  } else {
    digitalWrite(BUILTIN_LED, LOW);
  }
}

I2C OLED Display