Esp8266-01 pwm inverted from slider wiget

So I have what seems like a simple project with an Esp8266-01 connected via wifi, using sliders to control individual colors of an RGB led strip (driven by transistors). I’ve done the project in the past, but have lost the code, so I’m redoing everything. I just can’t remember running into my current problem.

BLYNK_WRITE(V1)
{
int redValue = param.asInt();
analogWrite (redPin, redValue) ;
} 

The variable redPin has been assigned to a pin elsewhere in the sketch. I am only able to post part of the sketch for now, until I have access to my laptop to copy paste the full thing. That should be irrelevant for now.
In the app, the slider is given a range of 0-1023 and assigned to V1. When uploaded to the esp and tested using a multimeter, I get 3.3v when the slider is set to 0 and 0v when set to 1023. I can’t find any reason why or where the signal is being inverted.
I’ve added serial to the sketch and displayed V1 (redValue) to confirm the appropriate value is being sent. So essentially what I have is:

analogWrite (redPin, 0);

giving me 3.3v on the pin and:

analogWrite (redPin, 1023);

giving me 0v on the pin…plus everything in between at intermediate values.

I know I could make the slider values inverted by changing from 0-1023 to 1023-0, but that messes with my zeRGBa that’s tied to the sliders.
Also, I realize I could probably easily remap the values in the sketch itself with

map(redValue,0,1023,1023,0);

but I’d rather know the why to what’s causeing the inversion in the first place.

Any help is much appreciated.

Do you really mean an ESP-01, or are you using a NodeMCU or similar?
If you are using an ESP-01 then can you clarify which pins you’re using. In fact, it would be useful to know what pin you’re usi g for redPin anyway

Can you confirm that the voltage reading you are seeing are measured directly at the pins, without any additional hardware such as the transistors attached?

Pete.

Thanks for the quick reply, Pete.

I do mean the simple 8 pin esp-01. Voltage was checked directly at the pin through the full range. Red is on pin 3 (RX), Green is pin 2, and Blue is pin 0. When I tried adding serial to the sketch, I tested the green pin. It’s the same setup I’ve used in the past.

Okay, I’ll wait to see your full sketch

Pete.

It really isn’t anything significant. Like I said, that part I feel like is irrelevant, but I suppose that’s why I’m here asking for help. I’ll be adding more to the sketch later for some additions like random fade, but for now:

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxx";

void setup()
{
  // Debug console
  Serial.begin(9600);

int redPin = 3;
int greenPin = 2;
int bluePin = 0;

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
}


BLYNK_WRITE(V1)
{
int redValue = param.asInt();
analogWrite (redPin, redValue);
} 

BLYNK_WRITE(V2)
{
int greenValue = param.asInt();
analogWrite (greenPin, greenValue);
} 

BLYNK_WRITE(V3)
{
int blueValue = param.asInt();
analogWrite (bluePin, blueValue);
} 

I also tried:

BLYNK_WRITE(V2)
{
int greenValue = param.asInt();
analogWrite (greenPin, greenValue);
int green = analogRead (greenPin) ;
Serial.print("Green Value:  ") ;
Serial.println(green);
} 

which gave me what seemed like random values that bounced around 60-70 regardless of slider position…possibly my own misunderstanding of something. Even so, like mentioned before, the meter reading directly at the pin showed correctly, just inverted. And if I put:

BLYNK_WRITE(V2)
{
int greenValue = param.asInt();
analogWrite (greenPin, greenValue);
Serial.print("Green Value:  ") ;
Serial.println(greenValue);
} 

then it printed out the correct reading from the slider as set at the moment (0-1023). So it seems like it’s being inverted somewhere between line 1 and line 2 of the BLYNK_WRITE functions…again, possibly my own misunderstanding. I can make a video when able and post the link if that will help to show a little better of what is actually going on. I was hoping it was going to be an easy catch by you guys though, so now I’m back to a little discouraged.

I’d take out the Serial.begin and BLYNK_PRINT Serial lines if I were you.

Pete.

After all that brain racking, on my way home from work it dawned on me that it was nothing more than a rookie mistake. I was measuring at the pin with the positive lead on 3.3v and ground lead at the pin… instead of positive lead on pin and negative to ground.

Sorry for all the headache, but part of it was to let me write it all down and run it by someone else to help me lay things out a little better in my head…and hey, it’s fixed and my mind can rest. So thanks!

Problem solved (or apparent problem)

image