メインコンテンツへスキップ
見出し画像

RP2040-Zeroはepiconで操縦するー1

    こんばんは、今日もお疲れ様
    実践IOTハウスです

    さて、RP2040-Zeroも単体で遊ぶ事も飽きて来たので
    IOTハウスで活躍して貰わないと

    と言うか既にRP2040-Zeroも単体では激安防犯対策で活躍中だった

    そこで、今回はRaspberry Piとコラボして本格的にIOTハウスの一員として活躍させる

    Raspberry Pi単体はLチカ、ADCもない

    なのでRaspberry PiのUSBへRP2040-Zero接続

    コマンド&レスポンス方式でADCや防犯ライトを点灯させる

    用意するのがSerial USB Terminal

    Linuxで使えるのが20年以上前に開発したepicon [Linux serial communication software]実践IOTハウスではMONOSTICK[モノスティック]とTWELITEで日没と換気扇制御で活躍中のもの

    シリアル通信ソフトepiconはgithub

    Raspberry Pi からRP2040へデモ・プログラム転送と実行

    # ssh  pi@iot000.local
    pi@iot000.local's password:
    Linux iot000 6.1.21+ #1642  Mon Apr  3 17:19:14 BST 2023 armv6l
    
    The programs included with the Debian GNU/Linux system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.
    
    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.
    Last login: Tue Jan  6 14:27:17 2026 from 192.168.11.28
    pi@iot000:~ $
    pi@iot000:~ $ sudo su
    root@iot000:/home/pi#
    root@iot000:/home/pi# cd /www/remote-hand/tmp/
    root@iot000:/www/remote-hand/tmp# epicon -ql /dev/ttyACM0 115200
    root@iot000:/www/remote-hand/tmp# epicon -ql /dev/ttyACM0 115200
    
    Device /dev/ttyACM0 is busy
    root@iot000:/www/remote-hand/tmp# rm /var/lock/epicon_socket.* ;rm /var/lock/LCK..ttyacm0
    root@iot000:/www/remote-hand/tmp#
    # epicon -l /dev/ttyACM0 115200
    
    ** Welcome to epicon Version-5.2 Copyright Isamu Yamauchi compiled:Feb 24 2021 **
          exec shell         ~!
          send binary files  ~f
          send break         ~b
          call rz,sz,sx,rx   ~rz,~sz,~sx,~rx
          call kermit        ~sk,~rk
          external command   ~C
          change speed       ~c
          exit               ~.
          Connected /dev/ttyACM0
    
    >>>
    >>>Ctl-D・・・実際には表示されません
    MPY: soft reboot
    MicroPython v1.26.1 on 2025-09-11; Raspberry Pi Pico with RP2040
    Type "help()" for more information.
    >>> help()
    Welcome to MicroPython!
    
    For online docs please visit http://docs.micropython.org/
    .
    Useful control commands:
      CTRL-C -- interrupt a running program
      CTRL-D -- on a blank line, do a soft reset of the board
      CTRL-E -- on a blank line, enter paste mode
    For further help on a specific object, type help(obj)
    For a list of available modules, type help('modules')
    >>>CTRL-E・・・実際には表示されません
    paste mode; Ctrl-C to cancel, Ctrl-D to finish
    paste mode; Ctrl-C to cancel, Ctrl-D to finish
    === import time
    === from machine import Pin
    === import rp2
    ===
    === max_lum =100
    === r=0
    === g=0
    === b=0
    ===
    === @rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24)
    === def ws2812():
    ===     T1 = 2
    ===     T2 = 5
    ===     T3 = 3
    ===     wrap_target()
    ===     label("bitloop")
    ===     out(x, 1)               .side(0)    [T3 - 1]
    ===     jmp(not_x, "do_zero")   .side(1)    [T1 - 1]
    ===     jmp("bitloop")          .side(1)    [T2 - 1]
    ===     label("do_zero")
    ===     nop()                   .side(0)    [T2 - 1]
    ===     wrap()
    ===
    ===
    === # Create the StateMachine with the ws2812 program, outputting on Pin(4).
    === sm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(16))
    ===
    === # Start the StateMachine, it will wait for data on its FIFO.
    === sm.active(1)
    ===
    === # Color change
    === while True:
    ===     for i in range(0,max_lum):
    ===         r=i
    ===         b=max_lum-i
    ===         rgb =(g<<24) | (r<<16) | (b<<8)
    ===         sm.put(rgb)
    ===         time.sleep_ms(10)
    ===     time.sleep_ms(300)
    ===     for i in range(0,max_lum):
    ===         g=i
    ===         r=max_lum-i
    ===         rgb =(g<<24) | (r<<16) | (b<<8)
    ===         sm.put(rgb)
    ===         time.sleep_ms(10)
    ===     time.sleep_ms(300)
    ===     for i in range(0,max_lum):
    ===         b=i
    ===         g=max_lum-i
    ===         rgb =(g<<24) | (r<<16) | (b<<8)
    ===         sm.put(rgb)
    ===         time.sleep_ms(10)
    ===     time.sleep_ms(300)
    === Ctl-D・・・実際には表示されません
    True・・・デモ用プログラムが走る
    
    ~. ・・・実際には表示されません,epiconから抜ける
    rue
    Traceback (most recent call last):
      File "<stdin>", line 52, in <module>
    KeyboardInterrupt:
    >>>
    >>> Connection to iot000.local closed.
    
    次ログイン時ロックファイルが残るremoveしないと使えない
    root@iot000:/www/remote-hand/tmp# epicon -ql /dev/ttyACM0 115200
    
    Device /dev/ttyACM0 is busy
    root@iot000:/www/remote-hand/tmp# rm /var/lock/epicon_socket.* ;rm /var/lock/LCK..ttyacm0
    root@iot000:/www/remote-hand/tmp#
    画像
    Raspberry Pi &RP2040でLチカ

    次はRP2040へコマンド送信&受信

    #Raspberry_Pi
    #RP2040
    #epicon
    #IOT
    #iot
    #USBシリアル通信
    #実践IOTハウス
    #Linux
    #Serial_Terminal


     
     
    実践IOTハウス開発中、 半世紀以上生きて夢中になれるLinuxプログラミング、 日々起きるIOTハウスのワクワクを綴ります 子供が実験や遊び学んだ物が実用化->親が喜ぶ->親が子供を褒める->子供が褒めてもらう為に更に学び工夫する->親が子供を褒める->子供が育つ->社会が育つ

    あなたへのおすすめ