Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
Changing analog reference voltage in Spresense
-
Hi,
I tried to change the analog reference voltage to 3.3v by connecting the AREF pin to 3.3v output on the extension board. (JP1 is set to 3.3v)
And when I supply 3.3v input to analog pin (I used A5), analog read should ideally return me 1023 or near values right?
But I see values around 675 which is right with 5v reference voltage. But I am using 3.3v reference which should ideally give me 1023. So is my reference voltage not changed? If not how to change it?
Below is the attached code:
#define AN_PIN A5
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
analogReference(3.3);
}void loop() {
// put your main code here, to run repeatedly://Read the analog output from the Anemometer
float sensorValue = analogRead(AN_PIN);Serial.print("Digital value: ");
Serial.println(sensorValue);float analogVoltage = (float)(sensorValue * 3.3) / 1023;
Serial.print("Analog value: ");
Serial.println(analogVoltage);delay(1000);
}BR
Navaneeth -
analogReference() is not supported. The reference voltage for analog input use for Spresense is fixed.
You could use analogReadMap() function
Please refer to:
https://developer.sony.com/develop/spresense/docs/arduino_developer_guide_en.html#_functional_differences.
.
."analogReadMap() [extended]
The analogRead() function gets a signed 16-bit value (signed short) from the ADC and maps it to a value between 0 and 1023 using the map(value, fromLow, fromHigh, toLow, toHigh) function.The analogReadMap() function allows you to change the fromLow and fromHigh used for the map() function. Also, if min and max of analogReadMap() are set to the same value, the analogRead() function will return the raw ADC value without any conversion by map()."
-
@CamilaSouza Thanks for the answer. In that case what is the role of AREF in the extension board?
BR
Navaneeth -
@CamilaSouza I tried to use the analogReadMap() API but I see the values are not mapped correctly.
Only the max value is being mapped to 1023 but not any other values. Attaching the output image for reference.
Below is the code:
#define AN_PIN A5
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}void loop() {
// put your main code here, to run repeatedly:analogReadMap(AN_PIN,0,664);
float sensorValue = analogRead(AN_PIN);Serial.print("Digital value: ");
Serial.println(sensorValue);delay(1000);
} -
Hey, @NavaneethRao-2
The numbers analogReadMap takes are the raw ADC values, without any conversion.
(From –32768 to 32767)To get the values to match 0 and 3.3V in my board I used first analogReadMap(AN_PIN, 0, 0) and printed the raw values.
0 was -32448 and 3.3 was 9408.Full code:
// the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { analogReadMap(A0, -32448, 9408); // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1000); // delay in between reads for stability }
-
Also
About AREF.
It's an output and it changes depending on whether your jumper is at 3.3V or 5V.It is generally used as an extra voltage output.
-
@CamilaSouza Thanks a lot.