{"id":14978068,"url":"https://github.com/fivdi/mcp-spi-adc","last_synced_at":"2025-10-14T10:01:47.628Z","repository":{"id":54193992,"uuid":"59898887","full_name":"fivdi/mcp-spi-adc","owner":"fivdi","description":"MCP3002/4/8, MCP3202/4/8 and MCP3304 SPI analog to digital conversion with Node.js","archived":false,"fork":false,"pushed_at":"2021-10-17T09:14:47.000Z","size":283,"stargazers_count":62,"open_issues_count":4,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-18T20:47:23.981Z","etag":null,"topics":["adc","beaglebone","beaglebone-black","iot","javascript","mcp3002","mcp3004","mcp3008","mcp3201","mcp3202","mcp3204","mcp3208","mcp3304","nodejs","raspberry-pi","spi"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fivdi.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-28T14:39:29.000Z","updated_at":"2023-11-06T07:12:26.000Z","dependencies_parsed_at":"2022-08-13T08:50:52.200Z","dependency_job_id":null,"html_url":"https://github.com/fivdi/mcp-spi-adc","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fmcp-spi-adc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fmcp-spi-adc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fmcp-spi-adc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fivdi%2Fmcp-spi-adc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fivdi","download_url":"https://codeload.github.com/fivdi/mcp-spi-adc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233806488,"owners_count":18733205,"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":["adc","beaglebone","beaglebone-black","iot","javascript","mcp3002","mcp3004","mcp3008","mcp3201","mcp3202","mcp3204","mcp3208","mcp3304","nodejs","raspberry-pi","spi"],"created_at":"2024-09-24T13:56:49.094Z","updated_at":"2025-09-21T23:31:25.775Z","avatar_url":"https://github.com/fivdi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://app.travis-ci.com/fivdi/mcp-spi-adc.svg?branch=master)](https://app.travis-ci.com/github/fivdi/mcp-spi-adc)\n[![npm Version](http://img.shields.io/npm/v/mcp-spi-adc.svg)](https://www.npmjs.com/package/mcp-spi-adc)\n[![Downloads Per Month](http://img.shields.io/npm/dm/mcp-spi-adc.svg)](https://www.npmjs.com/package/mcp-spi-adc)\n\n# mcp-spi-adc\n\nMCP3002/4/8, MCP3201/2/4/8 and MCP3304 SPI analog to digital conversion with\n**Node.js** on Linux boards like the Raspberry Pi or BeagleBone.\n\nmcp-spi-adc supports Node.js versions 10, 12, 14, 15 and 16.\n\n## Contents\n\n * [Installation](#installation)\n * [Usage](#usage)\n * [Supported Devices](#supported-devices)\n * [API Documentation](#api-documentation)\n\n## Installation\n\n```\nnpm install mcp-spi-adc\n```\n\nIn order to use mcp-spi-adc SPI must be enabled. How SPI is enabled varies\nfrom board to board. For example, on the Raspberry Pi the raspi-config tool\ncan be used enable SPI. On the BeagleBone Black the config-pin utility can be\nused.\n\n## Usage\n\nDetermine the temperature using a TMP36 analog temperature sensor wired to\nchannel 5 on an MCP3008 SPI A/D converter.\n\n\u003cimg src=\"https://raw.githubusercontent.com/fivdi/mcp-spi-adc/master/example/pi-mcp3008-tmp36.png\"\u003e\n\n```js\nconst mcpadc = require('mcp-spi-adc');\n\nconst tempSensor = mcpadc.open(5, {speedHz: 20000}, err =\u003e {\n  if (err) throw err;\n\n  setInterval(_ =\u003e {\n    tempSensor.read((err, reading) =\u003e {\n      if (err) throw err;\n\n      console.log((reading.value * 3.3 - 0.5) * 100);\n    });\n  }, 1000);\n});\n```\n\nNote how the optional configuration option speedHz is used to configure the\nSPI clock frequency in Hertz for reading the value from the TMP36 temperature\nsensor. The default SPI clock frequency for the MCP3008 is 1350000Hz but\nlowering it to 20000Hz gives a more acurate temperature reading. In general,\nit's not necessary to lower the clock speed to read a value.\n\nThe default clock speed of 1350000Hz for the MCP3008 is derived from the\n[MCP3008 datasheet](https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf).\nThe maximum sampling rate at VDD = 2.7V is 75 ksps and each sample requires\nan 18-bit transfer. 75000 x 18 = 1350000. 1350000Hz is a conservative frequency\nin the above circuit as VDD is 3.3V.\n\n## Supported Devices\n\nDevice | Channels | Channel Numbers | Default Clock Frequency | Resolution | Raw Value Range\n:---: | ---: | ---: | ---: | ---: | ---:\nMCP3002 | 2 | 0-1 | 1200000Hz | 10-bit | 0-1023\nMCP3004 | 4 | 0-3 | 1350000Hz | 10-bit | 0-1023\nMCP3008 | 8 | 0-7 | 1350000Hz | 10-bit | 0-1023\nMCP3201 | 1 | 0 | 800000Hz | 12-bit | 0-4095\nMCP3202 | 2 | 0-1 | 900000Hz | 12-bit | 0-4095\nMCP3204 | 4 | 0-3 | 1000000Hz | 12-bit | 0-4095\nMCP3208 | 8 | 0-7 | 1000000Hz | 12-bit | 0-4095\nMCP3304 | 8 | 0-7 | 1050000Hz | 13-bit | 0-4095\n\n## API Documentation\n\nAll methods are asynchronous and take a completion callback as their last\nargument. The arguments passed to the completion callback depend on the\nmethod, but the first argument is always reserved for an exception. If the\noperation was completed successfully, then the first argument will be null\nor undefined.\n\n### Functions\n\n- [openMcp3002(channel[, options], cb)](#openmcp3002channel-options-cb)\n- [openMcp3004(channel[, options], cb)](#openmcp3004channel-options-cb)\n- [openMcp3008(channel[, options], cb)](#openmcp3008channel-options-cb)\n- [openMcp3201(channel[, options], cb)](#openmcp3201channel-options-cb)\n- [openMcp3202(channel[, options], cb)](#openmcp3202channel-options-cb)\n- [openMcp3204(channel[, options], cb)](#openmcp3204channel-options-cb)\n- [openMcp3208(channel[, options], cb)](#openmcp3208channel-options-cb)\n- [openMcp3304(channel[, options], cb)](#openmcp3304channel-options-cb)\n- [open(channel[, options], cb) - alias for openMcp3008(channel[, options], cb)](#openchannel-options-cb---alias-for-openmcp3008channel-options-cb)\n\n### Class AdcChannel\n\n- [adcChannel.read(cb)](#adcchannelreadcb)\n- [adcChannel.close(cb)](#adcchannelclosecb)\n\n### openMcp3002(channel[, options], cb)\n### openMcp3004(channel[, options], cb)\n### openMcp3008(channel[, options], cb)\n### openMcp3201(channel[, options], cb)\n### openMcp3202(channel[, options], cb)\n### openMcp3204(channel[, options], cb)\n### openMcp3208(channel[, options], cb)\n### openMcp3304(channel[, options], cb)\n### open(channel[, options], cb) - alias for openMcp3008(channel[, options], cb)\n- channel - the number of the channel to open, see channel numbers in\n[supported devices](#supported-devices)\n- options - an optional object specifying channel configuration options\n- cb - completion callback\n\nAsynchronous open. Returns a new AdcChannel object. The completion callback\ngets one argument (err). The AdcChannel object returned should not be used\nbefore the completion callback is called.\n\nThe following channel configuration options are supported:\n\n- busNumber - the SPI bus number, 0 for `/dev/spidev0.n`,\n1 for `/dev/spidev1.n`, ..., default 0\n- deviceNumber - the SPI device number, 0 for `/dev/spidevn.0`,\n1 for `/dev/spidevn.1`, ..., default 0\n- speedHz - a number representing the SPI clock frequency for reading from the\nchannel in Hertz, see default clock frequency in\n[supported devices](#supported-devices)\n\n### adcChannel.read(cb)\n- cb - completion callback\n\nAsynchronous read. The completion callback gets two arguments (err,\nreading). The reading argument is an object with the following properties:\n\n- value - the value read from the channel scaled to a value between 0 and 1\n- rawValue - the value read from the channel, see raw value range in\n[supported devices](#supported-devices)\n\nReturns this.\n\n### adcChannel.close(cb)\n- cb - completion callback\n\nAsynchronous close. Frees system resources used by this instance. The\ncompletion callback gets one argument (err). Returns null.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffivdi%2Fmcp-spi-adc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffivdi%2Fmcp-spi-adc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffivdi%2Fmcp-spi-adc/lists"}