To use an existing library for driving the ATM90E26 energy metering IC, you can use the ATM90E26_Arduino library. Here's an example Arduino program that demonstrates the basic usage of this library:
cpp
#include <SPI.h>
#include "ATM90E26.h"
// Create an ATM90E26 object
ATM90E26 energyMeter;
// Define the SPI pins
#define CSPIN 10 // Chip Select pin
#define VOLT_PIN A0 // Voltage measurement pin
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize the ATM90E26
energyMeter.begin(CSPIN);
// Perform a soft reset
energyMeter.softReset();
// Calibrate the metering IC
energyMeter.calibrate();
// Set line calibration
energyMeter.linecalibration(1540, 24576);
// Configure the measurement mode
energyMeter.setMode(MEASURE_MODE_ACTIVE);
// Set the voltage range
energyMeter.setVoltageRange(0x0000);
// Set the current range
energyMeter.setCurrentRange(0x1FFE);
// Set the frequency range
energyMeter.setFrequencyRange(0x0000);
// Set the power factor range
energyMeter.setPowerFactorRange(0x199A);
// Display the system status
Serial.println("ATM90E26 initialized.");
}
void loop() {
// Read voltage, current, active power, and other parameters
float voltage = energyMeter.GetLineVoltage();
float current = energyMeter.GetLineCurrent();
float activePower = energyMeter.GetActivePower();
float reactivePower = energyMeter.GetReactivePower();
float apparentPower = energyMeter.GetApparentPower();
float powerFactor = energyMeter.GetPowerFactor();
float frequency = energyMeter.GetFrequency();
// Print the values to the serial monitor
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.println(" V");
Serial.print("Current: ");
Serial.print(current);
Serial.println(" A");
Serial.print("Active Power: ");
Serial.print(activePower);
Serial.println(" W");
Serial.print("Reactive Power: ");
Serial.print(reactivePower);
Serial.println(" VAR");
Serial.print("Apparent Power: ");
Serial.print(apparentPower);
Serial.println(" VA");
Serial.print("Power Factor: ");
Serial.println(powerFactor);
Serial.print("Frequency: ");
Serial.print(frequency);
Serial.println(" Hz");
// Wait for 2 seconds before updating the values
delay(2000);
}
To use this program, you'll need to install the ATM90E26_Arduino library in your Arduino IDE. You can download it from the following link: https://github.com/whatnick/ATM90E26_Arduino
After installing the library, you can upload the program to your Arduino board and start monitoring the energy parameters. Make sure to connect the ATM90E26 to your Arduino board as per the library instructions.