mirror of
https://github.com/kou029w/megabit.git
synced 2025-01-30 21:58:04 +00:00
feat: sht30
This commit is contained in:
parent
321864f078
commit
dd87a486ea
6 changed files with 44 additions and 6 deletions
|
@ -25,11 +25,12 @@ blink();
|
|||
### I<sup>2</sup>C Example
|
||||
|
||||
```js
|
||||
const { adt7410 } = require("megabit");
|
||||
const { sht30 } = require("megabit");
|
||||
|
||||
async function measure() {
|
||||
const temperature = await adt7410().read();
|
||||
console.log(`Temperature: ${temperature} ℃`);
|
||||
const { humidity, temperature } = await sht30().read();
|
||||
console.log(`Humidity: ${humidity.toFixed(2)}%`);
|
||||
console.log(`Temperature: ${temperature.toFixed(2)} ℃`);
|
||||
}
|
||||
|
||||
measure();
|
||||
|
@ -51,6 +52,7 @@ measure();
|
|||
| PAJ7620 | Gesture Recognition Sensor | [paj7620](https://kou029w.github.io/megabit/globals.html#paj7620) |
|
||||
| PCA9685 | 16-Channel 12-Bit PWM/Servo Driver | [pca9685](https://kou029w.github.io/megabit/globals.html#pca9685) |
|
||||
| S11059 | Color Sensor | [s11059](https://kou029w.github.io/megabit/globals.html#s11059) |
|
||||
| SHT30 | Humidity and Temperature Sensor | [sht30](https://kou029w.github.io/megabit/globals.html#sht30) |
|
||||
| SSD1306 | 128x64 Dot Matrix OLED | [ssd1306](https://kou029w.github.io/megabit/globals.html#ssd1306) |
|
||||
| SSD1308 | 128x64 Dot Matrix OLED | [ssd1308](https://kou029w.github.io/megabit/globals.html#ssd1308) |
|
||||
| TSL2561 | Ambient Light Sensor | [tsl2561](https://kou029w.github.io/megabit/globals.html#tsl2561) |
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
"@chirimen/grove-touch": "~1",
|
||||
"@chirimen/pca9685": "~1",
|
||||
"@chirimen/s11059": "~1",
|
||||
"@chirimen/sht30": "~1",
|
||||
"@chirimen/veml6070": "~1",
|
||||
"@chirimen/vl53l0x": "~1",
|
||||
"node-web-gpio": "~1",
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
export interface ReadableDevice<
|
||||
T extends boolean | number | string | boolean[] | number[]
|
||||
> {
|
||||
export interface ReadableDevice<T> {
|
||||
read(): Promise<T>;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ export { default as mpr121 } from "./mpr121";
|
|||
export { default as paj7620 } from "./paj7620";
|
||||
export { default as pca9685 } from "./pca9685";
|
||||
export { default as s11059 } from "./s11059";
|
||||
export { default as sht30 } from "./sht30";
|
||||
export { default as ssd1308 } from "./ssd1308";
|
||||
export { default as tsl2561 } from "./tsl2561";
|
||||
export { default as veml6070 } from "./veml6070";
|
||||
|
|
31
src/sht30.ts
Normal file
31
src/sht30.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import Device from "@chirimen/sht30";
|
||||
import { ReadableDevice } from "./Device";
|
||||
import { I2C, i2c } from "./i2c";
|
||||
|
||||
/** @type Humidity (%) */
|
||||
type Humidity = number;
|
||||
|
||||
/** @type Temperature (°C) */
|
||||
type Temperature = number;
|
||||
|
||||
/** @type Values */
|
||||
type Values = {
|
||||
humidity: Humidity;
|
||||
temperature: Temperature;
|
||||
};
|
||||
|
||||
export function sht30(
|
||||
bus: I2C = i2c(),
|
||||
address: number = 0x44
|
||||
): ReadableDevice<Values> {
|
||||
const device = new Device(bus, address);
|
||||
|
||||
return {
|
||||
async read(): Promise<Values> {
|
||||
if (device.i2cSlave == null) await device.init();
|
||||
return await device.readData();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default sht30;
|
|
@ -52,6 +52,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@chirimen/s11059/-/s11059-1.0.2.tgz#d27e1d205975296e28348fc5d8c17a573d23364d"
|
||||
integrity sha512-qj9Vp9pxEsL5XF1bM374xAWIpDJFnM3kx03UZnkZzHI76RG03+ghoh6iNu8eicy2fM55LIForUV+ZQDNcqOy1A==
|
||||
|
||||
"@chirimen/sht30@~1":
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@chirimen/sht30/-/sht30-1.0.3.tgz#e401ded73d3d70f936ac90f5b67ebfde01975682"
|
||||
integrity sha512-S6LUFYjSdIPSaK8RukEYD+UKS4yKpiFfMbUK9m9Phbsa704SQAvo+bUtbPqJko+XZX8lADXr12BdEW8QrLl+Qw==
|
||||
|
||||
"@chirimen/veml6070@~1":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@chirimen/veml6070/-/veml6070-1.0.0.tgz#407fdef1f1a6017196879b90fad8858eb20ad33a"
|
||||
|
|
Loading…
Add table
Reference in a new issue