1

I'm using RFduino to do analogRead at pin 2 and pin 0. Pin 2 works perfectly, and I got the result. However, for pin 0 it returns all zero.

#include <RFduinoBLE.h>
static const int topPin = 2;
static const int bottomPin = 1;
int top;
int bottom;
void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 pinMode(topPin, INPUT);
 pinMode(bottomPin, INPUT);
}
void loop() {
 // put your main code here, to run repeatedly:
 RFduino_ULPDelay( SECONDS(0.01) );
 bottom = analogRead(bottomPin);
 top = analogRead(topPin);
 Serial.print(top);
 Serial.print(" ");
 Serial.print(bottom); 
 Serial.print("\n"); 
}

I double checked the wires and it's OK. I measured the voltage across pin 0 and it's 3.3V. How do I fix this problem? There's no shortage between pin 0 and 3.3V.

Edgar Bonet
45.1k4 gold badges42 silver badges81 bronze badges
asked Sep 7, 2016 at 20:06
8
  • 1
    I don't see any pin 0 read.. Also IIRC the analog pins on Arduino are aliased by A0, A1... rather than the number. Commented Sep 7, 2016 at 20:13
  • It's RFduino, a variation of Arduino. And yes, there's a typo in the code Commented Sep 7, 2016 at 20:25
  • 1
    Soo.. shouldn't it be A0, A2 rather than 0 and 2? Commented Sep 7, 2016 at 20:26
  • No. Pin 2 works perfectly. If it's A0, A2 it would be a compilation problem. Commented Sep 7, 2016 at 20:33
  • You don't have to set them as inputs with pinMode. It's my understanding that pinMode is for digital pins only. Comment out those pinMode lines and see if it works. Commented Sep 7, 2016 at 20:41

2 Answers 2

1

Without RFDuino specs handy, I'm guessing - but I think it's likely - that the A/D converter gets shut down in an ultra low power sleep and requires some amount of time to wake up. The mis-reading pin, pin 0, is the one your sketch reads immediately on waking. That read call probably takes long enough that the A/D wakes up by the time your read pin 2 so it gives a better reading.

Try switching the order in which you read the pins and see if pin 2 mis-reads if you try to read it immediately after waking. If it does, the cure may be as simple as a 10-100 uSec delay between waking and trying to read any analog data. I just pulled that number out of the air; you might start with a couple of milliseconds and see how low you can make it before you start to see errors, then double that amount.

answered Sep 7, 2016 at 20:32
1
  • Thanks for your confidence, but unless this actually worked, I think @edgar nailed this one. Commented Sep 8, 2016 at 11:43
0

I couldn't find an usable datasheet for the RFduino, seems like a very poorly documented board. But I found an enlightening comment in the source code of the RFduino library:

Only pins 1-6 is avaliable [sic] for using as ADC inputs

If you read the source, it is clear that calling analogRead() on an inappropriate pin is supposed to return 0.

answered Sep 8, 2016 at 7:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.