Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NodeManager_BMP280_Stamp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
SmartHome
NodeManager_BMP280_Stamp
Commits
69f2705c
Commit
69f2705c
authored
8 years ago
by
user2684
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
PowerManager allows Vcc only to be set
parent
00ae05a8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
NodeManager.cpp
+41
-46
41 additions, 46 deletions
NodeManager.cpp
NodeManager.h
+2
-5
2 additions, 5 deletions
NodeManager.h
README.md
+2
-0
2 additions, 0 deletions
README.md
with
45 additions
and
51 deletions
NodeManager.cpp
+
41
−
46
View file @
69f2705c
...
...
@@ -4,36 +4,6 @@
#include
"NodeManager.h"
/***************************************
Global functions
*/
// return vcc in V
float
getVcc
()
{
#ifndef MY_GATEWAY_ESP8266
// Measure Vcc against 1.1V Vref
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX4
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX
=
(
_BV
(
MUX5
)
|
_BV
(
MUX0
));
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX
=
(
_BV
(
MUX3
)
|
_BV
(
MUX2
));
#else
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#endif
// Vref settle
wait
(
70
);
// Do conversion
ADCSRA
|=
_BV
(
ADSC
);
while
(
bit_is_set
(
ADCSRA
,
ADSC
))
{};
// return Vcc in mV
return
(
float
)((
1125300UL
)
/
ADC
)
/
1000
;
#else
return
(
float
)
0
;
#endif
}
/***************************************
PowerManager
*/
...
...
@@ -46,26 +16,26 @@ void PowerManager::setPowerPins(int ground_pin, int vcc_pin, int wait_time) {
Serial
.
print
(
F
(
" V="
));
Serial
.
println
(
vcc_pin
);
#endif
// configure the vcc pin as output and initialize to high (power on)
_vcc_pin
=
vcc_pin
;
pinMode
(
_vcc_pin
,
OUTPUT
);
digitalWrite
(
_vcc_pin
,
HIGH
);
// configure the ground pin as output and initialize to low
_ground_pin
=
ground_pin
;
pinMode
(
_ground_pin
,
OUTPUT
);
digitalWrite
(
_ground_pin
,
LOW
);
if
(
_ground_pin
>
0
)
{
// configure the ground pin as output and initialize to low
_ground_pin
=
ground_pin
;
pinMode
(
_ground_pin
,
OUTPUT
);
digitalWrite
(
_ground_pin
,
LOW
);
}
if
(
_vcc_pin
>
0
)
{
// configure the vcc pin as output and initialize to high (power on)
_vcc_pin
=
vcc_pin
;
pinMode
(
_vcc_pin
,
OUTPUT
);
digitalWrite
(
_vcc_pin
,
HIGH
);
}
// save wait time
_wait
=
wait_time
;
}
// return true if power pins have been configured
bool
PowerManager
::
isConfigured
()
{
if
(
_vcc_pin
!=
-
1
&&
_ground_pin
!=
-
1
)
return
true
;
return
false
;
}
// turn on the sensor by activating its power pins
void
PowerManager
::
powerOn
()
{
if
(
!
isConfigured
()
)
return
;
if
(
_vcc_pin
==
-
1
)
return
;
#if DEBUG == 1
Serial
.
print
(
F
(
"ON P="
));
Serial
.
println
(
_vcc_pin
);
...
...
@@ -78,7 +48,7 @@ void PowerManager::powerOn() {
// turn off the sensor
void
PowerManager
::
powerOff
()
{
if
(
!
isConfigured
()
)
return
;
if
(
_vcc_pin
==
-
1
)
return
;
#if DEBUG == 1
Serial
.
print
(
F
(
"OFF P="
));
Serial
.
println
(
_vcc_pin
);
...
...
@@ -768,7 +738,7 @@ void SensorML8511::onSetup() {
void
SensorML8511
::
onLoop
()
{
// read the voltage
int
uvLevel
=
analogRead
(
_pin
);
int
refLevel
=
getVcc
()
*
1024
/
3.3
;
int
refLevel
=
_node_manager
->
getVcc
()
*
1024
/
3.3
;
//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
float
outputVoltage
=
3.3
/
refLevel
*
uvLevel
;
//Convert the voltage to a UV intensity level
...
...
@@ -2997,6 +2967,31 @@ void NodeManager::saveToMemory(int index, int value) {
saveState
(
index
+
EEPROM_USER_START
,
value
);
}
// return vcc in V
float
NodeManager
::
getVcc
()
{
#ifndef MY_GATEWAY_ESP8266
// Measure Vcc against 1.1V Vref
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX4
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX
=
(
_BV
(
MUX5
)
|
_BV
(
MUX0
));
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX
=
(
_BV
(
MUX3
)
|
_BV
(
MUX2
));
#else
ADMUX
=
(
_BV
(
REFS0
)
|
_BV
(
MUX3
)
|
_BV
(
MUX2
)
|
_BV
(
MUX1
));
#endif
// Vref settle
wait
(
70
);
// Do conversion
ADCSRA
|=
_BV
(
ADSC
);
while
(
bit_is_set
(
ADCSRA
,
ADSC
))
{};
// return Vcc in mV
return
(
float
)((
1125300UL
)
/
ADC
)
/
1000
;
#else
return
(
float
)
0
;
#endif
}
// send a message to the network
void
NodeManager
::
_send
(
MyMessage
&
message
)
{
// send the message, multiple times if requested
...
...
This diff is collapsed.
Click to expand it.
NodeManager.h
+
2
−
5
View file @
69f2705c
...
...
@@ -332,10 +332,6 @@ class PowerManager {
void
powerOn
();
// turns the power pins on
void
powerOff
();
// returns the Vcc voltge
float
getVcc
();
// turns true if power pins are configured
bool
isConfigured
();
private
:
int
_vcc_pin
=
-
1
;
int
_ground_pin
=
-
1
;
...
...
@@ -1205,6 +1201,8 @@ class NodeManager {
int
loadFromMemory
(
int
index
);
// [27] save the given index of the EEPROM the provided value
void
saveToMemory
(
int
index
,
int
value
);
// return vcc in V
float
getVcc
();
// hook into the main sketch functions
void
before
();
void
presentation
();
...
...
@@ -1221,7 +1219,6 @@ class NodeManager {
bool
_battery_internal_vcc
=
true
;
int
_battery_pin
=
-
1
;
float
_battery_volts_per_bit
=
0.003363075
;
float
_getVcc
();
#endif
#if POWER_MANAGER == 1
// to optionally controller power pins
...
...
This diff is collapsed.
Click to expand it.
README.md
+
2
−
0
View file @
69f2705c
...
...
@@ -290,6 +290,8 @@ Node Manager comes with a reasonable default configuration. If you want/need to
int
loadFromMemory
(
int
index
);
// [27] save the given index of the EEPROM the provided value
void
saveToMemory
(
int
index
,
int
value
);
// return vcc in V
float
getVcc
();
~~~
For example
...
...
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