Hello, I’m making an AC current measuring and sending device.
but I have encountered some problems.
Details :
• NodeMCU(V3), ADS1115, SCT-013(CT Sensor 20A/1V)
• Blynk Library version : 1.1.0
First of all, the codes below work well in Arduino UNO and NodeMCU. I can read the currentRMS value.
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;
const float FACTOR = 20; //20A/1V from teh CT
const float multiplier = 0.00005;
void setup() {
Wire.begin();
Serial.begin(9600);
ads.setGain(GAIN_FOUR); // +/- 1.024V 1bit = 0.5mV
ads.begin();
}
void printMeasure(String prefix, float value, String postfix)
{
Serial.print(prefix);
Serial.print(value, 3);
Serial.println(postfix);
}
void loop() {
float currentRMS = getcurrent();
printMeasure("Irms: ", currentRMS, "A");
delay(1000);
}
float getcurrent()
{
float voltage;
float current;
float sum = 0;
long time_check = millis();
int counter = 0;
while (millis() - time_check < 1000)
{
voltage = ads.readADC_Differential_0_1() * multiplier;
current = voltage * FACTOR;
//current /= 1000.0;
sum += sq(current);
counter = counter + 1;
}
current = sqrt(sum / counter);
return (current);
}
So, I modified the code above into “Blynk style”.
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;
BlynkTimer timer;
const float FACTOR = 20; //20A/1V from teh CT
const float multiplier = 0.00005;
float getcurrent()
{
float voltage;
float current;
float sum = 0;
long time_check = millis();
int counter = 0;
while (millis() - time_check < 1000)
{
voltage = ads.readADC_Differential_0_1() * multiplier;
current = voltage * FACTOR;
//current /= 1000.0;
sum += sq(current);
counter = counter + 1;
}
current = sqrt(sum / counter);
return (current);
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V7);
}
void sendSensor()
{
float currentRMS = getcurrent();
printMeasure("Irms: ", currentRMS, "A");
Blynk.virtualWrite(V7, currentRMS);
//delay(1000);
}
void setup()
{
Wire.begin();
Serial.begin(9600);
ads.setGain(GAIN_FOUR); // +/- 1.024V 1bit = 0.5mV
ads.begin();
BlynkEdgent.begin();
timer.setInterval(1000L, sendSensor);
}
void printMeasure(String prefix, float value, String postfix)
{
Serial.print(prefix);
Serial.print(value, 3);
Serial.println(postfix);
}
void loop()
{
BlynkEdgent.run();
timer.run();
}
And I uploaded the code, but It didn’t work.
Serial monitor showed me Soft WDT reset.
⸮⸮b⸮LB⸮!⸮⸮⸮[288]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.1.0 on ESP8266
#StandWithUkraine https://bit.ly/swua
[359] --------------------------
[394] Product: CTwithADS1115
[427] Firmware: 0.1.0 (build Aug 11 2023 10:59:15)
[481] Token: •••• - •••• - •••• - ••••
[551] Device: ESP8266 @ 80MHz
[585] MAC: 8C:AA:B5:D4:93:75
[621] Flash: 4096K
[645] ESP core: 3.0.2
[669] ESP SDK: 2.2.2-dev(38a443e)
[707] Boot Ver: 31
[728] Boot Mode:1
[748] FW info: 474656/1622016, MD5:60689752c8201e075b82b21a94a62fef
[962] Free mem: 29616
[962] --------------------------
>[962] INIT => CONNECTING_NET
[989] Connecting to WiFi: Zeteo
[5127] Using Dynamic IP: 192.168.0.65
[5127] CONNECTING_NET => CONNECTING_CLOUD
Irms: 1.748A
[6246] Current time: Fri Aug 11 02:09:37 2023
[6246] Connecting to blynk.cloud:443
[8435] Ready (ping: 11ms).
[8968] CONNECTING_CLOUD => RUNNING
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffc60 end: 3fffffc0 offset: 01a0
3ffffe00: 3fff0fc0 00000001 3fff0fc0 40212f72
3ffffe10: 60000314 00000100 00000000 4021302f
3ffffe20: 00000002 3fff0d2e 3fff0fc0 40213115
3ffffe30: 00000048 3fff0fc0 00000001 3fff0cac
3ffffe40: 60000314 00000001 3fff0fc0 00000002
3ffffe50: 3fff1e44 3fff01fa 00000002 40213330
3ffffe60: 00000001 00000048 3fffff20 4020deec
3ffffe70: 4020ec01 3ffffecc 00000000 4020df20
3ffffe80: 00000000 00000001 3fff0ca9 4020e264
3ffffe90: 00000008 3ffffecc 3fffff58 3fff1e44
3ffffea0: 00000002 00000002 00000000 4020e2e0
3ffffeb0: 3fff01fa 00000001 00000001 00000000
3ffffec0: 00000000 00000000 4bc6a7f0 000003e7
3ffffed0: 00002309 3fff01fa 3fff01ec 4020e0a0
3ffffee0: 00002309 00000001 3fff01ec 4020e0c8
3ffffef0: 000006c2 00000001 3fff01ec 4020e12f
3fffff00: 00002309 00000000 00000000 402028c1
3fffff10: 00000000 00000000 4bc6a7f0 00000010
3fffff20: 00000000 3ffefeac 3ffefea8 40204036
3fffff30: 00002309 3ffe8650 00000004 40202349
3fffff40: 00000000 001b001f 00000000 3fff0f74
3fffff50: 3fffdad0 00000000 3ffefea8 402156b2
3fffff60: 00000000 4020a6c0 3fff0bdc 40208f2f
3fffff70: 00002309 0000137c 000007d0 40204770
3fffff80: 3fffdad0 00000000 3fff0f60 3fff0f74
3fffff90: 3fffdad0 00000000 3fff0f60 40208d56
3fffffa0: 3fffdad0 00000000 3fff0f60 40212500
3fffffb0: feefeffe feefeffe 3ffe8690 40101151
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
⸮Q)⸮⸮⸮@⸮1⸮H&A[288]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.1.0 on ESP8266
#StandWithUkraine https://bit.ly/swua
[359] --------------------------
[395] Product: CTwithADS1115
[427] Firmware: 0.1.0 (build Aug 11 2023 10:59:15)
[481] Token: •••• - •••• - •••• - ••••
[551] Device: ESP8266 @ 80MHz
[585] MAC: 8C:AA:B5:D4:93:75
[622] Flash: 4096K
[646] ESP core: 3.0.2
[670] ESP SDK: 2.2.2-dev(38a443e)
[707] Boot Ver: 31
[728] Boot Mode:1
[748] FW info: 474656/1622016, MD5:60689752c8201e075b82b21a94a62fef
[962] Free mem: 29616
[962] --------------------------
>[962] INIT => CONNECTING_NET
[989] Connecting to WiFi: Zeteo
[5147] Using Dynamic IP: 192.168.0.65
[5147] CONNECTING_NET => CONNECTING_CLOUD
Irms: 1.724A
[6267] Current time: Fri Aug 11 02:09:50 2023
[6267] Connecting to blynk.cloud:443
[8466] Ready (ping: 12ms).
[9004] CONNECTING_CLOUD => RUNNING
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffc90 end: 3fffffc0 offset: 01a0
3ffffe30: 00000002 3fff0fc0 00000001 3fff0cac
3ffffe40: 60000314 00000001 00000007 00000002
3ffffe50: 3fff0fc0 3fff0cab 00000004 402131d6
3ffffe60: 00000001 00000048 3fffff20 4020deec
3ffffe70: 4020ec01 3ffffecc 00000000 3fff01fa
3ffffe80: 00000000 00000001 3fff0ca9 40213310
3ffffe90: 00000009 3ffffecc 3fffff58 4020df6c
3ffffea0: 00000000 00000001 3fff1e44 4020e224
3ffffeb0: 00000001 00000000 00000001 00000000
3ffffec0: 00000000 00000000 4bc6a7f0 000003e7
3ffffed0: 0000232d 3fff01fa 3fff01ec 4020e095
3ffffee0: 0000232d 00000001 3fff01ec 4020e0c8
3ffffef0: 000006c2 00000001 3fff01ec 4020e12f
3fffff00: 0000232d 00000000 00000000 402028c1
3fffff10: 00000000 00000000 4bc6a7f0 00000010
3fffff20: 00000000 3ffefeac 3ffefea8 40204036
3fffff30: 0000232d 3ffe8650 00000004 40202349
3fffff40: 00000000 001b001f 00000000 3fff0f74
3fffff50: 3fffdad0 00000000 3ffefea8 402156b2
3fffff60: 00000000 4020a6c0 3fff0bdc 40208f2f
3fffff70: 0000232d 0000137c 000007d0 40204770
3fffff80: 3fffdad0 00000000 3fff0f60 3fff0f74
3fffff90: 3fffdad0 00000000 3fff0f60 40208d56
3fffffa0: 3fffdad0 00000000 3fff0f60 40212500
3fffffb0: feefeffe feefeffe 3ffe8690 40101151
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
⸮⸮)⸮LC⸮⸮⸮![289]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.1.0 on ESP8266
#StandWithUkraine https://bit.ly/swua
[360] --------------------------
[396] Product: CTwithADS1115
[428] Firmware: 0.1.0 (build Aug 11 2023 10:59:15)
[482] Token: •••• - •••• - •••• - ••••
[552] Device: ESP8266 @ 80MHz
[586] MAC: 8C:AA:B5:D4:93:75
[623] Flash: 4096K
[647] ESP core: 3.0.2
[671] ESP SDK: 2.2.2-dev(38a443e)
[708] Boot Ver: 31
[729] Boot Mode:1
[749] FW info: 474656/1622016, MD5:60689752c8201e075b82b21a94a62fef
[963] Free mem: 29616
[963] --------------------------
>[963] INIT => CONNECTING_NET
[990] Connecting to WiFi: Zeteo
[12901] Using Dynamic IP: 192.168.0.65
[12901] CONNECTING_NET => CONNECTING_CLOUD
Irms: 1.701A
[14020] Current time: Fri Aug 11 02:10:10 2023
[14020] Connecting to blynk.cloud:443
[16216] Ready (ping: 11ms).
[16753] CONNECTING_CLOUD => RUNNING
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffca0 end: 3fffffc0 offset: 01a0
3ffffe40: 60000314 00000001 3fff0fc0 40212ee1
3ffffe50: 3fff0fc0 3fff0cab 00000002 402131fb
3ffffe60: 00000001 00000048 3fffff20 4020deec
3ffffe70: 4020ec01 3ffffecb 00000000 3fff01fa
3ffffe80: 00000000 00000001 3fff0ca9 40213310
3ffffe90: 00000001 3ffffecb 3fffff58 4020df6c
3ffffea0: 00000000 00000001 3fff1e44 4020e224
3ffffeb0: 00000001 00000000 00000001 00000000
3ffffec0: 00000000 00000000 4bc6a7f0 000003e7
3ffffed0: 00004171 3fff01fa 3fff01ec 4020e095
3ffffee0: 00004171 00000001 3fff01ec 4020e0c8
3ffffef0: 0000033d 00000001 3fff01ec 4020e12f
3fffff00: 00004171 00000000 00000000 402028c1
3fffff10: 00000000 00000000 4bc6a7f0 00000010
3fffff20: 00000000 3ffefeac 3ffefea8 40204036
3fffff30: 00004171 3ffe8650 00000004 40202349
3fffff40: 00000000 001b001f 00000000 3fff0f74
3fffff50: 3fffdad0 00000000 3ffefea8 402156b2
3fffff60: 00000000 4020a6c0 3fff0bdc 40208f2f
3fffff70: 00004171 00002aed 000007d0 40204770
3fffff80: 3fffdad0 00000000 3fff0f60 3fff0f74
3fffff90: 3fffdad0 00000000 3fff0f60 40208d56
3fffffa0: 3fffdad0 00000000 3fff0f60 40212500
3fffffb0: feefeffe feefeffe 3ffe8690 40101151
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Since this soft WDT reset, I changed the code.
I turned the watch dog off. but It didn’t work correctly.
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include "BlynkEdgent.h"
// Fill-in information from your Blynk Template here
Adafruit_ADS1115 ads;
const float FACTOR = 20; //20A/1V from teh CT
const float multiplier = 0.00005;
void setup() {
Wire.begin();
Serial.begin(9600);
ads.setGain(GAIN_FOUR); // +/- 1.024V 1bit = 0.5mV
ads.begin();
ESP.wdtDisable();
*((volatile uint32_t*) 0x60000900) &= ~(1);
Wire.begin();
BlynkEdgent.begin();
delay(5000);
}
float getcurrent()
{
double voltage;
double current;
double sum = 0;
long time_check = millis();
int counter = 0;
// printf("1_1, ");
while (millis() - time_check < 1000)
{
voltage = ads.readADC_Differential_0_1() * multiplier;
current = voltage * FACTOR;
//current /= 1000.0;
sum += sq(current);
counter = counter + 1;
}
// printf("1_2, ");
current = sqrt(sum / counter);
// printf("1_3, ");
return (current);
}
void printMeasure(String prefix, float value, String postfix)
{
Serial.print(prefix);
Serial.print(value, 3);
Serial.println(postfix);
}
void loop() {
double currentRMS = getcurrent();
printMeasure("Irms: ", currentRMS, "A");
delay(500);
BlynkEdgent.run();
Blynk.virtualWrite(V7, currentRMS);
//delay(500);
}
This was the messages from serial monitor of new codes.
Even I didn’t connect SCT-013 current sensor, incorrect Irms values were displayed. (8.297A, 0.127A, 0.234A like that)
When Irms value reached 0.255A, system was stuck.
A few minutes later, watchdog reset the system even though I turned the watchdog off.
something noticeable point is…
- At first, the correct Irms value was displayed. (twice?) (0.000A)
- and then, suddenly the value rises. (8.297A)
- finally, the value converges to 0.255A.
⸮Hpʸ⸮⸮LM⸮x>⸮⸮4⸮⸮)4[289]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.1.0 on ESP8266
#StandWithUkraine https://bit.ly/swua
[360] --------------------------
[395] Product: CTwithADS1115
[428] Firmware: 0.1.0 (build Aug 11 2023 16:55:16)
[482] Token: ueQA - •••• - •••• - ••••
[552] Device: ESP8266 @ 80MHz
[586] MAC: 8C:AA:B5:D4:93:75
[622] Flash: 4096K
[646] ESP core: 3.0.2
[670] ESP SDK: 2.2.2-dev(38a443e)
[708] Boot Ver: 31
[729] Boot Mode:1
[748] FW info: 474784/1622016, MD5:d0619ffac673bd913dc220dc67d7f42d
[963] Free mem: 30448
[963] --------------------------
>[963] INIT => CONNECTING_NET
Irms: 0.000A
[7491] Connecting to WiFi: Zeteo
[11608] Using Dynamic IP: 192.168.0.65
[11608] CONNECTING_NET => CONNECTING_CLOUD
Irms: 0.000A
[13226] Current time: Fri Aug 11 07:56:35 2023
[13226] Connecting to blynk.cloud:443
[15490] Ready (ping: 12ms).
[15774] CONNECTING_CLOUD => RUNNING
Irms: 8.297A
Irms: 0.127A
Irms: 0.234A
Irms: 0.149A
Irms: 2.331A
Irms: 0.244A
Irms: 0.255A
Irms: 0.255A
Irms: 0.255A
I would really appreciate it if you could give me some advice.
Thank you!