Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
energy-monitor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
suazo2
energy-monitor
Merge requests
!2
Board voltage
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Board voltage
board-voltage
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
suazo2
requested to merge
board-voltage
into
main
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Created by: afesuazo
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
3212624a
1 commit,
1 year ago
1 file
+
11
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
energy_monitor.py
+
11
−
0
Options
@@ -55,6 +55,17 @@ class EnergyMonitor:
f
"
If you
'
re not sure where or how the other power monitor session is running, you can kill it with the following command: kill -9
{
pid
}
"
)
self
.
cleanup
()
def
get_board_voltage
(
self
):
"""
Take 10 sample readings and return the average board voltage from the +3.3V rail.
"""
samples
=
[]
while
len
(
samples
)
<=
10
:
data
=
self
.
read_adc
(
4
)
# channel 4 is the 3.3V ref voltage
samples
.
append
(
data
)
avg_reading
=
sum
(
samples
)
/
len
(
samples
)
board_voltage
=
(
avg_reading
/
1024
)
*
3.31
*
2
return
board_voltage
def
read_adc
(
self
,
adc_num
):
"""
Read SPI data from the MCP3008, 8 channels in total.
"""
r
=
self
.
spi
.
xfer2
([
1
,
8
+
adc_num
<<
4
,
0
])
Loading