Core Electronics Forum

PiicoDev data output to 1602 LCD

G’day,

Need help with data output from my PiicoDev Tempature and Light Sensors to my lcd 1602 display. I have it wired up and working with “Hello World”.

Being a complete biginner with both RPI-PICO and MicroPython, My setup is base on TechToTinker’s blog 002 - Raspberry Pi Pico: LCD 4-bit Mode ~ TechToTinker

Michael
silvergull
Busselton Western Australia

1 Like

Hi Michael,

You’ve already done the hard part! (The display). Apart from moving any setup code from the display example you’re using you could use something like this:

    from tmp117 import *
    from utime import sleep_ms

    mySensor = tmp117()

    while True:
        # Read and print the temperature in various units
        tempC = mySensor.readTempC() # Celsius
        tempF = mySensor.readTempF() # Farenheit
        tempK = mySensor.readTempK() # Kelvin
        
        tempStringC = str(tempC) # convert temperature number to string
        lcd.clear()
        lcd.move_to(1,1)

        lcd.putstr("It's " + tempStringC + "°C")
        
        sleep_ms(1000)

Once you’ve added your lcd setup stuff to the beginning of that, it should just work!

Keen to see if it works or we need to do some troubleshooting :slight_smile:
James

2 Likes

G’day James,

Thanks for the info.

Now I off and running on My Weather Station.

Thanks Again

Michael

Silvergull

Busselton Western Australia

1 Like

G’day James,

lcd.putstr("It’s " + tempStringC + “°C”)

The above line outputs 4 blank blocks, also if I shorten this line to (It’s ") same result??

I agree with the line’s logic, but some where “tempStringC” is getting corrupted.

Michael

1 Like

G’day James,

Here is Code:

# Weather Station Tempature Output
from machine import Pin, Timer
from gpio_lcd import GpioLcd
from tmp117 import *
from utime import sleep_ms

# Flash Pico LED
led = Pin(25, Pin.OUT)
LED_state = True
tim = Timer()

def tick(timer):
    global led, LED_state
    LED_state = not LED_state
    led.value(LED_state)

tim.init(freq=1, mode=Timer.PERIODIC, callback=tick)


# Create the LCD object
lcd = GpioLcd(rs_pin=Pin(8),
              enable_pin=Pin(9),
              d4_pin=Pin(10),
              d5_pin=Pin(11),
              d6_pin=Pin(12),
              d7_pin=Pin(13),
              num_lines=2, num_columns=16)

mySensor = tmp117()

while True:

        # Read and print the temperature in various units

        tempC = mySensor.readTempC() # Celsius

        tempF = mySensor.readTempF() # Farenheit

        tempK = mySensor.readTempK() # Kelvin
     
        tempStringC = str(tempC) # convert temperature number to string

        lcd.clear()

        lcd.move_to(0,0)
        
        print("It's " + tempStringC + "°C") #### test if tempString is valid
              
        lcd.putstr("It's " + tempStringC + "°C")
                    
        sleep_ms(1000)

####End of Code####

Code flashes Pico LED
Sets up LCD
Prints out Temp in Thonny
Clears the LCD and prints out 4 full cursor blocks not the Temp :frowning:

Michael
silvergull
Busselton Western Australia

1 Like

Could be character encoding? Unicode vs Ascii?

Looks like this bit of info is relevant:

See also: Converting Between Unicode and Plain Strings - Python Cookbook [Book]

Try getting rid of the degrees (°) symbol and the apostrophe (’) symbol. Also, take the LCD out of the mix and see if it’s writing data back correctly via a REPL.

The library only supports Ascii characters 32-127 (basically upper and lowercase letters, plus a few other common characters).
http://www.asciitable.com/

It might be some ungraceful handling of unknown characters by that LCD library.

1 Like