Reference
MCP3008
8-channel 10-bit ADC.
- Connects over
- SPI
- Made by
- Microchip
- Datasheet
- ww1.microchip.com
Use it
hardware {
device mcp3008: MCP3008(cs: 16)
}
every 1s {
let value: int = mcp3008.read(1)
log("mcp3008", "read={value}")
}
The MCP3008 goes on the SPI bus; give it its cs pin as an argument.
Methods
-
mcp3008.read(channel: int) -> int
ADC value 0-1023
Wiring
| Pin | Connect to |
|---|---|
VCC | 3.3V or 5V |
GND | Ground |
SCK | SPI clock |
MOSI | Master Out / Slave In |
MISO | Master In / Slave Out |
CS | Chip select (active low) |
AGND | Analog ground — tie to GND for single-supply use |
VREF | Reference voltage — tie to VCC for full-scale = supply |
Specifications
- Voltage
- 2.7V – 5.5V
- Current
- 500 μA active, 5 nA standby
- Channels
- 8 single-ended or 4 pseudo-differential
- Resolution
- 10-bit
- Sample rate
- Up to 200 kSPS at 5V
- Interface speed
- SPI up to 3.6 MHz at 5V
Tips
- Cheap and easy way to add analog inputs to an MCU with few or no ADC pins (e.g. Pi).
- VREF sets the full-scale range — drop it for higher resolution on small signals.
- 10-bit means 1024 steps — for 5V VREF that's ~5 mV resolution.
Alternatives worth knowing:
- ADS1115: I²C, 16-bit, PGA — slower but vastly more accurate.
- MCP3208: 12-bit version of the same chip — same pinout, same code with a different bit shift.