> ## Content Index
> Fetch the complete content index at: https://mfitzp.ghost.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Wemos D1 pin numbers & functions
- URL: https://mfitzp.ghost.io/wemos-d1-pins-micropython/
- Published: 2018-04-08T00:00:00.000Z
- Updated: 2024-03-29T22:05:36.000Z
- Description: Pin mapping and I2C/SPI from MicroPython
- Author: Martin Fitzpatrick
- Tags: Reference, MicroPython, Electronics, Python, #Import 2024-03-14 08:20, #Import 2026-08-24 14:26

Below is a quick reference guide to Wemos D1 pin mapping for GPIO, I2C and SPI when working from MicroPython.

## Pin mapping

The visible pin numbers written on the Wemos D1 does not relate to the internal pin numbering. In MicroPython you need to use the *internal* pin numbers to create your `Pin` objects and interface with the pins. The following table shows the internal to external pin mapping — together with the default *hardware level* functions for the given pin.

| Wemos D1 | ESP8266 Pin | Functions                                 |
| -------- | ----------- | ----------------------------------------- |
| D0       | 16          | GPIO                                      |
| D1       | 5           | GPIO, **I2C** SCL                         |
| D2       | 4           | GPIO, **I2C** SDA                         |
| D3       | 0           | GPIO                                      |
| D4       | 2           | GPIO                                      |
| D5       | 14          | GPIO, **SPI** SCK (Serial Clock)          |
| D6       | 12          | GPIO, **SPI** MISO (Master in, Slave out) |
| D7       | 13          | GPIO, **SPI** MOSI (Master out, Slave in) |
| D8       | 15          | GPIO, **SPI** SS (Slave select)           |
| A0       | A0          | Analog in, via ADC                        |
| RX       | 3           | Receive                                   |
| TX       | 1           | Transmit                                  |

ℹ️

The hardware `I2C` positions can be ignored in MicroPython, since the protocol is only available through a software implementation which works on all GPIO pins.

So, for example if you want to use pin `D6` for output, you could create the interface within MicroPython as follows:

```Python
import machine
d6 = machine.Pin(12, Pin.OUT)

```

The Wemos D1 only provides a single analogue input pin, which is accessed by it's ADC (referenced as 0).

```Python
import machine
adc = machine.ADC(0)

```

## I2C

The I2C ports in the table above reflect the pins where hardware I2C is available on ESP8266\. However, this is not currently accessible from MicroPython. Instead MicroPython offers a software I2C implementation accomplished by bit-banging, on any combination of GPIO pins. I usually stick them in the same place regardless —

```Python
from machine import I2C
i2c = I2C(-1, scl=Pin(5), sda=Pin(4))

```

ℹ️

The `-1` indicates to MicroPython to use the software I2C implementation.

You can provide any GPIO pins passing in to the `scl` and `sda` parameters.

```Python
i2c = I2C(-1, scl=Pin(12), sda=Pin(13))  # create I2C using ports D6 and D7 for SCL and SDA respectively

```

## SPI

SPI (Serial Peripheral Interface Bus) is a simple protocol, where master and slave device are linked by three data lines `MISO` (Master in, Slave out), `MOSI` (Master out, Slave in), `SCK` (Serial clock, also see as `M-CLK`)

ℹ️

The `SS` (Slave select) line is used to control communication with multiple slaves, for more information [see this writeup here](https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi?ref=mfitzp.ghost.io).

MicroPython provides both software and hardware SPI implementations both via the `machine.SPI` class.

To use the hardware implementation of SPI, pass in `1` for the first parameter. Pins `M-CLK`, `MISO`, `MOSI` (and `SS`) will end up on the pins shown in the table (`D5`, `D6`, `D7` and `D8` respectively).

```Python
from machine import Pin, SPI
spi = SPI(1, baudrate=80000000, polarity=0, phase=0)

```

The software implementation can be used by passing `-1` as the first parameter, and pins to use for `sck`, `mosi` and `miso`.

```Python
from machine import Pin, SPI
spi = SPI(-1, baudrate=100000, polarity=1, phase=0, sck=Pin(5), mosi=Pin(4), miso=Pin(0))

```