0.0.13 • Published 3 years ago

max6675-raspi v0.0.13

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

Max6675

NPM version jaywcjlove/sb

在树莓派上使用 Node.js 驱动 Max6675 芯片,读取 K 型热偶的温度值。

npm i max6675-raspi --save

Max6675

API

Max6675

const Max6675 = require("max6675-raspi");
const CS = 4;
const SCK = 24;
const SO = [25, 12, 16, 20, 21];
const UNIT = 1;

const max6675 = new Max6675(CS, SCK, SO, UNIT);

可以接收 4 个参数:

  • CS: Max6675 模块的CS脚对应的树莓派的 GPIO 号。
  • SCK: Max6675 模块的SCK脚对应的树莓派的 GPIO 号。
  • SO: Max6675 模块的SO脚对应的树莓派的 GPIO 号,可以接收一个数组,也可以接收一个整数。
  • UNIT: 设置结果输出单位,1°C0°F,不传参数则默认值为1,传其他值则直接返回Max6675芯片的二进制数转十进制数值。

setPin

const Max6675 = require("max6675-raspi");

const CS = 4;
const SCK = 24;
const SO = [25, 12, 16, 20, 21];
const UNIT = 1;

// const max = new Max6675(CS, SCK, SO, UNIT);
const max6675 = new Max6675();
max6675.setPin(CS, SCK, SO, UNIT);

如果你在new Max6675()的时候没有传参数,就可以调用这个方法设置针脚信息。与Max6675一样接收四个参数:

  • CS: Max6675 模块的CS脚对应的树莓派的 GPIO 号。
  • SCK: Max6675 模块的SCK脚对应的树莓派的 GPIO 号。
  • SO: Max6675 模块的SO脚对应的树莓派的 GPIO 号,可以接收一个数组,也可以接收一个整数。
  • UNIT: 设置结果输出单位,1°C2°F,不传参数则默认值为1,传其他值则直接返回Max6675芯片的二进制数转十进制数值。

readTemp

在设定了CSSCKSOUNIT(默认值为1) 后,即能调用这个方法来获取值。

const Max6675 = require("max6675-raspi");

const CS = 4;
const SCK = 24;
const SO = [25, 12, 16, 20, 21];
const UNIT = 1;
const max6675 = new Max6675();
max6675.setPin(CS, SCK, SO, UNIT);
const { temp, unit } = max6675.readTemp();
console.log(`${new Date()}:${temp.map(item => item + unit)}`);

setPin之后也可以立即调用readTemp

const Max6675 = require("max6675-raspi");

const CS = 4;
const SCK = 24;
const SO = [25, 12, 16, 20, 21];
const UNIT = 1;
const max6675 = new Max6675();
const { temp, unit } = max6675.setPin(CS, SCK, SO, UNIT).readTemp();
console.log(`${new Date()}:${temp.map(item => item + unit)}`);

sleep

这是个用Promise封装的延时器。当你需要循环获取值,但又不想自己写延时器的时候,可以像下面一样使用这个sleep方法。

const Max6675 = require("max6675-raspi");

const CS = 4;
const SCK = 24;
const SO = [25, 12, 16, 20, 21];
const UNIT = 1;
const max6675 = new Max6675();
max6675.setPin(CS, SCK, SO, UNIT);

(async () => {
    while (true) {
        const { temp, unit } = max6675.readTemp();
        if (temp.length)
            console.log(`${new Date()}:${temp.map(item => item + unit)}`);
        await max6675.sleep(2000);
    }
})();

PIN

The PINs value is BCM GPIOs (green).

GPIO

这里特地提 GPIO,SOCSSCK的值,是树莓派上的 BCM GPIO(绿色),不是针脚号。

引用一张 https://github.com/splitbrain/rpibplusleaf 的图片。

rpiblusleaf

0.0.13

3 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago