Expansion options & Protocols
Eventually you might run out of pins on your WeMOS. If that is the case you have a few options. We will go through them one by one and toch the topics: I2C, SPI, Multiplexer
1. I/O Expander board
Add an PCF8574/75 based IO expander to your WeMOS D1 Mini to get 8 or 16 more I/O pins on your WeMOS. You can get them from Miguel or buy them yourself is we run out.
Examples: Add more pins to your Arduino/ESP8266 board using PCF8574T module https://www.youtube.com/watch?v=usPiM_vv-rc
Where to buy:
PCF8574 I2C IO Expander - 8 Extra IO pins https://www.tinytronics.nl/en/communication-and-signals/io-converters/pcf8574-i2c-io-expander
Open-Smart PCF8575 IO Expander Module - 16 Extra IO pins https://www.tinytronics.nl/en/communication-and-signals/io-converters/open-smart-pcf8575-io-expander-module-16-extra-io-pins
2. I2C
Select sensors/modules that speak I2C protocol. You can chain them together on an I2C bus. A (data)bus is basically a bunch of dedicated wires between two or more devices to exchange data. Creating an I2C bus will cost you SDA (data), SCL (clock), so 2 pins for connecting about max 127 sensors in a chain.
See these movieclips to learn how I2C works:
Easy I2C: Introduction to I2C https://www.youtube.com/watch?v=qeJN_80CiMU
How I2C Communication Works and How To Use It with Arduino https://www.youtube.com/watch?v=6IAkYpmA1DQ
Understanding I2C https://www.youtube.com/watch?v=CAvawEcxoPU
3. SPI
Select sensors/modules that speak SPI protocol. You can chain them together on an SPI bus. Creating an SPI bus will cost you MISO (Master In/Slave Out), MOSI (Master Out/Slave In), SCLK (Serial Clock), so 3 pins and an additional SS (Slave Select) od CS (Chip Select) pin for each SPI device you add to the SPI-bus.
See these movieclips to learn how SPI works:
Understanding SPI https://www.youtube.com/watch?v=0nVNwozXsIc
Electronic Basics #36: SPI and how to use it https://www.youtube.com/watch?v=fvOAbDMzoks
Note that nowadays it is not very woke to talk about masters and slaves. So the pins MISO and MOSI have been renamed to PICO and POCI. SS is now CS (Chip Select). However, you will still find the old naming convention in 99% of the documents on the internet, See this article for more information: https://www.oshwa.org/2022/01/10/new-spi-terminology/
4. Multipler
Use a multiplexer to use less pins.
Arduino Multiplexer - MUX INPUTS & OUTPUTS - ANALOG and PWM https://www.youtube.com/watch?v=Dco6jo9xgAo
5. Arduino UNO
Use the pins on the Arduino UNO R3 and use the WeMOS D1 mini as a wifi router for your Arduino UNO R3. You can send data between WeMOS/Arduino UNO R3 using either RX/TX, SPI, or I2C protocols. And then add your own communciation protocol on top of that. Do not forget to use a logic level shifter between devices.
See this tutorial for explanation of the differences between the RX/TX, SPI and I2C protocols:
PROTOCOLS: UART - I2C - SPI - Serial communications #001 https://www.youtube.com/watch?v=IyGwvGzrqp8