https://github.com/johntalton/mcp300x
MCP3004/3008 ADC
https://github.com/johntalton/mcp300x
javascript mcp3004 mcp3008
Last synced: about 2 months ago
JSON representation
MCP3004/3008 ADC
- Host: GitHub
- URL: https://github.com/johntalton/mcp300x
- Owner: johntalton
- License: mit
- Created: 2017-07-24T01:49:11.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-07-01T10:17:56.000Z (10 months ago)
- Last Synced: 2025-01-12T20:11:30.938Z (3 months ago)
- Topics: javascript, mcp3004, mcp3008
- Language: JavaScript
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mcp300X
Implementation of the mcp3004/mcp3008 ADC chip.
[](https://www.npmjs.com/package/@johntalton/mcp300x)

[](https://github.com/johntalton/mcp300X/actions/workflows/CI.yml)

[](https://www.npmjs.com/package/@johntalton/mcp300x)

[](https://packagequality.com/#?package=@johntalton/mcp300x)Features:
- Provides access to pseudo differential mode
- Does not assume Vref and Vin are the sameAnd while this implementation is more verbose, it does so in order to aid in clarity of understanding and for learning.
## Sample Usage
```javascript
import { mcp300x } = from '@johntalton/mcp300X'
const spi = ...
const adc = mcp300X.from({ bus: spi, Vref: 5, channels: 8 })const result = await dev.readADC(channel)
console.log('normalized value', result.normal)
console.log('voltage', result.V)
```In the usage above our Analog circuitry is running at 5V, while the chip is running at 3.3V configuration.
The returned ```result``` object holds the ```normal```-ized value, as well as the ```raw``` ADC value and the ```V``oltage as calculated.
## Psuedo Differential Mode
The mode allows the bonding of two channels in +/- or -/+ configurations.
### Reference by channel pair or index
The ```readADCDiff``` method can be passed a single "index-channel" or the order +/- pair.
From the spec:
| Idx | +ch / -ch |
| --- | --- |
| 1st | Ch0 / Ch1 |
| 2nd | Ch1 / Ch0 |
| 3rd | Ch2 / Ch3 |
| etc ... |```
...
dev.readADCDiff(6).then(result => { ... }) // index-channel 6 or +Ch5 / -Ch4
```