jak zrobić loop jakiejś funkcji jak dodanie tego do void loop() powoduje crashe ? (kilka odczytów i wysypuje sie esp, restart). Coś, gdzieś mi się przewinęło, że w supli nie powinno się używać loopa modyfikuje kod Primary GUI v2 jeśli to ma znaczenie.
Kod, który chce wkleic w kod to:
Kod: Zaznacz cały
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void setup(void)
{
Serial.begin(115200);
while (!Serial) {
// will pause Zero, Leonardo, etc until serial console opens
delay(1);
}
uint32_t currentFrequency;
Serial.println("Hello!");
// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
ina219.begin();
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
//ina219.setCalibration_16V_400mA();
Serial.println("Measuring voltage and current with INA219 ...");
}
void loop(void)
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);
Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW");
Serial.println("");
delay(2000);
}
Kod: Zaznacz cały
Zainicjowany
Uruchamianie serwera...
Rozłączony
Connection fail. Server: svr10.supla.org
Bus Voltage: 4.98 V
Shunt Voltage: 3.97 mV
Load Voltage: 4.99 V
Current: 31.10 mA
Power: 160.00 mW
Bus Voltage: 4.98 V
Shunt Voltage: 4.11 mV
Load Voltage: 4.98 V
Current: 25.80 mA
Power: 150.00 mW
Bus Voltage: 4.98 V
Shunt Voltage: 4.01 mV
Load Voltage: 4.99 V
Current: 36.90 mA
Power: 210.00 mW
WiFi connected SSID:
Exception (9):
epc1=0x40105708 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000003 depc=0x00000000
>>>stack>>>
ctx: sys
sp: 3fffece0 end: 3fffffb0 offset: 01a0
3fffee80: 40105934 0043ccf1 3fff216c 00000000
3fffee90: 3fff04a0 3fff216c 00000400 402206be
3fffeea0: 00000000 004352df 40214c64 00000064
3fffeeb0: 3fff216c 3fff1184 3fff0658 4020b38d
(...)
<<<stack<<<