-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from pharo-iot/dev
BME280Device
- Loading branch information
Showing
31 changed files
with
235 additions
and
19 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
11 changes: 11 additions & 0 deletions
11
src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st
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,11 @@ | ||
baselines | ||
devices | ||
|
||
^{ | ||
#'PharoThings-Devices-Button' -> #(). | ||
#'PharoThings-Devices-Switch' -> #(#'PharoThings-Devices-Button'). | ||
|
||
#'PharoThings-Devices-ADXL345' -> #(#'PharoThings-Devices-I2C'). | ||
#'PharoThings-Devices-MCP9808' -> #(#'PharoThings-Devices-I2C'). | ||
#'PharoThings-Devices-BME280' -> #(#'PharoThings-Devices-I2C'). | ||
} |
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 @@ | ||
{ | ||
"separateMethodMetaAndSource" : false, | ||
"noMethodMetaData" : true, | ||
"useCypressPropertiesFile" : true | ||
} |
16 changes: 16 additions & 0 deletions
16
src/PharoThings-Devices-BME280.package/PotBME280Device.class/README.md
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,16 @@ | ||
I provide implementation of temperature/pressure/humidity sensor BME280Device. | ||
|
||
The code for initialization and sensors reading is copied from Python example: | ||
|
||
https://github.com/ControlEverythingCommunity/BME280/blob/master/Python/BME280.py | ||
|
||
In contract to the Pythin example I retrieve all coefficients in connection (setup) time because they are constant parameters. | ||
|
||
The method #readParameters returns three values: Celsius, hPa, humidity percents. | ||
|
||
Internal Representation and Key Implementation Points. | ||
|
||
Instance Variables | ||
hCoeffs: <WordArray> "humidity coefficients" | ||
pCoeffs: <WordArray> "pressure coefficients" | ||
tCoeffs: <WordArray> "temperature coefficients" |
3 changes: 3 additions & 0 deletions
3
src/PharoThings-Devices-BME280.package/PotBME280Device.class/class/defaultI2CAddress.st
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,3 @@ | ||
instance creation | ||
defaultI2CAddress | ||
^16r76 |
16 changes: 16 additions & 0 deletions
16
src/PharoThings-Devices-BME280.package/PotBME280Device.class/instance/connect.st
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,16 @@ | ||
controlling | ||
connect | ||
"https://github.com/ControlEverythingCommunity/BME280/blob/master/Python/BME280.py" | ||
super connect. | ||
self initTempAndPressureCoeffs. | ||
self initHumidityCoeffs. | ||
"Select control humidity register, 0xF2(242) | ||
0x01(01) Humidity Oversampling = 1" | ||
i2cConnection write8BitsAt: 16rF2 data: 16r01. | ||
"Select Control measurement register, 0xF4(244) | ||
0x27(39) Pressure and Temperature Oversampling rate = 1 | ||
Normal mode" | ||
i2cConnection write8BitsAt: 16rF4 data: 16r27. | ||
" Select Configuration register, 0xF5(245) | ||
0xA0(00) Stand_by time = 1000 ms" | ||
i2cConnection write8BitsAt: 16rF5 data: 16rA0 |
11 changes: 11 additions & 0 deletions
11
src/PharoThings-Devices-BME280.package/PotBME280Device.class/instance/decodeHumidityFrom..st
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,11 @@ | ||
decoding | ||
decodeHumidityFrom: dataFromF7 | ||
"data: Humidity MSB, Humidity LSB | ||
returns percents" | ||
| raw temperature var_H humidity | | ||
raw := ((dataFromF7 at: 7) << 8) | (dataFromF7 at: 8). | ||
temperature := self decodeTemperatureFrom: dataFromF7. | ||
var_H := (temperature * 5120.0) - 76800.0. | ||
var_H := (raw - ((hCoeffs at: 4) * 64.0 + ((hCoeffs at: 5) / 16384.0 * var_H))) * ((hCoeffs at: 2) / 65536.0 * (1.0 + ((hCoeffs at: 6) / 67108864.0 * var_H * (1.0 + ((hCoeffs at: 3) / 67108864.0 * var_H))))). | ||
humidity := var_H * (1.0 - ((hCoeffs at: 1) * var_H / 524288.0)). | ||
^humidity min: 100 max: 0 |
18 changes: 18 additions & 0 deletions
18
src/PharoThings-Devices-BME280.package/PotBME280Device.class/instance/decodePressureFrom..st
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,18 @@ | ||
decoding | ||
decodePressureFrom: dataFromF7 | ||
"data: Pressure MSB, Pressure LSB, Pressure xLSB | ||
returns hPa" | ||
| raw temperature var1 var2 p | | ||
raw := ((dataFromF7 at: 1) << 12) | ((dataFromF7 at: 2) << 4) | ((dataFromF7 at: 3) >> 4). | ||
temperature := self decodeTemperatureFrom: dataFromF7. | ||
var1 := ((temperature * 5120.0) / 2.0) - 64000.0. | ||
var2 := var1 * var1 * (pCoeffs at: 6) / 32768.0. | ||
var2 := var2 + (var1 * (pCoeffs at: 5) * 2.0). | ||
var2 := (var2 / 4.0) + ((pCoeffs at: 4) * 65536.0). | ||
var1 := ((pCoeffs at: 3) * var1 * var1 / 524288.0 + (( pCoeffs at: 2) * var1)) / 524288.0. | ||
var1 := (1.0 + (var1 / 32768.0)) * (pCoeffs at: 1). | ||
p := 1048576.0 - raw. | ||
p := (p - (var2 / 4096.0)) * 6250.0 / var1. | ||
var1 := (pCoeffs at: 9) * p * p / 2147483648.0. | ||
var2 := p * (pCoeffs at: 8) / 32768.0. | ||
^(p + ((var1 + var2 + (pCoeffs at: 7)) / 16.0)) / 100 |
8 changes: 8 additions & 0 deletions
8
...vices-BME280.package/PotBME280Device.class/instance/decodeSignedWordArrayFrom.at.size..st
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,8 @@ | ||
decoding | ||
decodeSignedWordArrayFrom: coeffs at: index size: size | ||
| result word | | ||
result := Array new: size. | ||
1 to: size do: [ :i | | ||
word := self decodeSignedWordFrom: coeffs at: index + ((i - 1) * 2). | ||
result at: i put: word ]. | ||
^ result |
7 changes: 7 additions & 0 deletions
7
...oThings-Devices-BME280.package/PotBME280Device.class/instance/decodeSignedWordFrom.at..st
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 @@ | ||
decoding | ||
decodeSignedWordFrom: coeffs at: index | ||
| unsigned | | ||
unsigned := self decodeUnsignedWordFrom: coeffs at: index. | ||
^ unsigned > 32767 | ||
ifTrue: [ unsigned - 65536 ] | ||
ifFalse: [ unsigned ] |
10 changes: 10 additions & 0 deletions
10
...aroThings-Devices-BME280.package/PotBME280Device.class/instance/decodeTemperatureFrom..st
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,10 @@ | ||
decoding | ||
decodeTemperatureFrom: dataFromF7 | ||
"data: Temperature MSB, Temperature LSB, Temperature xLSB. | ||
returns Celsius" | ||
| raw var1 var2 | | ||
raw := ((dataFromF7 at: 4) << 12) | ((dataFromF7 at: 5) << 4) | ((dataFromF7 at: 6) >> 4). | ||
|
||
var1 := (raw / 16384.0 - ((tCoeffs at: 1) / 1024.0)) * (tCoeffs at: 2). | ||
var2 := ((raw / 131072.0 - ((tCoeffs at: 1) / 8192.0)) * (raw / 131072.0 - ((tCoeffs at: 1) / 8192.0))) * (tCoeffs at: 3). | ||
^(var1 + var2) / 5120.0 |
3 changes: 3 additions & 0 deletions
3
...hings-Devices-BME280.package/PotBME280Device.class/instance/decodeUnsignedWordFrom.at..st
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,3 @@ | ||
decoding | ||
decodeUnsignedWordFrom: coeffs at: index | ||
^(coeffs at: index + 1) * 256 + (coeffs at: index) |
14 changes: 14 additions & 0 deletions
14
src/PharoThings-Devices-BME280.package/PotBME280Device.class/instance/initHumidityCoeffs.st
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,14 @@ | ||
controlling | ||
initHumidityCoeffs | ||
| data h1 h2 h3 h4 h5 h6 | | ||
h1 := i2cConnection read8BitsAt: 16rA1. | ||
data := i2cConnection read8BitsArray: 7 startingAt: 16rE1. | ||
h2 := self decodeSignedWordFrom: data at: 1. | ||
h3 := (data at: 3) bitAnd: 16rFF. | ||
h4 := (data at: 4) * 16 + ((data at: 5) bitAnd: 16rF). | ||
h4 > 32767 ifTrue: [ h4 := h4 - 65536]. | ||
h5 := ((data at: 5) / 16) + ((data at: 6) * 16). | ||
h5 > 32767 ifTrue: [ h5 := h5 - 65536]. | ||
h6 := data at: 7. | ||
h6 > 127 ifTrue: [ h6 := h6 - 256]. | ||
hCoeffs := {h1. h2. h3. h4. h5. h6} |
10 changes: 10 additions & 0 deletions
10
...Things-Devices-BME280.package/PotBME280Device.class/instance/initTempAndPressureCoeffs.st
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,10 @@ | ||
controlling | ||
initTempAndPressureCoeffs | ||
|
||
| data | | ||
data := i2cConnection read8BitsArray: 24 startingAt: 16r88. | ||
|
||
tCoeffs := {self decodeUnsignedWordFrom: data at: 1} | ||
, (self decodeSignedWordArrayFrom: data at: 3 size: 2). | ||
pCoeffs := {self decodeUnsignedWordFrom: data at: 7} | ||
, (self decodeSignedWordArrayFrom: data at: 9 size: 8) |
12 changes: 12 additions & 0 deletions
12
src/PharoThings-Devices-BME280.package/PotBME280Device.class/instance/readParameters.st
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,12 @@ | ||
controlling | ||
readParameters | ||
"Pressure MSB, Pressure LSB, Pressure xLSB, Temperature MSB, Temperature LSB | ||
Temperature xLSB, Humidity MSB, Humidity LSB" | ||
| data | | ||
data := i2cConnection read8BitsArray: 8 startingAt: 16rF7. | ||
|
||
^{ | ||
self decodeTemperatureFrom: data. | ||
self decodePressureFrom: data. | ||
self decodeHumidityFrom: data | ||
} |
3 changes: 3 additions & 0 deletions
3
src/PharoThings-Devices-BME280.package/PotBME280Device.class/instance/readTemperature.st
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,3 @@ | ||
controlling | ||
readTemperature | ||
^self readParameters first |
15 changes: 15 additions & 0 deletions
15
src/PharoThings-Devices-BME280.package/PotBME280Device.class/properties.json
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,15 @@ | ||
{ | ||
"commentStamp" : "DenisKudryashov 2/14/2018 16:01", | ||
"super" : "PotI2CDevice", | ||
"category" : "PharoThings-Devices-BME280", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"tCoeffs", | ||
"hCoeffs", | ||
"pCoeffs" | ||
], | ||
"name" : "PotBME280Device", | ||
"type" : "normal" | ||
} |
1 change: 1 addition & 0 deletions
1
src/PharoThings-Devices-BME280.package/monticello.meta/categories.st
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 @@ | ||
SystemOrganization addCategory: #'PharoThings-Devices-BME280'! |
Empty file.
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 @@ | ||
(name 'PharoThings-Devices-BME280') |
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 @@ | ||
{ } |
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 @@ | ||
{ | ||
"separateMethodMetaAndSource" : false, | ||
"noMethodMetaData" : true, | ||
"useCypressPropertiesFile" : true | ||
} |
7 changes: 7 additions & 0 deletions
7
src/PharoThings-Devices-MCP9808.package/PotMCP9808Device.class/README.md
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 @@ | ||
I provide implementation of temperature sensor MCP9808. | ||
|
||
The code for initialization and sensors reading is copied from Python example: | ||
|
||
https://github.com/ControlEverythingCommunity/MCP9808/blob/master/Python/MCP9808.py | ||
|
||
The method #readTemperature returns the value in Celsius |
3 changes: 3 additions & 0 deletions
3
src/PharoThings-Devices-MCP9808.package/PotMCP9808Device.class/class/defaultI2CAddress.st
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,3 @@ | ||
instance creation | ||
defaultI2CAddress | ||
^16r18 |
13 changes: 13 additions & 0 deletions
13
src/PharoThings-Devices-MCP9808.package/PotMCP9808Device.class/instance/connect.st
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,13 @@ | ||
controlling | ||
connect | ||
"The code is copied from Python: | ||
https://github.com/ControlEverythingCommunity/MCP9808/blob/master/Python/MCP9808.py" | ||
super connect. | ||
|
||
"Select configuration register, 0x01(1) | ||
0x0000(00) Continuous conversion mode, Power-up default" | ||
i2cConnection write16BitsAt: 16r01 data: #[16r00 16r00] asInteger. | ||
|
||
"Select resolution rgister, 0x08(8) | ||
0x03(03) Resolution = +0.0625 / C" | ||
i2cConnection write8BitsAt: 16r08 data: 16r03. |
11 changes: 11 additions & 0 deletions
11
src/PharoThings-Devices-MCP9808.package/PotMCP9808Device.class/instance/readTemperature.st
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,11 @@ | ||
controlling | ||
readTemperature | ||
| rawData ctemp | | ||
"Read data back from 0x05(5), 2 bytes | ||
Temp MSB, TEMP LSB" | ||
rawData := (i2cConnection read16BitsAt: 16r05) asByteArray. | ||
|
||
"Convert the data to 13-bits" | ||
ctemp := ((rawData second bitAnd: 16r1F) * 256) + rawData first. | ||
ctemp > 4095 ifTrue: [ ctemp := ctemp - 8192]. | ||
^ctemp * 0.0625 |
11 changes: 11 additions & 0 deletions
11
src/PharoThings-Devices-MCP9808.package/PotMCP9808Device.class/properties.json
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,11 @@ | ||
{ | ||
"commentStamp" : "DenisKudryashov 2/13/2018 18:18", | ||
"super" : "PotI2CDevice", | ||
"category" : "PharoThings-Devices-MCP9808", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"name" : "PotMCP9808Device", | ||
"type" : "normal" | ||
} |
1 change: 1 addition & 0 deletions
1
src/PharoThings-Devices-MCP9808.package/monticello.meta/categories.st
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 @@ | ||
SystemOrganization addCategory: #'PharoThings-Devices-MCP9808'! |
Empty file.
1 change: 1 addition & 0 deletions
1
src/PharoThings-Devices-MCP9808.package/monticello.meta/package
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 @@ | ||
(name 'PharoThings-Devices-MCP9808') |
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 @@ | ||
{ } |