WeMos D1 (esp8266): i2c shield to manage encoder, multiple buttons, and LEDs

Spread the love

For fast prototyping, I will create a set of shields for the WeMos D1 mini; the first is a service board with integrated pcf8574 IC, an encoder, and five other pins to use as input or output.

Naturally, I start my work from the example I created for my library in this article “PCF8574 i2c digital I/O expander: Arduino, esp8266 and esp32, rotary encoder“.

WeMos D1 mini pcf8574 encoder breadboard photo
WeMos D1 mini pcf8574 encoder breadboard photo

The basic breadboard schema is quite simple, and It’s better explained in the library article.

WeMos D1 mini pcf8574 encoder breadboard simple
WeMos D1 mini pcf8574 encoder breadboard simple

Here is the video with the code at work.

PCB

You can find the updated version of the PCB on PCBWay for a few dollars.

WeMos D1 mini pcf8574 encoder shield PCB
WeMos D1 mini pcf8574 encoder shield PCB

WeMos D1 mini pcb with pcf8574 and encoder PCBWay
PCB from PCBWay

Here is the PCB schema. It’s become quite complex because I’m going to add the switches to change the address of pcf8574 some jumper to activate buttons or use the pins as output.

WeMos D1 mini pcf8574 encoder shield PCB
WeMos D1 mini pcf8574 encoder shield PCB

Start milling to get the prototype

WeMos D1 mini pcf8574 encoder shield PCB rough milled
WeMos D1 mini pcf8574 encoder shield PCB rough milled

Materials

ObjectDescr.
1DIP SWITCHpackage dipswitch-03
1210kΩ Resistor
4Pushbuttonpackage [THT]
2Ceramic Capacitorpackage 100 mil [THT, multilayer]; capacitance 100nF
6Generic male header – 2 pinspackage THT; form ♂ (male)
1PCF8574package DIP16; type PCF8574
1Rotary Encoderpackage THT; Tipo ALPS ec11e
1WeMos D1 Mini

You can find WeMos D1 mini on WeMos D1 mini - NodeMCU V2 V2.1 V3 - esp01 - esp01 programmer

You can find rotary encoder on AliExpress

You can find pcf8574 on AliExpress

Assembly video

And now all assembled.

WeMos D1 mini pcf8574 encoder shield PCB up with description
WeMos D1 mini pcf8574 encoder shield PCB up with the description

Here the shield used in a project.

WeMos D1 mini pcf8574 encoder shield PCB at working
WeMos D1 mini pcf8574 encoder shield PCB at working

And here is the code for putting the shield in working condition; as you can see, the parameters are

esp8266pcf8574
SDAD2 (PullUp)
SCLD1 (PullUp)
INTD7 (PullUp)

and the encoder

pcf8574Encoder
P0PIN A
P1PIN B
P2BUTTON
/*
 * PCF8574 Shield encoder and buttons
 * https://mischianti.org
 *
 * PCF8574    ----- WeMos
 * SDA        ----- D2(PullUp)
 * SCL        ----- D1(PullUp)
 * INT        ----- D7(PullUp)
 *
 * PCF8574 ----------------- Encoder
 * P0      ----------------- ENCODER PIN A
 * P1      ----------------- ENCODER PIN B
 * P2      ----------------- ENCODER BUTTON
 *
 */
#include "Arduino.h"
#include "PCF8574.h"
 
int encoderPinA = P0;
int encoderPinB = P1;
 
#define INTERRUPTED_PIN D7
 
void ICACHE_RAM_ATTR updateEncoder();
 
// initialize library
PCF8574 pcf8574(0x38, INTERRUPTED_PIN, updateEncoder);
 
volatile long encoderValue = 0;
uint8_t encoderButtonVal = HIGH;
 
void setup()
{
    Serial.begin (9600);
    delay(500);
 
    // encoder pins
    pcf8574.encoder(encoderPinA, encoderPinB);
    // encoder button
    pcf8574.pinMode(P2, INPUT_PULLUP);
 
    // Start library
    pcf8574.begin();
 
}
 
bool changed = false;
 
// The loop function is called in an endless loop
void loop()
{
    if (changed){
        Serial.print("ENCODER --> ");
        Serial.print(encoderValue);
        Serial.print(" - BUTTON --> ");
        Serial.println(encoderButtonVal?"HIGH":"LOW");
        changed = false;
    }
}
 
bool valPrec = LOW;
void updateEncoder(){
    changed = pcf8574.readEncoderValue(encoderPinA, encoderPinB, &encoderValue);
 
//  int vale = pcf8574.readEncoderValue(encoderPinA, encoderPinB);
//  if (vale!=0){
//      changed = true;
//  }
//  encoderValue = encoderValue + vale;
 
    bool val = pcf8574.digitalRead(P2);
    if (val!=valPrec){
      changed = true;
      valPrec = val;
      encoderButtonVal = val;
    }
}

Thanks

  1. WeMos D1 (esp8266): i2c shield to manage encoder, multiple buttons, and LEDs
  2. WeMos D1 (esp8266): relay shield
  3. WeMos D1 (esp8266): Ebyte LoRa shield (e32, e22 and e220)


Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *