Blynk with Emon Library

Good day i am a newbie here… i am trying to create a project where a current meter(break out Board) reads current and this can be visible on Blynk App widget…

from multiple experiments it seems as though Bylnk is interfereng with the emon lib function and not producing a reading as when i do not include Blynk code it works fine and produces accurate readings…as soon as i try to include this in a Blynk sketch not even in the serial monitor am i getting readings and just getting 0 in Serial monitor…i know the program is calling the function and printing “a” (done purposely as a test) in the serial monitor but no readings are being taken …

Below is a very simple version of the sketch as even this is not working…if anyone can shed some light as to why this is happening please let me know…ps i have tried other sketches in Blynk and they work fine like taking and sending temperature readings and other sensors etc…my concern to begin with is why are no readings being taken in the serial monitor first and foremost when without the Blynk code they where (so not an issue of pins,wiring or sensor malfunction)…meanwhile i will continue to experiment but f anyone spots something i am unaware of please let me know

#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
 

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "EmonLib.h"   


EnergyMonitor emon1;                  
char ssid[] = "";
char pass[] = "";




BlynkTimer timer; 


void setup()
{ 
  Serial.begin(9600); 
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  emon1.current(13, 1.72);
  timer.setInterval(3000L, myTimer);
  
 
}

void myTimer()
{
   double Irms = emon1.calcIrms(1480);  
  
  Serial.print(Irms*230.0);	       
  Serial.print("a ");
  Serial.println(Irms);
  Blynk.virtualWrite(V5, Irms);	       
}



void loop(){

Blynk.run(); 
timer.run(); 

}

I assume that the 13 here is pin 13, which is connected to the ESP32’s ADC2 Digital to Analog converter (DAC)?

If so, that’s a problem because the ESP32’s internal; architecture doesn’t allow ADC2 to be used at the same time as WiFi.

You should use an ADC1 pin instead…

Analog to Digital Converter (ADC)

The ESP32 has 18 x 12 bits ADC input channels (while the ESP8266 only has 1x 10 bits ADC). These are the GPIOs that can be used as ADC and respective channels:

  • ADC1_CH0 (GPIO 36)
  • ADC1_CH1 (GPIO 37)
  • ADC1_CH2 (GPIO 38)
  • ADC1_CH3 (GPIO 39)
  • ADC1_CH4 (GPIO 32)
  • ADC1_CH5 (GPIO 33)
  • ADC1_CH6 (GPIO 34)
  • ADC1_CH7 (GPIO 35)
  • ADC2_CH0 (GPIO 4)
  • ADC2_CH1 (GPIO 0)
  • ADC2_CH2 (GPIO 2)
  • ADC2_CH3 (GPIO 15)
  • ADC2_CH4 (GPIO 13)
  • ADC2_CH5 (GPIO 12)
  • ADC2_CH6 (GPIO 14)
  • ADC2_CH7 (GPIO 27)
  • ADC2_CH8 (GPIO 25)
  • ADC2_CH9 (GPIO 26)

Pete.

Thanks a lot Pete! i will give it a shot and see if it works…yes the 13 refers to pin 13…i had tried it on pin 27 but i see from your diagram it is still classified as ADC2…so let me try again following your advice and get back to you

Spot on… finally solved that was it…Thanks a lot !! :partying_face:

1 Like