Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 2.57 KB

EmonLib.md

File metadata and controls

56 lines (37 loc) · 2.57 KB

Basic NUCLEO-F303RE energy monitor using an EmonTxShield & EmonLib discreet sampling STM32Duino library

EmonLib.png

Original forum thread: https://community.openenergymonitor.org/t/stm32-development/6815/4

You will need:

1) Remove the 5v pin from the EmonTxShield and put a solder jumper across from 3.3v to 5v:

shieldmod.JPG

2) Download EmonLib

Clone EmonLib into your Arduino libraries folder using git (or download from here).

git clone https://github.com/openenergymonitor/EmonLib.git

3) Change to STM32 branch

cd EmonLib
git checkout STM32

4) Open EmonLib example: File > Examples > EmonLib > voltage_and_current

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
#include "EmonLib.h"             // Include Emon Library
EnergyMonitor emon1;             // Create an instance

void setup()
{  
  Serial.begin(9600);
  
  emon1.voltage(PA_0, 268.97, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(PA_1, 60.606);       // Current: input pin, calibration.
}

void loop()
{
  emon1.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
  emon1.serialprint();           // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
  
  float realPower       = emon1.realPower;        //extract Real Power into variable
  float apparentPower   = emon1.apparentPower;    //extract Apparent Power into variable
  float powerFActor     = emon1.powerFactor;      //extract Power Factor into Variable
  float supplyVoltage   = emon1.Vrms;             //extract Vrms into Variable
  float Irms            = emon1.Irms;             //extract Irms into Variable
}

Compile and Upload.

Connect up an ACAC Voltage adaptor and CT sensor. Monitor the output using the Arduino serial monitor.