Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoziyang committed Jun 18, 2018
1 parent 85becbd commit d06d163
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
built
node_modules
yotta_modules
yotta_targets
pxt_modules
*.db
*.tgz
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018
Copyright (c) 2018, microbit/micropython Chinese community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
49 changes: 48 additions & 1 deletion README.md
@@ -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)
Binary file added bmp180.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions main.ts
@@ -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.

Copy link
@pelikhan

pelikhan Jun 20, 2018

use "temperature" and consider adding the unit like "temperature (°C)"

//% weight=80 blockGap=8
export function Temperature(): number {

This comment has been minimized.

Copy link
@pelikhan

pelikhan Jun 20, 2018

use camel casing for TypeScript function names

get();
return T;
}

/**
* get pressure
*/
//% blockId="BMP180_GET_PRESSURE" block="get pressure"

This comment has been minimized.

Copy link
@pelikhan

pelikhan Jun 20, 2018

typically we don't use "get ", so just "pressure" is better.

This comment has been minimized.

Copy link
@shaoziyang

shaoziyang Jun 20, 2018

Author Contributor

I am a beginner of typscript, can you give me more advise?

//% weight=80 blockGap=8
export function Press(): number {

This comment has been minimized.

Copy link
@pelikhan

pelikhan Jun 20, 2018

spell out the function name entirely, "pressure"

get();
return P;
}
}
17 changes: 17 additions & 0 deletions pxt.json
@@ -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
}
5 changes: 5 additions & 0 deletions test.ts
@@ -0,0 +1,5 @@
basic.forever(() => {
serial.writeValue("T", BMP180.Temperature())
serial.writeValue("P", BMP180.Press())
basic.pause(1000)
})

1 comment on commit d06d163

@pelikhan
Copy link

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!

Please sign in to comment.