Raspberry Pi Pico -- Inbuilt Temperature Sensor Measurement

by PugazhM in Circuits > Raspberry Pi

117 Views, 0 Favorites, 0 Comments

Raspberry Pi Pico -- Inbuilt Temperature Sensor Measurement

Circuit_V01.jpeg

This experimentation uses Python programming, to measures the inbuilt temperature sensor in Celsius format and then converts the reading into either Fahrenheit, or Kelvin or Rankine. Displays the different temperature format on 16x2 LCD at 5 seconds interval

Visit the "VESZLE - The Art Of Electronics" you tube channel for further information and videos.

https://www.youtube.com/channel/UCY4mekPLfeFinbQHp...

Inbuilt Temperature Sensor


Abstract

The Raspberry Pi Pico is a tiny, fast, and versatile board built using RP2040 features a dual-core Arm Cortex-M0+ processor with 264KB internal RAM and support for up to 16MB of off-chip Flash. It provides wide range of flexible I/O options includes I2C, SPI, and uniquely Programmable I/O (GPIO) pins.

The RPi Pico has an integrated inbuilt temperature sensor, which is connected to analog pin 4.

This experimentation uses Python programming, to measures the onboard temperature sensor in Celsius format and then converts the reading into either Fahrenheit, or Kelvin or Rankine. Displays the different temperature format on 16x2 LCD at 5 seconds interval.

Reference

“Raspberry Pi Pico, Getting Started on Board Blink LED” Instruct-able / You-tube by PugazhM

https://www.instructables.com/Raspberry-Pi-Pico-G...

“Raspberry Pi Pico -- 16x2 LCD, 4Bit Mode Interface, BCD Counter” Instruct-able / You-tube by PugazhM https://www.instructables.com/Raspberry-Pi-Pico-G...

https://www.instructables.com/Raspberry-Pi-Pico-G...

The “lcd_4bit_mode.py” driver library

Component

Component.jpg

Raspberry Pi Pico

Micro USB Cable

16x2 LCD Keypad Shield

Schematic -- 4Bit Mode - 16x2 LCD Connection

Circuit_V01.jpeg
PinConnectionTable.jpg

The 16x2 is very common type LCD, with two rows.

The “16x2 LCD Keypad shield” can be connected to Raspberry Pi Pico GPIO pins (GPIO0--GPIO6). LCD operates at 4-bit data mode as given in above circuit.

If the display is not visible, adjust the Contrast pot (1K), to make it visible.

The above table describes the 16x2 LCD -- Shield – RPi Pico pin connections.

RPi Pico Inbuilt Temperature Sensor

The RPi Pico has four ADCs. Three ADC pins (A0 to A2) are exposed to external pins. The fourth ADC (A3) is internally connected to the inbuild temperature sensor. MicroPython assigns the fourth ADC pin as “machine.ADC(4)”.

The ADCs are 3.3VDC referenced with 12-bit accuracy.

This means 3.3VDC equivalent to 4095 hex vale.

MicroPython reads the ADC value in 16-bit format. MicroPython upscales 12 bit into 16 bits.

Calculate the ADC measurement voltage by applying following method

read_voltage=16Bit_ADC_VALUE*(3.3 ÷ 65535)

The RPi Pico datasheet states that, 27 degrees Celsius delivers ADC voltage of 0.706 Volt, and then each addition degree Celsius the voltage is getting reduces by 1.721 mVolt or 0.001721Volts

This yields the following method for calculating the T(°C).

T(°C)=27-((read_voltage-0.706)÷0.001721)

The calculated Celsius is converted into Fahrenheit, Kelvin and Rankine scale are given below.

Fahrenheit: - T(°F) = T(°C) × 9/5 + 32

Kelvin: - T(K) = T(°C) + 273.15

Rankine: - T(°R) = (T(°C) + 273.15) × 9/5

Python Program – Inbuilt Temperature Sensor Measurement

As referenced above, download “lcd_4bit_mode.py” driver library.

Open the RPi Pico as drive, and then copy the library into root directory

LCD is initialized and welcome screen of “RPi Pico Onboard Temp Sensor” is displayed in two rows, for about 5 seconds.

The temperature values are read as voltage and converted into Celsius, Fahrenheit, Kelvin and Rankin

Each converted values are displayed at LCD screen for about 5 Seconds.

The measurement cycle repeats at 20 Seconds interval.

'''<br> Demonstrates RPI Pico onboard temperature sensor measurement
 Method for conversion of Celsius into Fahrenheit, Kelvin and Rankin
 Displays the reading on 16x2 LCD at 5 seconds interval
 
 4Bit mode LCD interface on Instructable and Youtube:
 https://www.instructables.com/Raspberry-Pi-Pico-16x2-LCD-4Bit-Mode-Interface-BCD/
 https://www.youtube.com/channel/UCY4mekPLfeFinbQHpf9QcHg
   
 * The Raspberry Pi Pico pin connections for 16x2 LCD, for 4Bit mode are given below:
 
 # LCD Power Pins
 * 16x2 LCD VCC pin to VBUS
 * 16x2 LCD GND pin to GND
 
 # LCD Data Pins
 * 16x2 LCD D4 pin to GPIO0
 * 16x2 LCD D5 pin to GPIO1
 * 16x2 LCD D6 pin to GPIO2
 * 16x2 LCD D7 pin to GPIO3
 
 # LCD Control Pins
 * 16x2 LCD RS pin to GPIO4
 * 16x2 LCD ENABLE pin to GPIO5
 * 16x2 LCD BACK LIGHT pin to GPIO6
  
 Name:- M.Pugazhendi
 Date:-  17thJul2021
 Version:- V0.1
 e-mail:- muthuswamy.pugazhendi@gmail.com
'''
import machine
# Import lcd_4bit_mode
import lcd_4bit_mode
# Import time
import time
# Initialize LCD pins
RS = machine.Pin(4,machine.Pin.OUT)
ENABLE = machine.Pin(5,machine.Pin.OUT)
BACK_LIGHT = machine.Pin(6,machine.Pin.OUT)
D4 = machine.Pin(0,machine.Pin.OUT)
D5 = machine.Pin(1,machine.Pin.OUT)
D6 = machine.Pin(2,machine.Pin.OUT)
D7 = machine.Pin(3,machine.Pin.OUT)
display = lcd_4bit_mode.LCD16x2(RS,ENABLE,BACK_LIGHT,D4,D5,D6,D7)
# Initialize onboard temperature sensor
sensor_temp = machine.ADC(4)
display.BackLightOn()
# Line one string
display.WriteLine('RPi Pico Onboard',1)
# Line two string
display.WriteLine('  Temp Sensor',2)
time.sleep(5)
conversion_factor = 3.3 / (65535)
while True:
    # Clear Screen
    display.ClearScreenCursorHome()
    
    reading = sensor_temp.read_u16() * conversion_factor
    print("RAW = %f" % reading)
    temperature = 27 - (reading - 0.706)/0.001721
    # Debug message
    print(temperature)
 
    #Display Celsius into LCD
    display.WriteLine('Celsius',1)
    display.WriteLine('Temp = ' +"{:0.2f}".format(temperature)+ " \337C",2)
    #Wair for five seconds
    time.sleep(5)
    
    # Display Fahrenheit into LCD
    # T(°F) = T(°C) × 9/5 + 32
    display.WriteLine("                ",1)
    display.WriteLine('Fahrenheit',1)
    f = ( temperature * 1.8 ) + 32.0
    display.WriteLine("                ",2)
    display.WriteLine('Temp = ' +"{:0.2f}".format(f)+ " \337F",2)
    #Wair for five seconds
    time.sleep(5)
    
    # Display Kelvin into LCD
    # T(K) = T(°C) + 273.15
    display.WriteLine("                ",1)
    display.WriteLine('Kelvin',1)
    f = temperature + 273.15
    display.WriteLine("                ",2)
    display.WriteLine('Temp = ' +"{:0.2f}".format(f)+ " K",2)
    #Wair for five seconds
    time.sleep(5)
    
    # Display Rankin into LCD
    # T(°R) = (T(°C) + 273.15) × 9/5
    display.WriteLine("                ",1)
    display.WriteLine('Rankin',1)
    f = (temperature + 273.15) * 1.8
    display.WriteLine("                ",2)
    display.WriteLine('Temp = ' +"{:0.2f}".format(f)+ " \337R",2)
    #Wair for five seconds
    time.sleep(5)

Conclusion

Conclusion.jpg

The project is successfully completed with Raspberry Pi Pico, inbuilt temperature sensor and 1602 LCD Keypad shield

The inbuilt temperature is read and then converted into Celsius, Fahrenheit, Kelvin and Rankin format and displayed at LCD screen at 20 Seconds interval

Video Links

Result_Video.mp4

Visit "VESZLE - The Art Of Electronics" you tube channel for further information and videos.

https://www.youtube.com/channel/UCY4mekPLfeFinbQH...

If you enjoyed this instruct-able, then make sure you subscribe

Inbuilt temperature sensor video link