10K NTC Thermistor problem on the Giga R1

Hi everyone,

I'm having a problem with the readings I'm getting from a 10K sensor, or rather the processing of it.

When everything is wired up to a Mega2560 the output is fine. Using the Steinhart-Hart conversion to calculate. When I connect everything to the Giga R1 the end result seems to be double the temperature.

I've been trying to read up on analogReadResolution but the link to the page (found here) no longer works. I've tried various things like putting analogReadResolution(10); in the setup or loop after reading this and this.

From this page I gather the resolution for the Giga can be different, but after adding the line to set it to 10 it shouldn't be.

So either I'm doing it wrong, something else wrong, or trying to fix something that isn't broken.

Here are my numbers and code:


int ThermistorPin = A0;
int Vo;
float R1 = 10000;
float logR2, logR3, R2, R3;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
waterTemp1 = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
waterTemp2 = waterTemp1 - 273.15; //to Celsius

"the resolution can be changed (only for Zero, Due and MKR boards) using analogReadResolution()"

" **The default analogRead() resolution for these boards is 10 bits, for compatibility. You need to use analogReadResolution() to change it to a higher resolution."

is stated here and the Giga has ** behind it

(that answers my own question what the default is though)

So the problem is not the analogReadResolution ...... ?

They're on about audio applications, but there is
'Advanced Analog Redux', which gets you, for example (evidently) --

AN_RESOLUTION_16
https://docs.arduino.cc/tutorials/giga-r1-wifi/cheat-sheet/

The Arduino AdvancedAnalog library is designed to offer high performance DAC/ADC applications on boards based on the STM32H7 microcontroller.

I've written a simple sketch to run on the mega and the giga.

When connected to the mega I'm printing to serial temp values from 2 sensors, but also the value of Vo = analogRead(ThermistorPin);
On the mega this prints:

18:03:09.850 -> Temp 1=13 Temp 2=14
18:03:09.850 -> pin 1=412 pin 2=415

when running the same sketch on the giga I get

18:05:02.332 -> Temp 1=35 Temp 2=36
18:05:02.332 -> pin 1=626 pin 2=630

adding analogReadResolution(12); to the setup does quite a bit to the result. Now reading

18:10:01.909 -> Temp 1=4294967023 Temp 2=4294967023
18:10:01.909 -> pin 1=2510 pin 2=2528

adding analogReadResolution(9); gives me

18:15:33.343 -> Temp 1=3 Temp 2=4
18:15:33.343 -> pin 1=313 pin 2=315

but with this data I'm no closer to understanding the problem. Does the giga have an offset compared to the mega when both are running analogReadResolution(10);?

The mega should run at 10 but the analogReadResolution(); command is not supported so I could not test this with that line in the code for it.

I've looked at AdvancedADC.h but I don't see anything that helps me here. AdvancedDAC.h seems to deal with output only.

What are you expecting to see ?

ADC

To use this library for ADC applications, you must have a supported Arduino board and include the AdvancedAnalog library in your Arduino sketch. Here is a minimal example:

#include <Arduino_AdvancedAnalog.h>

AdvancedADC adc1(A0);

void setup() {
    Serial.begin(9600);

    // Initialize ADC with: resolution, sample rate, number of samples per channel, queue depth
    if (!adc1.begin(AN_RESOLUTION_16, 16000, 32, 64)) {
        Serial.println("Failed to start ADC!");
        while (1);
    }
}

void loop() {
    // Check if an ADC measurement is ready
    if (adc1.available()) {
        // Get read buffer
        SampleBuffer buf = adc1.read();

        // Print sample from read buffer
        Serial.println(buf[0]);

        // Release read buffer
        buf.release();
    }
}

On the Mega, if you connect a pot from Vcc to GND and set it about halfway you see an ADC reading around 512. If you do the same on the Giga, what do you read?

I am not expecting to see anything. When I found the giga and mega use the same default resolution I was looking for something that would tell me if the giga processes the input differently.

When I run the advanced ADC sketch with AN_RESOLUTION_16, AN_RESOLUTION_12 or AN_RESOLUTION_10 I'm getting the exact same readings as when I use analogReadResolution(x); respectively. The only difference is AN_RESOLUTION_9 does not compile where analogReadResolution(9) does.

The sample_rate, n_samples and n_buffers are variables I don't understand well enough to determine if they are relevant or not. After testing sketch alteration with changed values for these it does not affect the outcome at all.

On the Mega when I set it to 510, and transfer the wires to the Giga it reads 720... so that's interesting.

measuring 4.89 volts on the mega and 4.56 volts on the giga.

could it be something like 102.4 khz vs 144 khz ?

I'll dig into frequencies

I'm not at all familiar with the Giga or it's MCU, just wonder what it's AREF voltage is. 4.096 or 2.048 Volts maybe?

3.26

Let's see, if resolution were 1024 and you read 720, that would be 720 / 1024 * 3.26 = 2.29V, just about 1/2 the 4.56V your program said...?
What was the voltage across the pot?

hang on, it was 510 and 720, so that would be 1024 and 1450 give or take

sorry, I edited when I spotted an oversight.

so then 1450 / 1024 * 3.26 = 4.6 volt

about 60 seconds after I laid down in bed I think I had an eureka moment. If there is a relation between 1450 and 1024 I'll change the code for the calculation: Change 1023 in R2 = R1 * (1023.0 / (float)Vo - 1.0); to 1444...

so:

Vo = analogRead(ThermistorPin);
R2 = R1 * (1444.0 / (float)Vo - 1.0);
logR2 = log(R2);
waterTemp1 = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
waterTemp2 = waterTemp1 - 273.15; //to Celsius

and it works :smiley:

after running the numbers with 4.56 / 3.26 * 1024 I settled on 1432.

If I swap the sensors back and forth the readings are almost identical.

It works so I'm not complaining but I don't really understand why 1432 appears to be the magic number. Can anybody explain what the cause is?

Hi, I have a similar problem with reading the values from an accelerometer. All readings are shifted by 1.3V and I do not know why. I tried the same setup with an Arduino Uno R4 and the readings were ok. Maybe there is a reference inside the board which is not well done?
EDIT: I have find this on the cheatsheet of Arduino GIGA


The reference voltage is 3.3V

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.