Things Plus SAMD51, need analogReference() functionality

I want to give an external analog reference for thermistor wiring.

In Arduino Uno, there is a dedicated pin “AREF” for this purpose but how can I achive this functionality in Things Plus SAMD51?

I have below queries:

  • Which pin on Things Plus SAMD51 should I use for external analog reference.
  • Inside **void setup()**, I am using a function **analogReference(AR_DEFAULT)** , will this configure the designated analog reference pin to 3.3 volt
  • Code given below gets compiled successfully

    #include <math.h>
    
    #define therm_pin A0
    float T_approx;
    
    float V_0 = 3.3; // voltage reference
    
    // first resistance value for voltage divider
    float R_1 = 220000.0;
    // fit coefficients
    float a = 283786.2;
    float b = 0.06593;
    float c = 49886.0;
    
    int avg_size = 10; // averaging size
    
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
      pinMode(therm_pin,INPUT);
    
      // set analog reference to read AREF pin
      analogReference(AR_DEFAULT);
    }
    
    void loop() {
      
      // loop over several values to lower noise
      float T_sum = 0.0;
      for (int ii;ii<avg_size;ii++){
        // read the input on analog pin 0:
        int sensorValue = analogRead(therm_pin);
        // Convert the analog reading (which goes from 0 - 1023) to voltage reference (3.3V or 5V or other):
        float voltage = (sensorValue/1023.0)*V_0;
    
        // this is where the thermistor conversion happens based on parameters from fit
        T_sum+=(-1.0/b)*(log(((R_1*voltage)/(a*(V_0-voltage)))-(c/a)));
      }
      
      // averaging values from loop
      T_approx = T_sum/float(avg_size);
    
      // readout for Celsius and Fahrenheit
      Serial.print("Temperature: ");
      Serial.print(T_approx);
      Serial.print(" (");
      Serial.print((T_approx*(9.0/5.0))+32.0);
      Serial.println(" F)");
      
      delay(500);
    }
    

    It looks like there’s one @ PA03 for VREFA tied to VDDA, and another VREFB @ A3

    https://cdn.sparkfun.com/assets/8/2/1/d … us_v10.pdf

    (and a third if you want more!)

    Thanks for a quick reply! :slight_smile:

    I do not know, how to call any of these specific pins in Arduino IDE?

    Will using “analogReference(AR_DEFAULT)” as below, enable VREFA?

    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
      pinMode(therm_pin,INPUT);
    
      // set analog reference to read AREF pin
      analogReference(AR_DEFAULT);
    }
    

    I also do not see PA03 available here https://cdn.sparkfun.com/assets/c/c/4/3 … v01-01.pdf

    These pins are multiplexed and for a TQFP/QFN 64 package, “Table 6-1.” at page 32 in https://cdn.sparkfun.com/assets/0/0/5/9/2/60001507C.pdf provides some information but to be honest, I do not know how to achieve this in Arduino IDE.

    Could you please help here little bit please!