Script to Read Pin A0 on Wemos D1
Pin numbering for WeMos D1 Mini (ESP8266)
Here I explicate the difference in pin numbering for the WeMos D1 Mini compared to an Arduino and include a sample blink sketch.
Setting up the Arduino IDE for the WeMos D1 mini
This tutorial assumes that you have prepare up the Arduino IDE to able to compile the Wemos D1 mini.
You can follow the steps as outlined in the post Configuring the Wemos D1 Mini Pro ESP8266 for Arduino IDE. Once it is ready up as described in the tutorial the Arduino IDE needs to be set to compile for the WeMos D1 Mini
Difference betwixt the Arduino and WeMos D1 mini pins
One of the issues you will encounter when programming the WeMos D1 is that pin 1 on the WeMos isnt pin 1 in the Arduino IDE. The pin numbers in the WeMos D1 Pro (the ESP8266) are differently numbered than the Arduino.
This means that if y'all want to plough on pin one on the WeMos D1 mini y'all will need to use a different pivot in the IDE. For case to enable the pivot labelled D1 for output for the WeMos you lot would need to use the following lawmaking:
void setup() { Serial.begin(115200); pinMode(5, OUTPUT); //Digital pin 1 is pin 5 on the ESP8266 }
The total list of output pins to identifiers are equally follows, taken from the source lawmaking:
Labelled WeMos Pin Number | Arduino Pin Number constant to use | "Existent" Microcontroller Pivot Number |
Digital Pivot 0 | D0 | 16 |
Digital Pivot i | D1 | 5 |
Digital Pivot two | D2 | 4 |
Digital Pin iii | D3 | 0 |
Digital Pin 4 | D4 | 2 |
Digital Pin five | D5 | 14 |
Digital Pin six | D6 | 12 |
Digital Pin 7 | D7 | xiii |
Digital Pin 8 | D8 | 15 |
TX | TX | 1 |
RX | RX | 3 |
These tin can exist used to program the WeMos D1 mini using the Arduino IDE.
Nonetheless in that location is an easier style. The ESP8266 Arduino library provides a number of constants to program the WeMos electronics easier. These constants are named as same every bit the pins, so digital pin one labelled on the WeMos as D1 tin exist used with the constant D1
.
So our above case can exist made easier using these constants
void setup() { Serial.begin(115200); pinMode(D1, OUTPUT); //Digital pin ane is pin 4 on the ESP8266 and D1 as a constant }
Using these constants mean nosotros don't need to refer to the table to find which pivot number relates to Arduino pin.
Case Blink Sketch for WeMos D1 mini
To demonstrate using these constants I have rewritten the Arduino blink sketch using the WeMos D1 mini. The lawmaking is every bit follows:
void setup() { Serial.begin(115200); pinMode(D1, OUTPUT); } void loop() { //We apply D1 as a constant instead of 1 since the port mapping is different to the Arduino. digitalWrite(D1, HIGH); Serial.println("Blink On"); delay(2000); digitalWrite(D1, LOW); Series.println("Glimmer Off"); filibuster(2000); }
Here I initialize the Serial connection so nosotros can see progress of the program. Using this I take added the boosted logging to the program.
The principal difference to the standard Arduino Blink sketch is that I am using the constant D1
as discussed earlier instead of 5
every bit the pin number.
Using these constants you lot can easily programme the WeMos D1 mini and other WeMos microcontrollers.
If you accept any questions virtually the WeMos or using the constants in a higher place feel complimentary to enquire below.
Source: https://chewett.co.uk/blog/1066/pin-numbering-for-wemos-d1-mini-esp8266/
0 Response to "Script to Read Pin A0 on Wemos D1"
Post a Comment