Author Topic: How to use Aref?  (Read 2865 times)

ChenWXKenny

  • RFduino Jr. Member
  • **
  • Posts: 39
  • Karma: +1/-0
    • View Profile
How to use Aref?
« on: August 03, 2014, 08:45:33 PM »
Hi,

I am trying to provide a stable voltage (3.3V?) to RFduino as a voltage reference for analogRead as i noticed the analogRead value will fluctuate as i change the value of power supplied to RFduino (1.8V - 3.6V).

I am using a battery to supply the RFduino and therefore i need a stable voltage for to ensure analog value stay true regardless of battery voltage.

How do i make use of Aref on GPIO 0?

Thanks in advance:)

tolson

  • Global Moderator
  • *****
  • Posts: 861
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: How to use Aref?
« Reply #1 on: August 03, 2014, 09:49:24 PM »

Hi Chen,
The discussion for that is here...

http://forum.rfduino.com/index.php?topic=265.msg962#msg962

Alexdurino

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: How to use Aref?
« Reply #2 on: April 18, 2015, 03:19:41 AM »
Hi Chen.
Were you able to solve the problem?
I'm currently facing a similar problem as I want to provide an external voltage reference through the Aref pin. With the Arduino this works perfectly through the analogReference(EXTERNAL) command. However, due to size limitations of my project I wanted to do the same with the RFduino. The link to the other discussion unfortunately doesn't help me, especially since it doesn't deal with the issue of making use of the Aref on GPIO0. A Rfduino documentation on that topic I can't find either.

My testing code at the moment looks like this:

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

const int refPin = 0;
const int sensorPin1 = 1;
const int sensorPin2 = 2;
int sensorValue1;
int sensorValue2;

void setup() {
  analogReference(EXTERNAL);
  pinMode(refPin, INPUT);
  pinMode(sensorPin1, INPUT);
  pinMode(sensorPin2, INPUT);
  RFduinoBLE.advertisementData = "sensorValue1";
  RFduinoBLE.advertisementData = "sensorValue2";
  RFduinoBLE.begin();
  Serial.begin(4800);
}


void loop() {
 
  RFduino_ULPDelay( SECONDS(0.5) );
 
  sensorValue1 = analogRead(sensorPin1);
  sensorValue2 = analogRead(sensorPin2);
 
  Serial.print("Value1 : ");
  Serial.print(sensorValue1);
  Serial.print("Value2 : ");
  Serial.println(sensorValue2);
 
 
  RFduinoBLE.send(sensorValue1);
  RFduinoBLE.send(sensorValue2);
 
}

Thanks for any help.

jklein

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: How to use Aref?
« Reply #3 on: July 16, 2016, 01:45:53 PM »
I was also struggling with the problem of trying to accurately use an external analog reference.  Numerous google searches and this was the only form that popped up and seemed unresolved.  You've likely solved the problem now or moved on but I thought it would be useful to post what worked for me so that others don't waste as much time as I did.

To make things easy, I switched to AREF1 which is GPIO6 on the RFduino.  If you use AREF0 then you have to disconnect the RFduino module from the programmer.  After I switched to AREF1 I noticed that the ADC was definitely using GPIO6 as the reference pin, however the values were always off by ~2/3.  It was only after I found the analogSelection() function and specified no rescaling (AIN_NO_PS) did it start working.  I had previously thought that maybe the analogReadResolution() was defaulting to something like 8 bits and therefore specified that also, but that wasn't the problem.

//code snippet that I use to set everything up
    analogReadResolution(10);
    analogReference(EXTERNAL);
    analogSelection(AIN_NO_PS);   
    externalReference(AREF1);

Hope this helps others!

MaMikee

  • RFduino Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: How to use Aref?
« Reply #4 on: November 20, 2016, 04:33:16 PM »
BOY AND HOW!  I ran into the same thing and knew it had to be configuration as all voltages were good.  Many searches later I found your post so I only pissed off an hour or so.  THANK YOU

Why can't RFDigital update their user manuals with key things like this?  Too busy being leap-frogged by competition?  I'd say if your documentation isn't first rate your product cannot be.

 

anything