Read and display temperature from Raspberry Pi PICO

Introduction

In this project we will read the temperature from the in built temperature sensor and then display it on OLED display.

This is a very basic project and help you in understanding how to use Pi PICO. For details on how to setup and start using Pi Pico visit my previous blog here.

Parts Required

  1. Raspberry Pi PICO
  2. OLED display
  3. Few connecting wired
  4. Breadboard
  5. Some patience

Connection Diagram:

Ground pin of OLED is connected to Ground pin 33 of Pico

VCC pin of OLED is connected to pin 36 (3.3v) of  Pico

SCL and SDA of OLED is connected to pin 27 (GP21) and pin 26(GP20) of Pico respectively [ refer the image below]

Program used is as follows

import machine
import utime
from machine import ADC
from time import sleep
from ssd1306 import SSD1306_I2C

sensor_temp = ADC(4) 
conversion_factor = 3.3 / (65535)

sda=machine.Pin(20)
scl=machine.Pin(21)

i2c=machine.I2C(0,sda=sda,scl=scl,freq=400000)

oled=SSD1306_I2C(128,64,i2c)

oled.text('Welcome to',0,0)
oled.text('DIGITAL LAB',0,20)
oled.show()
utime.sleep(4)

while True:
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721

tstring=str(temperature)
print(temperature)
oled.fill(0)
oled.show()
oled.text('Digital Lab',0,0)
oled.text('Temp = '+ tstring,0,20)
oled.show()
utime.sleep(2)

Refer the following video for an overview.

Let me know how it goes for you. Next we will cover connecting it to Azure using esp8266 or any other wifi board.

One comment

  1. hello, thanks for the nice work, but problem about this “conversion_factor = 3.3 / (65535)” Traceback (most recent call last):
    File “”, line 23
    SyntaxError: invalid syntax. please help

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.