Note WeMos – Connessione base

>>> LINK A PAGINA AGGIORNATA <<<

  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .
  • .

  • All’accensione il pin D3 non deve mai essere a zero altrimenti si avvia il boot.
  • All’accensione il pin D4 è alto tramite resistenza di pull-up.
  • All’accensione il pin D8 è basso tramite resistenza di pull-down.
  • Durante il reset il pin D0 va alto.
  • Durante la trasmissione si richiedono almeno 300mA.
  • Si può alimentare a 5V o a 3.3V, le uscite e gli ingressi sono a 3.3V
  • Si può resettare tramite pulsante o portando a gnd il pin ‘rst’

Codice base per connessione WiFi con IP statico e indicazione stato su LED on board (pin D4 corrispondente al GPIO2). Il LED è normalmente acceso per indicare presenza alimentazione. Se la connessione è assente, il LED si spegne per 20ms ogni 250ms. La variabile globale booleana ‘g_link_ok’ viene impostata a ‘true’ o ‘false’ a seconda dello stato della connessione. Se la connessione WiFi cade, ad esempio per reset router, la scheda WeMos si riconnette automaticamente.

#include     <ESP8266WiFi.h>
IPAddress    IPLOCALE(..., ..., ..., ...);
const char*  ssid = ".....";
const char*  PASSWORD = "................";
IPAddress    GATEWAY(..., ..., ..., ...);
IPAddress    SUBNET(..., ..., ..., ...);
bool         g_link_ok = false;
uint32_t     g_now;
uint32_t     g_board_led_time;
#define      ONBOARDLED  D4
//----------------------------------------------------------
//  FUNZIONE   : board_led_off
//  DESCRIZIONE: Spegne LED on board.
//  PARAMETRI  : nessuno, usa variabile globale
//               'g_board_led_time'
//  RETURN CODE: ignorato
//----------------------------------------------------------
void board_led_off(void)
{
    digitalWrite(ONBOARDLED, HIGH);
    g_board_led_time = g_now;
}
//----------------------------------------------------------
//  FUNZIONE   : board_led_on
//  DESCRIZIONE: Accende LED on board.
//  PARAMETRI  : nessuno
//  RETURN CODE: ignorato
//----------------------------------------------------------
void board_led_on(void)
{
    digitalWrite(ONBOARDLED, LOW);
}
//----------------------------------------------------------
//  FUNZIONE   : board_led_update
//  DESCRIZIONE: Trascorsi 20ms riaccende LED on board.
//               Questo e` un processo da
//               richiamare continuamente.
//  PARAMETRI  : nessuno, usa variabile globale
//               'g_board_led_time'
//  RETURN CODE: ignorato
//----------------------------------------------------------
void board_led_update(void)
{
    if ((g_now - g_board_led_time) > 20)
    {
        board_led_on();
    }
}
//----------------------------------------------------------
//  FUNZIONE   : link_survey_update
//  DESCRIZIONE: Controlla stato connessione WiFi, blinka
//               LED on board se non connesso, imposta
//               flag 'g_link_ok'.
//               Questo e` un processo da
//               richiamare continuamente.
//  PARAMETRI  : nessuno, usa variabili globali
//  RETURN CODE: ignorato
//----------------------------------------------------------
void link_survey_update(void)
{
    uint32_t static t = g_now;
    bool connesso = (WiFi.status() == WL_CONNECTED);
    
    if (connesso  and  !g_link_ok)
    { 
        g_link_ok = true;
    }
    else if (!connesso  and  g_link_ok) 
    { 
        g_link_ok = false;
        t = g_now;
    }
    else if (!connesso  and  ((g_now - t) > 250)) 
    { 
        board_led_off();
        t = g_now;
    }
}
//----------------------------------------------------------
//  FUNZIONE   : setup
//  DESCRIZIONE: Inizializza il sistema all'accensione
//  PARAMETRI  : nessuno
//  RETURN CODE: ignorato
//----------------------------------------------------------
void setup(void)
{
    WiFi.persistent(false);
    WiFi.mode(WIFI_OFF);
    delay(500);
    WiFi.mode(WIFI_STA);
    WiFi.setOutputPower(7.0);  // 0.0 .. 20.5
    WiFi.config(IPLOCALE, GATEWAY, SUBNET);
    WiFi.begin(ssid, PASSWORD);
    pinMode(ONBOARDLED, OUTPUT);
    board_led_on();
}  
//----------------------------------------------------------
//  FUNZIONE   : loop
//  DESCRIZIONE: Ciclo principale del programma, imposta
//               tempo globale 'g_now' (in millisecondi)
//               e richiama processi ciclici.
//  PARAMETRI  : nessuno
//  RETURN CODE: ignorato
//----------------------------------------------------------
void loop(void)
{
    g_now = millis();  // salva tempo globale attuale
    link_survey_update();
    board_led_update();
    delay(5);        // permette processi ESP in background
}

Codice FidoCadJ (visualizzatore online):

[FIDOCAD]
FJC C 3.0
FJC B 0.5
TY 32 62 4 3 0 0 0 Courier++10++Pitch d8
TY 32 37 4 3 0 0 0 Courier++10++Pitch a0
TY 32 42 4 3 0 0 0 Courier++10++Pitch d0
TY 57 32 4 3 0 0 0 Courier++10++Pitch tx
TY 57 67 4 3 0 0 0 Courier++10++Pitch 5v
TY 32 67 4 3 0 0 0 Courier++10++Pitch 3v3
TY 55 62 4 3 0 0 0 Courier++10++Pitch gnd
MC 70 35 0 1 ey_libraries.refpnt3
MC 70 40 0 1 ey_libraries.refpnt3
MC 70 45 0 1 ey_libraries.refpnt3
MC 70 50 0 1 ey_libraries.refpnt3
MC 70 55 0 1 ey_libraries.refpnt3
MC 70 60 0 1 ey_libraries.refpnt3
MC 70 65 0 1 ey_libraries.refpnt3
MC 70 70 0 1 ey_libraries.refpnt3
MC 25 45 2 1 ey_libraries.refpnt3
MC 25 50 2 1 ey_libraries.refpnt3
MC 25 55 2 1 ey_libraries.refpnt3
MC 25 70 2 1 ey_libraries.refpnt3
TY 57 42 4 3 0 0 0 Courier++10++Pitch d1
TY 57 47 4 3 0 0 0 Courier++10++Pitch d2
MC 25 65 2 1 ey_libraries.refpnt3
MC 25 60 2 1 ey_libraries.refpnt3
MC 25 35 2 1 ey_libraries.refpnt3
MC 25 40 2 1 ey_libraries.refpnt3
PV 65 30 30 30 30 75 35 75 35 80 65 80 0
TY 57 37 4 3 0 0 0 Courier++10++Pitch rx
TY 57 57 4 3 0 0 0 Courier++10++Pitch d4
TY 32 47 4 3 0 0 0 Courier++10++Pitch d5
TY 32 52 4 3 0 0 0 Courier++10++Pitch d6
TY 32 57 4 3 0 0 0 Courier++10++Pitch d7
TY 32 32 4 3 0 0 0 Courier++10++Pitch rst
TY 57 52 4 3 0 0 0 Courier++10++Pitch d3
BE 43 22 46 19 50 19 53 22 0
BE 41 20 45 16 51 16 55 20 0
SA 48 26 0
BE 45 24 47 22 49 22 51 24 0
TY 42 73 4 3 0 0 3 Courier++10++Pitch WeMos
RP 39 39 56 60 13

29/06/2019

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *