Code Monkey home page Code Monkey logo

adafruit_mcp3008's Introduction

Adafruit_MCP3008 Build StatusDocumentation

This is the Adafruit MCP3008 - 8-Channel 10-Bit ADC With SPI Interface Library.

Tested for the following boards using pins shown.

MCP3008 UNO FEATHER HUZZAH1 FEATHER 32u4 FEATHER M0
VDD 5V 3V 3V 3V
VREF 5V 3V 3V 3V
AGND GND GND GND GND
CLK 13 SCK (14) SCK SCK
DOUT 12 MI (12) MISO MISO
DIN 11 MO (13) MOSI MOSI
CS 10 any2 (15) any2 any2
DGND GND GND GND GND

1also works for non-Feather HUZZAH, use (XX) pins

2use any available digital pin

adafruit_mcp3008's People

Contributors

caternuson avatar evaherrada avatar hoffmannjan avatar ladyada avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_mcp3008's Issues

missing file ?

Hi !

I get a fatal error with this comment :

"...libraries\Adafruit_MCP3008-master/Adafruit_MCP3008.h:22:32: fatal error: Adafruit_SPIDevice.h: No such file or directory"

??
thanks in advance

SPI CLOCK

Thank you for this library, works perfectly ; however, I would like to report an observation which seems to allow an improvement.

Indeed, I was initially very disappointed by the measurement speeds.
I compare below 4x6 measurement cycles:

  • arduino NANO ADC pins : 600 microseconds
  • ESP32 ADC1 pins : 1100 us (!)
  • MCP3008 (on ESP32) : 800 us

What I wanted to point out is that by only changing the SPI clock => spiCLK=8000000 ;
I get in combination with the ESP32 a much better time of 330us. Without noticing that measures are less accurate.

(BUT MAYBE IS THERE A DISADVANTAGE I DIDN'T (yet) DETECT ??)

Software SPI Version - Missing last bit

The code which reads a value from the ADC via a software SPI port seems to be missing a bit. The maximum value reported is 512. Only 16 bits (Including the dummy bits used to read back the result) are sent to the ADC, but the datasheet calls for one more - The hardware SPI version sends a total of 24 bits.
https://github.com/adafruit/Adafruit_MCP3008/blob/master/Adafruit_MCP3008.cpp#L150-L167

  • Arduino board: ESP32 (TTGO T-Display)

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.12

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

  1. Use the library with the software SPI constructor
  2. Read the ADC on any channel
  3. The result will be between 0 and 511

Here's a version which I used to test the theory that it is just missing the last bit - I hacked in the last bit after the loop:

    uint16_t outBuffer, inBuffer = 0;

    digitalWrite(cs, LOW);

    // 5 command bits + 1 null bit + 10 data bits = 16 bits
    outBuffer = command << 8;
    for (int c = 0; c < 16; c++) {
      digitalWrite(mosi, (outBuffer >> (15 - c)) & 0x01);
      digitalWrite(sck, HIGH);
      digitalWrite(sck, LOW);
      inBuffer <<= 1;
      if (digitalRead(miso))
        inBuffer |= 0x01;
    }

    digitalWrite(mosi, 0x00);
    digitalWrite(sck, HIGH);
    digitalWrite(sck, LOW);

    inBuffer <<= 1;
    if (digitalRead(miso))
      inBuffer |= 0x01;

    digitalWrite(cs, HIGH);

    return inBuffer & 0x3FF;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.