{"id":14978108,"url":"https://github.com/bubao/max6675-raspberry-pi-nodejs","last_synced_at":"2025-10-28T08:31:45.874Z","repository":{"id":57292704,"uuid":"173276768","full_name":"bubao/Max6675-Raspberry-pi-nodejs","owner":"bubao","description":"Read the temperature with K-type thermocouple. Raspberry pi NodeJS","archived":false,"fork":false,"pushed_at":"2024-06-10T01:03:48.000Z","size":2296,"stargazers_count":4,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-29T01:01:20.756Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bubao.png","metadata":{"files":{"readme":"README.cn.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-01T09:47:10.000Z","updated_at":"2023-08-26T13:36:07.000Z","dependencies_parsed_at":"2024-09-18T23:04:31.168Z","dependency_job_id":"f8a4c5b1-a73b-45d2-bfa7-0e2954f14144","html_url":"https://github.com/bubao/Max6675-Raspberry-pi-nodejs","commit_stats":{"total_commits":87,"total_committers":1,"mean_commits":87.0,"dds":0.0,"last_synced_commit":"6e629fcc0a2e9587bf729e97eb2e836650fb95b3"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubao%2FMax6675-Raspberry-pi-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubao%2FMax6675-Raspberry-pi-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubao%2FMax6675-Raspberry-pi-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubao%2FMax6675-Raspberry-pi-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bubao","download_url":"https://codeload.github.com/bubao/Max6675-Raspberry-pi-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859904,"owners_count":16556031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:56:52.488Z","updated_at":"2025-10-28T08:31:45.449Z","avatar_url":"https://github.com/bubao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Max6675\n\n[![NPM version](https://img.shields.io/npm/v/max6675-raspi.svg)](https://www.npmjs.com/package/max6675-raspi) [![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/english.svg)](README.md)\n\n在树莓派上使用 Node.js 驱动 Max6675 芯片，读取 K 型热偶的温度值。\n\n```sh\nnpm i max6675-raspi --save\n```\n\n![Max6675](https://github.com/bubao/Max6675-Raspberry-pi-nodejs/raw/master/imgs/Max6675.png)\n\n## API\n\n### `Max6675`\n\n```js\nconst Max6675 = require(\"max6675-raspi\");\nconst CS = 4;\nconst SCK = 24;\nconst SO = [25, 12, 16, 20, 21];\nconst UNIT = 1;\n\nconst max6675 = new Max6675(CS, SCK, SO, UNIT);\n```\n\n可以接收 4 个参数：\n\n- `CS`: Max6675 模块的`CS`脚对应的树莓派的 GPIO 号。\n- `SCK`: Max6675 模块的`SCK`脚对应的树莓派的 GPIO 号。\n- `SO`: Max6675 模块的`SO`脚对应的树莓派的 GPIO 号，可以接收一个数组，也可以接收一个整数。\n- `UNIT`: 设置结果输出单位，`1`为`°C`，`0`为`°F`，不传参数则默认值为`1`，传其他值则直接返回`Max6675`芯片的二进制数转十进制数值。\n\n### `setPin`\n\n```js\nconst Max6675 = require(\"max6675-raspi\");\n\nconst CS = 4;\nconst SCK = 24;\nconst SO = [25, 12, 16, 20, 21];\nconst UNIT = 1;\n\n// const max = new Max6675(CS, SCK, SO, UNIT);\nconst max6675 = new Max6675();\nmax6675.setPin(CS, SCK, SO, UNIT);\n```\n\n如果你在`new Max6675()`的时候没有传参数，就可以调用这个方法设置针脚信息。与`Max6675`一样接收四个参数：\n\n- `CS`: Max6675 模块的`CS`脚对应的树莓派的 GPIO 号。\n- `SCK`: Max6675 模块的`SCK`脚对应的树莓派的 GPIO 号。\n- `SO`: Max6675 模块的`SO`脚对应的树莓派的 GPIO 号，可以接收一个数组，也可以接收一个整数。\n- `UNIT`: 设置结果输出单位，`1`为`°C`，`2`为`°F`，不传参数则默认值为`1`，传其他值则直接返回`Max6675`芯片的二进制数转十进制数值。\n\n### `readTemp`\n\n在设定了`CS`，`SCK`，`SO`和`UNIT`（默认值为`1`) 后，即能调用这个方法来获取值。\n\n```js\nconst Max6675 = require(\"max6675-raspi\");\n\nconst CS = 4;\nconst SCK = 24;\nconst SO = [25, 12, 16, 20, 21];\nconst UNIT = 1;\nconst max6675 = new Max6675();\nmax6675.setPin(CS, SCK, SO, UNIT);\nconst { temp, unit } = max6675.readTemp();\nconsole.log(`${new Date()}:${temp.map(item =\u003e item + unit)}`);\n```\n\n`setPin`之后也可以立即调用`readTemp`\n\n```js\nconst Max6675 = require(\"max6675-raspi\");\n\nconst CS = 4;\nconst SCK = 24;\nconst SO = [25, 12, 16, 20, 21];\nconst UNIT = 1;\nconst max6675 = new Max6675();\nconst { temp, unit } = max6675.setPin(CS, SCK, SO, UNIT).readTemp();\nconsole.log(`${new Date()}:${temp.map(item =\u003e item + unit)}`);\n```\n\n### `sleep`\n\n这是个用`Promise`封装的延时器。当你需要循环获取值，但又不想自己写延时器的时候，可以像下面一样使用这个`sleep`方法。\n\n```js\nconst Max6675 = require(\"max6675-raspi\");\n\nconst CS = 4;\nconst SCK = 24;\nconst SO = [25, 12, 16, 20, 21];\nconst UNIT = 1;\nconst max6675 = new Max6675();\nmax6675.setPin(CS, SCK, SO, UNIT);\n\n(async () =\u003e {\n    while (true) {\n        const { temp, unit } = max6675.readTemp();\n        if (temp.length)\n            console.log(`${new Date()}:${temp.map(item =\u003e item + unit)}`);\n        await max6675.sleep(2000);\n    }\n})();\n```\n\n![PIN](https://user-images.githubusercontent.com/13029001/107857184-c58d7100-6e67-11eb-93b1-8a4ebc9c9309.png)\n\nThe PINs value is BCM GPIOs (green).\n\n## GPIO\n\n这里特地提 GPIO，`SO`，`CS`，`SCK`的值，是树莓派上的 BCM GPIO（绿色），不是针脚号。\n\n引用一张 [`https://github.com/splitbrain/rpibplusleaf`](https://github.com/splitbrain/rpibplusleaf) 的图片。\n\n[![rpiblusleaf](https://raw.githubusercontent.com/splitbrain/rpibplusleaf/master/rpiblusleaf.png)](https://github.com/splitbrain/rpibplusleaf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubao%2Fmax6675-raspberry-pi-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbubao%2Fmax6675-raspberry-pi-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubao%2Fmax6675-raspberry-pi-nodejs/lists"}