# adc-pi-spi

> Using an ADC (MCP3008) with a Pi over spi

Latest version **0.0.1** (published 2013-08-19) · BSD license · 0 weekly downloads

## Install

```sh
npm install adc-pi-spi
pnpm add adc-pi-spi
yarn add adc-pi-spi
bun add adc-pi-spi
```

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2013-08-19 |
| First published | 2013-08-19 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Christian Fehmer |
| Maintainers | fehmer |
| Keywords | raspberry, pi, spi, spi-dev, adc, mcp3008 |

## Links

- npm: https://www.npmjs.com/package/adc-pi-spi
- Repository: https://github.com/fehmer/adc-pi-spi
- Issues: https://github.com/fehmer/adc-pi-spi/issues
- npm.io page: https://npm.io/package/adc-pi-spi

## Dependencies (2)

- [node-spi](https://npm.io/package/node-spi.md) git://github.com/rosterloh/node-spi.git#master
- [coffee-script](https://npm.io/package/coffee-script.md)

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2013-08-19

## README

#     Read ADC (MCP3008) using spi

Read values from an MCP3008 connected to an raspberry pi using spidev

## Usage / Example


```coffeescript
ADC = require 'adc-pi-spi'
options =
	tolerance: 10		#default = 10
	pollInterval: 200	#default = 200
	channels: [0,1,2,3]	#default = [0]

adc=new ADC('/dev/spidev0.0', options)

adc.on 'change', (channel, value)->
	console.log 'channel ', channel, 'is now', value

process.on 'SIGTERM', () ->
	adc.close()

process.on 'SIGINT', () ->
	adc.close()

process.on 'exit', () ->
	adc.close()
```

## API

  - [ADC(device:String,[options:Array])](#adcdevicestringoptionsarray)
  - [ADC.state([channel:Number])](#adcstatechannelnumber)
  - [ADC.close()](#adcclose)
  - [ADC.read(channel, callbackfunction))](#adcreadchannelnumber-callback-function)

## ADC(device:String,[options:Array])

  Setting up a new ADC. Options are optional. The device name is the full path to the spi device, like /dev/spidev0.0
  
```coffeescript
options =
	tolerance: 10		#default = 10
	pollInterval: 200	#default = 200
	channels: [0,1,2,3]	#default = [0]

adc=new ADC('/dev/spidev0.0', options)
```



## ADC.state([channel:Number])

Retrieve the current state of the inputs. 
If no channel is given, the function will return the values of all defined channels (see options). 
If a channel is given, the function will return only the value of the choosen channel.

The values are absolute values from the adc (e.g. 0..1023 if you are using a 10Bit chip)

## ADC.close()

  Close the spi device

## ADC.read(channel:Number, callback: function())

Read the current value of the channel. Note: state() uses the buffered state which is updated automatically each pollInterval (see options). Read always reads the actual data without updating the state().

## Options

- tolerance

    Change-Event will not fire if the difference between the current and the last value is lower than the tolerance

- pollInterval

	The ADC is polled every pollInterval milliseconds.

- channels

	The ADC channels to monitor, state() and events only contains theese channels

## Events

- change

	Fires if a channel value changes more than the tolerance value. The events has two parameters:
    
	* channel: Number the number of the channel which changed
	* value: Number the absolute value of the channel

    ### Example
```coffeescript
adc.on 'change', (channel, value)->
console.log 'channel ', channel, 'is now', value
```

---
_Source: https://npm.io/package/adc-pi-spi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
