npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

max6675-raspi

v0.0.13

Published

Read the temperature with K-type thermocouple. Raspberry pi NodeJS.

Downloads

13

Readme

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