Created
July 5, 2025 17:07
-
-
Save maxpromer/19b48daa94ce955393316b708c9e2f79 to your computer and use it in GitHub Desktop.
Example code for AS-Energy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MCM_BL0940.h" | |
BL0940 bl0940; | |
void setup() { | |
Serial.begin(115200); | |
bl0940.begin(Serial1, 25, 26); // RX, TX pin | |
bl0940.Reset(); | |
bl0940.setFrequency(50); // 50[Hz] | |
bl0940.setUpdateRate(800); // 400[ms] | |
} | |
void loop() { | |
float voltage; | |
bl0940.getVoltage( &voltage ); | |
Serial.printf("%.2f [V]\n", voltage ); | |
float current; | |
bl0940.getCurrent( ¤t ); | |
Serial.printf("%.4f [A]\n", current ); | |
float activePower; | |
bl0940.getActivePower( &activePower ); | |
Serial.printf("%.2f [W]\n", activePower ); | |
float activeEnergy; | |
bl0940.getActiveEnergy( &activeEnergy ); | |
Serial.printf("%.6f [kWh]\n", activeEnergy ); | |
float powerFactor; | |
bl0940.getPowerFactor( &powerFactor ); | |
Serial.printf("%.1f [%%]\n", powerFactor ); | |
float temperature; | |
bl0940.getTemperature( &temperature ); | |
Serial.printf("%.1f [deg C]\n", temperature ); | |
Serial.println(""); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment