Virtual pin referencing physical didn't work. Can help?

Can anyone help me to figure out where is the problem when i programm a virtual pin to control a LED ON/OFF state. I use a Button widget and set to V1 pin . The circuit connection : D7 connect to a LED anode with a resistor in series. Cathode of the LED back to GND. Below is the sketch:

const int led = 7;

BLYNK_WRITE(V1)
{ 
  int ledState = param.asInt();
  digitalWrite(7,ledState);
}

pinMode(7,OUTPUT);

I’m using WeMos D1 wifi board.

This is telling the hardware to use GPIO7 for the LED
Pin D7 on the Wemos IS NOT GPIO7, it’s GPIO13

As you’ll see from the pinout diagram above, GPIO7 is not directly available on the Wemos D1 Mini.

Pete.

I’m a newbie, it’s mean that i change the pinMode(7,OUTPUT) to pinMode(13,OUTPUT) and the anode of LED connect to D13?

No leave the LED where it is. The silly D7 label is GPIO 13 so just the pinMode change to 13.

1 Like


This is the board i’m using. Quite confuse to the pins. How to understand the pins?

Very little difference between the full Wemos and the mini, your pinout is at https://wiki.wemos.cc/products:d1:d1

Thanks for the information. I try to understand the pins.

They can be very confusing… or simple, depending on how you look at it and code for it.

For example this code, while using two different pin designations, will work just fine as both are referring to the same WEMOS pin. And as long as your IDE knows it is programming a Wemos D1 or D1 Mini, it will compile and work properly.

void setup() {
// BOTH are not required - only the last one takes precedence, but either of these will work as they are both referring to the same pin
  pinMode(D4, OUTPUT); // NOTE, must have the D or it will be referenced to the Arduino 4 pin (GPIO4 AKA D2) confused yet?
  pinMode(2, OUTPUT);  // NOTE also called GPIO2
}

void loop()
{
  // Turn ON and OFF the same pin - which is the built in LED on a Wemos D1/D1 Mini board
  digitalWrite(2, LOW); // 2 being the GPIO/Arduino designated pin number
  delay(500);
  digitalWrite(D4, HIGH); // D4 being the silkscreened Wemos designated pin number
  delay(500);
}

But as a rule here… always best to use the GPIO designated numbers (referenced with most ESPs as the full GIOx and just as x on the Arduino) as they generally work in the IDE for programming the differing types of boards (Arduino and ESP).

A post was merged into an existing topic: Basic physical LED Control via Blynk