0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RasPi Pico で I2C LCD表示する

Posted at

Raspberry Pi Picoを買ったのでいじってみることにした
手元にある秋月電子から買ったI2C小型キャラクタLCDモジュールを接続し、Picoの温度センサを表示してみる

開発環境は、mac bookPro Monterey に Thonnyをインストールして行った
Pico の初期設定は省略する
I2C接続小型キャラクタLCDモジュール 8x2行
AQM0802A-RN-GBW
ST7032i

[Pico]
SDA:GP6
SCL:GP7

----- main.py -----
from machine import Pin
from machine import I2C
import time

class st7032i:
LCD_RS_CMD = 0x00
LCD_RS_DATA = 0x40
LCD_CMD_CLEAR = 0x01
LCD_CMD_HOME = 0x03
lcd_bus = 0
my_id = 1
my_freq = 400000
my_sda = Pin(6)
my_scl = Pin(7)
my_addr = int(62)
i2c = I2C

def __init__(self):
    cmd1 = [b'\x38',b'\x39',b'\x14',b'\x70',b'\x56',b'\x6c']
    cmd2 = [b'\x38',b'\x0d',b'\x01']
    self.i2c = I2C(self.my_id, freq=self.my_freq, sda=self.my_sda, scl=self.my_scl)
    addr = self.i2c.scan()
    self.my_addr = [int(n) for n in addr]
    print (self.my_addr[0])
    for order in cmd1:
        self.i2c.writeto_mem(self.my_addr[0], self.LCD_RS_CMD, order)
        time.sleep(0.2)
    for order in cmd2:
        self.i2c.writeto_mem(self.my_addr[0], self.LCD_RS_CMD, order)
        time.sleep(0.2)
    
def char(self, y, x, msg):
    dat = 0x80 + (0x40 * y) + x
    byte = dat.to_bytes(1,'littele')
    #dat = b'\x80'
    self.i2c.writeto_mem(self.my_addr[0],self.LCD_RS_CMD,byte)
    for order in msg:
        self.i2c.writeto_mem(self.my_addr[0],self.LCD_RS_DATA, order)
        #time.sleep(0.2)

if name == 'main':
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
led = Pin(25, Pin.OUT)
#i2c = I2C(1,freq=400000,sda=Pin(6),scl=Pin(7))
#print(i2c.scan())
st = st7032i()
msg = "RPi Pico"
st.char(0, 0, msg)

while True:
  led.value(1)
  time.sleep(0.5)
  led.value(0)
  time.sleep(0.5)
  
  reading = sensor_temp.read_u16() * conversion_factor
  temperature = 27 - (reading - 0.706)/0.001721
  msg = "%3.2f" % temperature
  st.char(1,2, msg)
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?