Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
0349c1e0
"vscode:/vscode.git/clone" did not exist on "009862ab7eee394061eeaf1aa187fa339ca50be4"
Commit
0349c1e0
authored
Feb 12, 2017
by
vsky
Committed by
Marcel Stör
Feb 12, 2017
Browse files
Improve BME280 code samples for negative values (#1794)
parent
b26ed972
Changes
1
Hide whitespace changes
Inline
Side-by-side
docs/en/modules/bme280.md
View file @
0349c1e0
...
@@ -137,27 +137,20 @@ QNH = bme280.qfe2qnh(P, alt)
...
@@ -137,27 +137,20 @@ QNH = bme280.qfe2qnh(P, alt)
print
(
string.format
(
"QNH=%d.%03d"
,
QNH
/
1000
,
QNH
%
1000
))
print
(
string.format
(
"QNH=%d.%03d"
,
QNH
/
1000
,
QNH
%
1000
))
H
,
T
=
bme280
.
humi
()
H
,
T
=
bme280
.
humi
()
if
T
<
0
then
print
(
string.format
(
"T=-%d.%02d"
,
-
T
/
100
,
-
T
%
100
))
local
Tsgn
=
(
T
<
0
and
-
1
or
1
);
T
=
Tsgn
*
T
else
print
(
string.format
(
"T=%s%d.%02d"
,
Tsgn
<
0
and
"-"
or
""
,
T
/
100
,
T
%
100
))
print
(
string.format
(
"T=%d.%02d"
,
T
/
100
,
T
%
100
))
end
print
(
string.format
(
"humidity=%d.%03d%%"
,
H
/
1000
,
H
%
1000
))
print
(
string.format
(
"humidity=%d.%03d%%"
,
H
/
1000
,
H
%
1000
))
D
=
bme280
.
dewpoint
(
H
,
T
)
D
=
bme280
.
dewpoint
(
H
,
T
)
if
D
<
0
then
local
Dsgn
=
(
D
<
0
and
-
1
or
1
);
D
=
Dsgn
*
D
print
(
string.format
(
"dew_point=-%d.%02d"
,
-
D
/
100
,
-
D
%
100
))
print
(
string.format
(
"dew_point=%s%d.%02d"
,
Dsgn
<
0
and
"-"
or
""
,
D
/
100
,
D
%
100
))
else
print
(
string.format
(
"dew_point=%d.%02d"
,
D
/
100
,
D
%
100
))
end
-- altimeter function - calculate altitude based on current sea level pressure (QNH) and measure pressure
-- altimeter function - calculate altitude based on current sea level pressure (QNH) and measure pressure
P
=
bme280
.
baro
()
P
=
bme280
.
baro
()
curAlt
=
bme280
.
altitude
(
P
,
QNH
)
curAlt
=
bme280
.
altitude
(
P
,
QNH
)
if
curAlt
<
0
then
local
curAltsgn
=
(
curAlt
<
0
and
-
1
or
1
);
curAlt
=
curAltsgn
*
curAlt
print
(
string.format
(
"altitude=-%d.%02d"
,
-
curAlt
/
100
,
-
curAlt
%
100
))
print
(
string.format
(
"altitude=%s%d.%02d"
,
curAltsgn
<
0
and
"-"
or
""
,
curAlt
/
100
,
curAlt
%
100
))
else
print
(
string.format
(
"altitude=%d.%02d"
,
curAlt
/
100
,
curAlt
%
100
))
end
```
```
Or simpler and more efficient
Or simpler and more efficient
...
@@ -167,29 +160,20 @@ alt=320 -- altitude of the measurement place
...
@@ -167,29 +160,20 @@ alt=320 -- altitude of the measurement place
bme280
.
init
(
3
,
4
)
bme280
.
init
(
3
,
4
)
T
,
P
,
H
,
QNH
=
bme280
.
read
(
alt
)
T
,
P
,
H
,
QNH
=
bme280
.
read
(
alt
)
if
T
<
0
then
local
Tsgn
=
(
T
<
0
and
-
1
or
1
);
T
=
Tsgn
*
T
print
(
string.format
(
"T=-%d.%02d"
,
-
T
/
100
,
-
T
%
100
))
print
(
string.format
(
"T=%s%d.%02d"
,
Tsgn
<
0
and
"-"
or
""
,
T
/
100
,
T
%
100
))
else
print
(
string.format
(
"T=%d.%02d"
,
T
/
100
,
T
%
100
))
end
print
(
string.format
(
"QFE=%d.%03d"
,
P
/
1000
,
P
%
1000
))
print
(
string.format
(
"QFE=%d.%03d"
,
P
/
1000
,
P
%
1000
))
print
(
string.format
(
"QNH=%d.%03d"
,
QNH
/
1000
,
QNH
%
1000
))
print
(
string.format
(
"QNH=%d.%03d"
,
QNH
/
1000
,
QNH
%
1000
))
print
(
string.format
(
"humidity=%d.%03d%%"
,
H
/
1000
,
H
%
1000
))
print
(
string.format
(
"humidity=%d.%03d%%"
,
H
/
1000
,
H
%
1000
))
D
=
bme280
.
dewpoint
(
H
,
T
)
D
=
bme280
.
dewpoint
(
H
,
T
)
if
D
<
0
then
local
Dsgn
=
(
D
<
0
and
-
1
or
1
);
D
=
Dsgn
*
D
print
(
string.format
(
"dew_point=-%d.%02d"
,
-
D
/
100
,
-
D
%
100
))
print
(
string.format
(
"dew_point=%s%d.%02d"
,
Dsgn
<
0
and
"-"
or
""
,
D
/
100
,
D
%
100
))
else
print
(
string.format
(
"dew_point=%d.%02d"
,
D
/
100
,
D
%
100
))
end
-- altimeter function - calculate altitude based on current sea level pressure (QNH) and measure pressure
-- altimeter function - calculate altitude based on current sea level pressure (QNH) and measure pressure
P
=
bme280
.
baro
()
P
=
bme280
.
baro
()
curAlt
=
bme280
.
altitude
(
P
,
QNH
)
curAlt
=
bme280
.
altitude
(
P
,
QNH
)
if
curAlt
<
0
then
local
curAltsgn
=
(
curAlt
<
0
and
-
1
or
1
);
curAlt
=
curAltsgn
*
curAlt
print
(
string.format
(
"altitude=-%d.%02d"
,
-
curAlt
/
100
,
-
curAlt
%
100
))
print
(
string.format
(
"altitude=%s%d.%02d"
,
curAltsgn
<
0
and
"-"
or
""
,
curAlt
/
100
,
curAlt
%
100
))
else
print
(
string.format
(
"altitude=%d.%02d"
,
curAlt
/
100
,
curAlt
%
100
))
end
```
```
Use
`bme280.init(sda, scl, 1, 3, 0, 3, 0, 4)`
for "game mode" - Oversampling settings pressure ×4, temperature ×1, humidity ×0, sensor mode: normal mode, inactive duration = 0.5 ms, IIR filter settings filter coefficient 16.
Use
`bme280.init(sda, scl, 1, 3, 0, 3, 0, 4)`
for "game mode" - Oversampling settings pressure ×4, temperature ×1, humidity ×0, sensor mode: normal mode, inactive duration = 0.5 ms, IIR filter settings filter coefficient 16.
...
@@ -199,11 +183,8 @@ Example of readout in forced mode (asynchronous)
...
@@ -199,11 +183,8 @@ Example of readout in forced mode (asynchronous)
bme280
.
init
(
3
,
4
,
nil
,
nil
,
nil
,
0
)
-- initialize to sleep mode
bme280
.
init
(
3
,
4
,
nil
,
nil
,
nil
,
0
)
-- initialize to sleep mode
bme280
.
startreadout
(
0
,
function
()
bme280
.
startreadout
(
0
,
function
()
T
,
P
=
bme280
.
read
()
T
,
P
=
bme280
.
read
()
if
T
<
0
then
local
Tsgn
=
(
T
<
0
and
-
1
or
1
);
T
=
Tsgn
*
T
print
(
string.format
(
"T=-%d.%02d"
,
-
T
/
100
,
-
T
%
100
))
print
(
string.format
(
"T=%s%d.%02d"
,
Tsgn
<
0
and
"-"
or
""
,
T
/
100
,
T
%
100
))
else
print
(
string.format
(
"T=%d.%02d"
,
T
/
100
,
T
%
100
))
end
end
)
end
)
```
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment