Skip to content
Snippets Groups Projects
Unverified Commit 90b7b9af authored by Wolfgang (Wolle) Ewald's avatar Wolfgang (Wolle) Ewald Committed by GitHub
Browse files

Add files via upload

parent 68c66348
No related branches found
No related tags found
No related merge requests found
......@@ -17,15 +17,20 @@
#include "INA219_WE.h"
INA219_WE::INA219_WE(int addr){
#ifndef USE_TINY_WIRE_M_
_wire = &Wire;
#endif
i2cAddress = addr;
}
INA219_WE::INA219_WE(){
#ifndef USE_TINY_WIRE_M_
_wire = &Wire;
#endif
i2cAddress = 0x40;
}
#ifndef USE_TINY_WIRE_M_
INA219_WE::INA219_WE(TwoWire *w, int addr){
_wire = w;
i2cAddress = addr;
......@@ -35,6 +40,7 @@ INA219_WE::INA219_WE(TwoWire *w){
_wire = w;
i2cAddress = 0x40;
}
#endif
bool INA219_WE::init(){
if( !reset_INA219() )
......@@ -230,6 +236,7 @@ void INA219_WE::powerUp(){
delayMicroseconds(40);
}
#ifndef USE_TINY_WIRE_M_
uint8_t INA219_WE::writeRegister(uint8_t reg, uint16_t val){
_wire->beginTransmission(i2cAddress);
uint8_t lVal = val & 255;
......@@ -254,6 +261,29 @@ uint16_t INA219_WE::readRegister(uint8_t reg){
regValue = (MSByte<<8) + LSByte;
return regValue;
}
#else
uint8_t INA219_WE::writeRegister(uint8_t reg, uint16_t val){
TinyWireM.beginTransmission(i2cAddress);
uint8_t lVal = val & 255;
uint8_t hVal = val >> 8;
TinyWireM.send(reg);
TinyWireM.send(hVal);
TinyWireM.send(lVal);
return TinyWireM.endTransmission();
}
uint16_t INA219_WE::readRegister(uint8_t reg){
uint8_t MSByte = 0, LSByte = 0;
uint16_t regValue = 0;
TinyWireM.beginTransmission(i2cAddress);
TinyWireM.send(reg);
TinyWireM.endTransmission();
TinyWireM.requestFrom(i2cAddress,2);
MSByte = TinyWireM.receive();
LSByte = TinyWireM.receive();
regValue = (MSByte<<8) + LSByte;
return regValue;
}
#endif
......@@ -24,8 +24,14 @@
#else
#include "WProgram.h"
#endif
#include "ina219_config.h"
#include <Wire.h>
#ifdef USE_TINY_WIRE_M_
#include <TinyWireM.h>
#endif
#ifndef USE_TINY_WIRE_M_
#include <Wire.h>
#endif
/* registers */
#define INA219_ADDRESS 0x40
......@@ -80,8 +86,10 @@ public:
// Constructors: if not passed 0x40 / Wire will be set as address / wire object
INA219_WE(int addr);
INA219_WE();
#ifndef USE_TINY_WIRE_M_
INA219_WE(TwoWire *w, int addr);
INA219_WE(TwoWire *w);
#endif
bool init();
bool reset_INA219();
......@@ -109,7 +117,9 @@ private:
INA219_MEASURE_MODE deviceMeasureMode;
INA219_PGAIN devicePGain;
INA219_BUS_RANGE deviceBusRange;
#ifndef USE_TINY_WIRE_M_
TwoWire *_wire;
#endif
int i2cAddress;
uint16_t calVal;
uint16_t calValCorrected;
......
#ifndef INA219_CONFIG_H_
#define INA219_CONFIG_H_
/* Uncomment the following line to use TinyWireM instead of Wire */
//#define USE_TINY_WIRE_M_
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment