I’m just running tests with Blynk - I have bluetooth working and can switch LEDs on and off etc
The next step was to read a voltage on GPIO 2 -
The problem I’ve got is that the result of the code below is always 4095 output. It seems that the analogue read always returns 4095
If I comment out the lines Blynk.begin and Blynk.run I get the output I expect.
I obviously don’t understand something - I need the anaolgue pin value in my code for control later but when Blynk is running I don’t appear to be able to get any value other than 4095
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <BlynkSimpleEsp32_BT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "........riqfV";
WidgetLCD lcd(V1);
const int TPin = 2;
int TempReading = 0;
void setup()
{
// Debug console
Serial.begin(115200);
Serial.println("Waiting for connections...");
Blynk.setDeviceName("HotTub");
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
TempReading = analogRead(TPin);
Serial.println(TempReading);
delay(500);
}
Adding a pinMode statement go your void setup for your TPin would be a good move, but you also need to sort out your void loop and use a timer to call the code that reads your TPin…
Yes I’ll progress to the timer later, I’m still trying to understand how that works.
For now I just want to prove I can get the read working. I’ve looked at setting the pin but this not in any of the examples I’ve found. Can you provide me with a setpin example?
@Mslater please edit your post and replace the characters you’ve used at the beginning and end of your code with the correct ones - as you did in your earlier post.
I’m not sure why this is happening when Blynk is enabled but not when it isn’t.
However, the solution is probably to use a voltage divider to reduce the voltage to the pin.
GPIO 2 may not be the best pin top use, as it’s usually where the onboard LED is connected.
I assume that your app doesn’t have any widgets attached to D2, and that you’ve selected ESP32 as your device type in the app?
I’m.not even running the App at this stage. It appears that enabling blink the Gpio is compromised. I’ve tried all analog pins. They all work without blink enabled.
There’s no point in connecting the device unless I can get the inpouts working in code.
Originally this was a much bigger sketch with lots of switches and LCD output. I;ve stripped it right back to solve this problem. To be honest I’d almost finished the sketch and just had some calculations to do for PID switching of the Heaters when I discovered this problem.
It seems that every piece of advice I give is regarded as irrelevant or unnecessary for your project at this stage in the development process, so as you clearly know more about it than me I’ll leave you to work this out for yourself.