Porting Arduino Uno code to Wemos D1 R2

Hello. I just bought a Wemos D1 R2 to have alexa in a school project. Then i figured out that the pinouts of the wemos are super complicated to me. Could anyone help me to port over the pins and code? Here is the pinouts that i had in my Uno:

#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Servo.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

Servo myservo;
int pos = 0;

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 8, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


Sorry I cannot follow your code therefore I cannot answer your question. However this link probably will:

You will find as I did several pins although marked differently are the same. I would write some code that blinks each a pin, then change the code and do the next. You should get it figured out doing that. You could do as I did and use a port expander such as the PCF8574.

The D1 R2, IMO is one of the most confusing boards from a pin mapping perspective.
It can be quite confusing to get the pin numbers correct.
For an UNO based form factor, IMO, the D1 (not the D1 R2) is a better choice.

On the esp8266 platform. a naked constant like 7 or 6 specify a GPIO bit number.
If you have an UNO type form factor board like a D1 or a D1 R2 board you cannot use naked constants like you used on a UNO board.
I.e. Arduino pin 2 is not the same pin location on the header on a Wemos board.

The Wemos board types contain Dx symbols to map from an "uno" type pin reference number to a GPIO number
The intent was to be able to map UNO type pin numbers to wemos pins on UNO form factor esp8266 boards.
It was so you could simply use say D7 instead of 7 to get pin on the header reference as 7 on an UNO.
(but that does not work on the D1 R2 board - see below for more)

The Dx symbols do not map directly to GPIO numbers.
Example D7 is GPIO 13
D6 is GPIO 12

Making things even worse/more confusing is the D1 R2 board.
On the D1 (not the R2) board, you can use D7 to get to the same pin as 7 on an UNO.
But that does not work on the D1 R2 since on that board they skipped over the pin locations for the serial port which are 0 and 1 on an UNO which means that all Dx pin numbers are offset by 2.
So D0 on the D1 R2 is the pin position for pin 2 on an UNO since all the pins are offshifted by 2.

The simple thing to do is simply use what is printed on the PCB for the pin you want to reference.
i.e. if you see "D7" printed on the PCB next to the pin you want to reference, use that not 7

Also pay close attention to the pins as the esp8266 doesn't have as many actual pins as the UNO so some pins are re-used.
Depending on the board you have it may show to pins like D7/D11 that means that the same pin is reference by D7 or D11.

--- bill

Similar situation and some kind of conclusion.


This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.