Skip to main content

PL7223

Latest Version: 1.0.0

This library provides a driver for the PL7223 Power Sensing Chip. It is based on a datasheet released under NDA (non-disclosure agreement). As such, we cannot open-source the driver class, however we can make it available through Electric Imp’s library management system.

To add this library to your project, add #require "PL7223.class.nut:1.0.0 to the top of your device code

Class Usage

Constructor: PL7223(spiBus, resetPin, chipSelectPin)

To instantiate a new PL7223 object, you must pass it three parameters: a pre-configured SPI bus, and the imp pins connected to the PL7223’s reset and chip-select lines:

#require "PL7223.class.nut:1.0.0"

// Configure Power Monitoring:
spi <- hardware.spi257;
spi.configure(CLOCK_IDLE_LOW, 100);
power <- PL7223(spi, hardware.pinB, hardware.pin8);

Class Methods

sample([callback])

The sample() method takes a reading and returns the Voltage (Volts), Current (Amps) and Power (Watts).

An optional callback may be passed into the method. It takes a single parameter: a table into which the readings are placed as values of the keys voltage, current and power. If a callback is not supplied, a table with the same three keys will be returned.

// No callback
local powerData = power.sample();
server.log("Voltage: " + powerData.voltage + "V");
server.log("Current: " + powerData.current + "A");
server.log("Power: " + powerData.power + "W");

// With a callback:
power.sample(function(powerData) {
    server.log("Voltage: " + powerData.voltage + "V");
    server.log("Current: " + powerData.current + "A");
    server.log("Power: " + powerData.power + "W");
});

License

The example code in this library is licensed under the MIT License.