Author Topic: Faster analogRead via external ADC  (Read 8273 times)

jesse

  • RFduino Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Faster analogRead via external ADC
« on: November 28, 2014, 11:27:36 AM »
Fast analogReads using the MCP3201.  Ebay item: http://www.ebay.com/itm/141457779249

Here's a tutorial for getting started (with an Uno): http://www.speedlimit88.com/arduino/spi_adc/



SPI Pins are:
SS/CS -> GPIO6
MOSI -> GPIO5
MISO -> GPIO3
SCK -> GPIO4

Code: [Select]
#include <SPI.h>

const int chipSelectPinADC = 6;
unsigned int result = 0;
byte inByte = 0;

void setup(){
  Serial.begin(921600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  //SPI.setClockDivider(SPI_CLOCK_DIV2);
  pinMode(chipSelectPinADC, OUTPUT);
  digitalWrite(chipSelectPinADC, HIGH);
}

void loop(){
  digitalWrite(chipSelectPinADC, LOW);
  result = SPI.transfer(0x00);
  result = result << 8;
  inByte = SPI.transfer(0x00);
  result = result | inByte;
  digitalWrite(chipSelectPinADC, HIGH);
  result = result >> 1;
  result = result & 0b0000111111111111;
  //result = map(result,0,4095,0,255);
  Serial.println(result);
  delay(1000);
}



The max speed is around 40,000 reads per second.  The analogRead function tops out at 13,000 reads per second.
« Last Edit: November 28, 2014, 11:31:09 AM by jesse »

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: Faster analogRead via external ADC
« Reply #1 on: November 30, 2014, 01:32:31 PM »
Won't it create a bottleneck when received by the RFDuino? wouldn't it just be simpler to send it directly by bluetooth with a bluetooth dongle without an arduino?

I'm just thinking, the rfduino would have to receive that data and then send it back out while doing other stuff can create a bottleneck unless of course I'm just thinking wrong...

Nice contribution tho!

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Faster analogRead via external ADC
« Reply #2 on: November 30, 2014, 02:15:35 PM »
Hi maverik0106,

I don't know why he is showing the UNO hookup picture. He is describing hooking up a RFduino in it's place. Perhaps replace the picture with a Fritzing drawing showing RFduino hook up instead would be more useful.

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: Faster analogRead via external ADC
« Reply #3 on: December 02, 2014, 06:51:03 AM »
No, I do understand that he's describing a hookup with the RFDuino... I'm guessing he just used the Arduino UNO as a "related" image... since I don't think there's a fritzing image for RFDuino (or I haven't found one either)...

but using an ADC to read analog values and send it to another ADC (slower) would that really work faster reads? that's an interesting theory...

Not one I'm convinced but will have to get that chip and test...

bsiever

  • RFduino Full Member
  • ***
  • Posts: 89
  • Karma: +4/-0
    • View Profile
Re: Faster analogRead via external ADC
« Reply #4 on: December 02, 2014, 07:43:36 AM »
Slightly off-topic, but here's the thread with a link to the Fritzing part for an RFduino:
http://forum.rfduino.com/index.php?topic=257.msg793#msg793

maverik0106

  • RFduino Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: Faster analogRead via external ADC
« Reply #5 on: December 03, 2014, 09:14:07 AM »
Oh awesome! I can definitely use that!

Thanks a lot!