Wio Terminal - InternalReference() - LM35 Temperature Sensor

Hello all,

I’m reading temperature from a LM35 CAZ (TO-92) sensor and displaying it to the LCD.
However, I’m running into 2 issues:

  1. When trying to use analogReference(INTERNAL), compiling fails with the Wio Terminal and says INTERNAL was not declared in this scope. How do I reference an internal voltage of 1.1v (or whatever other reference voltage available), if possible?

  2. Is there a way to easily print floats with two decimals to the LCD? It seems I may have to convert the decimals to INTs and then use drawNumber… suggestions?

#include <SPI.h>
#include <Seeed_FS.h>
#include "SD/Seeed_SD.h"
#include"seeed_line_chart.h" //include the library
#include "TFT_eSPI.h"
#include "Free_Fonts.h"

TFT_eSPI tft;
TFT_eSprite spr = TFT_eSprite(&tft);  // Sprite 

#define time_increment 1000
#define x1 20
#define y1 10
#define w1 200

#define sensorPin A0  

float sensorVal;
float voltage;
float temperature;
 
void setup() {
    Serial.begin(115200);

    analogReference(DEFAULT);
  
    // declare the analog pins as inputs...? not sure if necessary...
    pinMode(sensorPin, INPUT);
    
    tft.begin();
    tft.setRotation(3);
    tft.fillScreen(TFT_BLACK);
    tft.setFreeFont(FMB9); //bold, 9pt font
}
 
void loop() {
    // Read sensor values
    sensorVal = analogRead(sensorPin);

    // Convert sensor value to voltage
    voltage = sensorVal * (1100/1024.0);

    // Convert voltage to Celcius
    temperature = voltage / 10;

    // print values to serial monitor
    Serial.print(temperature);
    Serial.print(" \xC2\xB0"); // shows degree symbol
    Serial.println("C");

    // display values to LCD
    tft.drawString("Temp: ",x1, y1);
    tft.drawString("          ",w1,y1);
    tft.drawNumber(temperature,w1,y1);
    
    delay(time_increment);
}

Can you try these!

Configures the reference voltage used for analogue input . Arduino SAMD Boards (Zero, etc.)

  • AR_DEFAULT: the default analog reference of 3.3V
  • AR_INTERNAL: a built-in 2.23V reference
  • AR_INTERNAL1V0: a built-in 1.0V reference
  • AR_INTERNAL1V65: a built-in 1.65V reference
  • AR_INTERNAL2V23: a built-in 2.23V reference
  • AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference

src: https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/

2 Likes

The Arduino print routines are very lousy.
You can use sprintf(…) with a format “%5.2f” or similar and then print the created string.

2 Likes

You nailed it. I was using the wrong types!

Currently using:

analogReference(AR_DEFAULT);

voltage = sensorVal * (3300/1024.0);

And it appears to be reading the correct temperature now, thank you!

Your advice was exactly what I was looking for. This is a much cleaner implementation than what I would’ve done.

Thank you for the input!

I like the <Arduino_DebugUtils.h> because they allow exactly this.
Debug.print(DBG_VERBOSE, “%d: v=%f i=%f”, i, voltage[i], current[i]);