Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85becbd
commit d06d163
Showing
9 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
built | ||
node_modules | ||
yotta_modules | ||
yotta_targets | ||
pxt_modules | ||
*.db | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,48 @@ | ||
# BMP180 | ||
# BMP180 | ||
|
||
makecode BMP180 Digital Pressure Sensor package for micro:bit | ||
|
||
Author: shaoziyang | ||
Date: 2018.Jun | ||
|
||
![](icon.png) | ||
|
||
![](bmp180.jpg) | ||
|
||
## usage | ||
|
||
open your microbit makecode project, in Add Package, paste | ||
|
||
https://github.com/microbit-makecode-packages/BMP280 | ||
|
||
to search box then search. | ||
|
||
## I2C Address | ||
|
||
- 0x77 | ||
|
||
## API | ||
|
||
- function pressure() | ||
get pressure in hpa | ||
|
||
- function temperature() | ||
return temperature in Celsius. | ||
|
||
|
||
## Demo | ||
|
||
![](demo.jpg) | ||
|
||
## License | ||
|
||
MIT | ||
|
||
Copyright (c) 2018, microbit/micropython Chinese community | ||
|
||
## Supported targets | ||
|
||
* for PXT/microbit | ||
|
||
|
||
[From microbit/micropython Chinese community](http://www.micropython.org.cn) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
* makecode BMP180 digital pressure sensor Package. | ||
* From microbit/micropython Chinese community. | ||
* http://www.micropython.org.cn | ||
*/ | ||
|
||
/** | ||
* BMP180 block | ||
*/ | ||
//% weight=100 color=#30A0C0 icon="\uf042" block="BMP180" | ||
namespace BMP180 { | ||
let BMP180_I2C_ADDR = 0x77; | ||
|
||
function setreg(reg: number, dat: number): void { | ||
let buf = pins.createBuffer(2); | ||
buf[0] = reg; | ||
buf[1] = dat; | ||
pins.i2cWriteBuffer(BMP180_I2C_ADDR, buf); | ||
} | ||
|
||
function getreg(reg: number): number { | ||
pins.i2cWriteNumber(BMP180_I2C_ADDR, reg, NumberFormat.UInt8BE); | ||
return pins.i2cReadNumber(BMP180_I2C_ADDR, NumberFormat.UInt8BE); | ||
} | ||
|
||
function getUInt16BE(reg: number): number { | ||
pins.i2cWriteNumber(BMP180_I2C_ADDR, reg, NumberFormat.UInt8BE); | ||
return pins.i2cReadNumber(BMP180_I2C_ADDR, NumberFormat.UInt16BE); | ||
} | ||
|
||
function getInt16BE(reg: number): number { | ||
pins.i2cWriteNumber(BMP180_I2C_ADDR, reg, NumberFormat.UInt8BE); | ||
return pins.i2cReadNumber(BMP180_I2C_ADDR, NumberFormat.Int16BE); | ||
} | ||
|
||
let AC1 = getInt16BE(0xAA) | ||
let AC2 = getInt16BE(0xAC) | ||
let AC3 = getInt16BE(0xAE) | ||
let AC4 = getUInt16BE(0xB0) | ||
let AC5 = getUInt16BE(0xB2) | ||
let AC6 = getUInt16BE(0xB4) | ||
let B1 = getInt16BE(0xB6) | ||
let B2 = getInt16BE(0xB8) | ||
let MB = getInt16BE(0xBA) | ||
let MC = getInt16BE(0xBC) | ||
let MD = getInt16BE(0xBE) | ||
let UT = 0 | ||
let UP = 0 | ||
let T = 0 | ||
let P = 0 | ||
let X1 = 0 | ||
let X2 = 0 | ||
let X3 = 0 | ||
let B3 = 0 | ||
let B4 = 0 | ||
let B5 = 0 | ||
let B6 = 0 | ||
let B7 = 0 | ||
let _p = 0 | ||
|
||
function measure(): void { | ||
setreg(0xF4, 0x2E) | ||
basic.pause(6) | ||
UT = getUInt16BE(0xF6) | ||
setreg(0xF4, 0x34) | ||
basic.pause(6) | ||
UP = getUInt16BE(0xF6) | ||
} | ||
|
||
function get(): void { | ||
measure() | ||
X1 = (UT - AC6) * AC5 / (1 << 15) | ||
X2 = MC * (1 << 11) / (X1 + MD) | ||
B5 = X1 + X2 | ||
T = (B5 + 8) / 160 | ||
B6 = B5 - 4000 | ||
X1 = (B2 * (B6 * B6 / (1 << 12))) / (1 << 11) | ||
X2 = (AC2 * B6) / (1 << 11) | ||
X3 = X1 + X2 | ||
B3 = ((AC1 * 4 + X3) + 2) / 4 | ||
X1 = AC3 * B6 / (1 << 13) | ||
X2 = (B1 * (B6 * B6 / (1 << 12))) / (1 << 16) | ||
X3 = (X1 + X2 + 2) / 4 | ||
B4 = AC4 * (X3 + 32768) / (1 << 15) | ||
B7 = (UP - B3) * 50000 | ||
_p = (B7 / B4) * 2 | ||
X1 = (_p / (1 << 8)) * (_p / (1 << 8)) | ||
X1 = (X1 * 3038) / (1 << 16) | ||
X2 = (-7357 * _p) / (1 << 16) | ||
P = _p + (X1 + X2 + 3791) / 16 | ||
} | ||
|
||
/** | ||
* get temperature | ||
*/ | ||
//% blockId="BMP180_GET_TEMPERATURE" block="get temperature" | ||
This comment has been minimized.
Sorry, something went wrong. |
||
//% weight=80 blockGap=8 | ||
export function Temperature(): number { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
get(); | ||
return T; | ||
} | ||
|
||
/** | ||
* get pressure | ||
*/ | ||
//% blockId="BMP180_GET_PRESSURE" block="get pressure" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
shaoziyang
Author
Contributor
|
||
//% weight=80 blockGap=8 | ||
export function Press(): number { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
get(); | ||
return P; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "BMP180", | ||
"version": "1.0.0", | ||
"description": "makecode BMP180 Digital Pressure Sensor Package for micro:bit", | ||
"license": "MIT", | ||
"dependencies": { | ||
"core": "*" | ||
}, | ||
"files": [ | ||
"README.md", | ||
"main.ts" | ||
], | ||
"testFiles": [ | ||
"test.ts" | ||
], | ||
"public": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
basic.forever(() => { | ||
serial.writeValue("T", BMP180.Temperature()) | ||
serial.writeValue("P", BMP180.Press()) | ||
basic.pause(1000) | ||
}) |
1 comment
on commit d06d163
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! this is great!
use "temperature" and consider adding the unit like "temperature (°C)"