Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
INA219 WE pico port
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Joris Holm
INA219 WE pico port
Commits
90b7b9af
Unverified
Commit
90b7b9af
authored
2 years ago
by
Wolfgang (Wolle) Ewald
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add files via upload
parent
68c66348
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/INA219_WE.cpp
+31
-1
31 additions, 1 deletion
src/INA219_WE.cpp
src/INA219_WE.h
+11
-1
11 additions, 1 deletion
src/INA219_WE.h
src/ina219_config.h
+5
-0
5 additions, 0 deletions
src/ina219_config.h
with
47 additions
and
2 deletions
src/INA219_WE.cpp
+
31
−
1
View file @
90b7b9af
...
...
@@ -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
This diff is collapsed.
Click to expand it.
src/INA219_WE.h
+
11
−
1
View file @
90b7b9af
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
src/ina219_config.h
0 → 100644
+
5
−
0
View file @
90b7b9af
#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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment