2025年10月20日月曜日

積み残し Raspberry Pi cf Pico W aqm0802

-------------raspberry pi Blynk(PICOWは成功ずみ)------未踏------------------------

https://docs.sunfounder.com/projects/raphael-kit/ja/latest/python/play_with_python.html :: blynk

ーーーーーーーーーーーーーーーーーーーーー

https://randomnerdtutorials.com/raspberry-pi-apache-mysql-php-lamp-server/

rootはpswd:rootにした cf sqlite3も入れた

ーーーーーーーーーーーーーーーーーーーーーーーーーー

 https://philkitty.hateblo.jp/entry/2023/09/05/213011 aqm1602のコードだが0802でも動いた


from machine import Pin, I2C
import time

# I2C の設定(GPIO16 端子を SDA, GPIO17 端子を SCL として使用、クロック 100kHz)
i2c = I2C(0,freq=100000,scl=Pin(17),sda=Pin(16))
# AQM1602 I2C デバイスのアドレス,AQM0802と一緒だったのでうごいた!
addr=0x3e
buf=bytearray(2)
# LM73 I2C デバイスのアドレス これは絶版
LM73_addr=0x4c
LM73_buf=bytearray(2)


# ************************************************************************/
#  AQM1602へコマンド送信
# ************************************************************************/
def write_cmd(cmd):
    buf[0]=0x00
    buf[1]=cmd
    # 7ビットアドレス 0x3e のペリフェラルに2バイトを書き込みます
    i2c.writeto(addr,buf)

# ************************************************************************/
#  AQM1602へデータ書き込み
# ************************************************************************/
def write_char(char):
    buf[0]=0x40
    buf[1]=char
    i2c.writeto(addr,buf)

# print 関数の名前を変更
def custom_print(str):
    for c in str:
        write_char(ord(c))
        

def LCD_cursor(x,y):
    #1段目に書き込み*/
    if y==0:
        write_cmd(0x80+x)
    #2段目に書き込み*/
    if y==1:
        write_cmd(0xc0+x)

def LCD_clear():
    buf[0]=0x00
    buf[1]=0x01
    i2c.writeto(addr,buf)
    time.sleep(0.001)

def LCD_home():
    buf[0]=0x00
    buf[1]=0x02
    i2c.writeto(addr,buf)
    time.sleep(0.001)

# ************************************************************************/
#  AQM1602の初期化設定
# ************************************************************************/
def LCD_init():
    orders = [b'\x38', b'\x39', b'\x14', b'\x73', b'\x56', b'\x6c',b'\x38', b'\x0c', b'\x01']
    time.sleep(0.04)
    for order in orders:
        # addr のメモリの、ペリフェラルのメモリアドレス 0で,orderを書き込みます
        i2c.writeto_mem(addr, 0x00, order)
        time.sleep(0.001)

# ************************************************************************/
#  LM73の初期化設定
# ************************************************************************/
def LM73_ini():
    LM73_buf[0]=0x04
    LM73_buf[1]=0x60    
    i2c.writeto(LM73_addr,LM73_buf)
    time.sleep(0.001)
    #ポイント・レジスタを0にしておく(readするだけで温度が読めるようになる)
    i2c.writeto(LM73_addr,b'\x00')
    time.sleep(0.001)
 
LCD_init()
LCD_clear()
LCD_home()
# LM73_ini()
custom_print('Hello Word')

while True:
    time.sleep(0.1)
    LCD_cursor(0,1)
    # スレーブアドレス LM73_addr のデバイスから 2バイトを読み出す
    # LM73_buf = i2c.readfrom(LM73_addr,2)
    #バイトデータを加工
    temp = ((LM73_buf[0]  << 6) | (LM73_buf[1] >> 2)); #データを結合して14ビットの温度値にする
    temp=temp* 0.03125; 
    custom_print(str(temp))
    time.sleep(0.5)

0 件のコメント:

コメントを投稿