ESP8266 MCP3002 Driver

In an upcoming ESP8266 project I need to able to read some analog sensors in the range of 0.0 – 3.3 V and since the ADC that comes with ESP8266 is limited to 0-1 V range, it’s not suitable for my purposes. To solve this problem I’m going to use Microchip Technology Inc. MCP3002 which is a low-cost (less than 2.50 euros a piece) dual channel 10-bit A/D converter with an SPI interface. Unfortunately the ESP8266 SDK doesn’t provide a driver for SPI communications but luckily David Ogilvy (MetalPhreak) has done excellent investigation work with the ESP8266 SPI features and even written an SPI driver for ESP8266.

My ESP8266 MCP3002 driver utilizes David’s great SPI driver for reading the A/D conversion results from the MCP3002. As I suspect that others may be facing the limitations of ESP8266 ADC, and MCP3002 is probably quite common solution for adding additional ADC channels, I figured that I’d share my ESP8266 MCP3002 driver source codes. This was also an excellent opportunity to create my first GitHub project. So here goes: ESP8266 MCP3002 Driver @ GitHub

ESP8266 MCP3002 Driver in action

For testing purposes I wrote a simple program that reads both MCP3002 ADC channels and also the pseudo-differential values and prints them out to UART. From the hardware point of view, there’s simple a potentiometer attached to MCP3002 channel 0 to act as a voltage divider to simulate an analog sensor output at 0.0 – 3.3 V range. The MCP3002 is connected to ESP8266 HSPI port, i.e.

PortFunction
GPIO12Master In, Slave Out
GPIO13Master Out, Slave In
GPIO14Clock
GPIO15Chip Select

For reading ESP8266 prints, I use a method of redirecting ESP8266 stdout to its second UART which I have connected to a Raspberry Pi (GND and RXD pins on Raspberry Pi GPIO header). This allows me to receive the ESP8266 prints with simple screen /dev/ttyAMA0 115200 command.

ESP8266 MCP3002 driver example program output
The output of the driver test program. A potentiometer is being adjusted and its output voltage is sampled 1/second.
Posted in Electronics, General Tagged with: , ,
0 comments on “ESP8266 MCP3002 Driver
    1 Pings/Trackbacks for "ESP8266 MCP3002 Driver"
    1. […] Teemu Leskinen:ESP8266 MCP3002 Driver exabugs:ESP8266 (ESP-WROOM-02) でセンサーを扱う […]

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *