Skip to content

Modulino ampere #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/Modulino_Ampere/Basic/Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "Modulino.h"

ModulinoAmpere ampere;

void setup() {
Serial.begin(9600);
Modulino.begin();
ampere.begin();
}

void loop() {
if (ampere.available()) {
Serial.print("Voltage: ");
Serial.print(ampere.getVoltage(), 3);
Serial.print(" V ");

Serial.print(" Current: ");
Serial.print(ampere.getCurrent()*1000, 3);
Serial.print(" mA ");

Serial.print("Power: ");
Serial.print(ampere.getPower(), 8);
Serial.print(" W\n");
}
delay(500);
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ category=Communication
url=https://github.com/arduino-libraries/Modulino
architectures=*
includes=Modulino.h
depends=STM32duino VL53L4CD,STM32duino VL53L4ED,Arduino_LSM6DSOX,Arduino_LPS22HB,Arduino_HS300x
depends=STM32duino VL53L4CD,STM32duino VL53L4ED,Arduino_LSM6DSOX,Arduino_LPS22HB,Arduino_HS300x,Arduino_ISL28022
64 changes: 64 additions & 0 deletions src/Modulino.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Arduino_LSM6DSOX.h"
#include <Arduino_LPS22HB.h>
#include <Arduino_HS300x.h>
#include <Arduino_ISL28022.h>
//#include <SE05X.h> // need to provide a way to change Wire object

#ifndef ARDUINO_API_VERSION
Expand Down Expand Up @@ -48,6 +49,7 @@ class Module : public Printable {
public:
Module(uint8_t address = 0xFF, char* name = "")
: address(address), name(name) {}
virtual ~Module() {}
bool begin() {
if (address == 0xFF) {
address = discover() / 2; // divide by 2 to match address in fw main.c
Expand Down Expand Up @@ -504,4 +506,66 @@ class ModulinoDistance : public Module {
//VL53L4ED_ResultsData_t results;
float internal = NAN;
_distance_api* api = nullptr;
};

#define M_AMPERE_SHUNT_R 0.1 //100 mohm
#define M_AMPERE_ADDRESS 0x40 //A0 and A1 to GND

class ModulinoAmpere : public Module {
public:
ModulinoAmpere() : Module(0xFF,"AMPERE"),
_sensor(nullptr), initialized(false), isAvailable(false) {
}
~ModulinoAmpere() {
if(_sensor != nullptr) {
delete _sensor;
_sensor = nullptr;
}
}

void begin(float shunt_res_ohm, uint8_t address = M_AMPERE_ADDRESS) {
if (_sensor == nullptr) {
_sensor = new ISL28022Class(shunt_res_ohm,
*((TwoWire*)getWire()),
address);
}
if(_sensor != nullptr) {
initialized = _sensor->begin();
if(*_sensor) {
isAvailable = true;
}
}
__increaseI2CPriority();
}

void begin() {
begin(M_AMPERE_SHUNT_R,M_AMPERE_ADDRESS);
}
/* get voltage in Volts*/
float getVoltage() {
if(initialized) {
bool ovf = false;
return _sensor->getBusVoltage(ovf); }
return 0.0;
}
/* get current in Ampere */
float getCurrent() {
if(initialized) { return _sensor->getCurrent(); }
return 0.0;
}
/* get power in Watts*/
float getPower() {
if(initialized) { return _sensor->getPower(); }
return 0.0;
}

/* sensor is configured and present */
bool available() {
return isAvailable;
}

private:
ISL28022Class *_sensor;
bool initialized;
bool isAvailable;
};
Loading