Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

Arduino UNO系でも動くLISP実装 uLISP その5:obnizでシリアル通信をうける

実際のところ

obniz側

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
    <script src="https://unpkg.com/[email protected]/obniz.js" crossorigin="anonymous"></script>
  </head>
  <body>

    <div id="obniz-debug"></div>
    <h1>obniz instant HTML</h1>

    <script>
      var obniz = new Obniz("YOURID")
      
      obniz.onconnect = async function(){
        obniz.uart0.start({tx:0, rx:1, baud: 9600})
        while(1){
            if(obniz.uart0.isDataExists()){
                console.log(obniz.uart0.readText());
            }
            await obniz.wait(100);  //wait for 100ms
        }
      }
      
    </script>
  </body>
</html>

uLisp側

 (with-serial (str 2 96)(delay 500) (loop(write-line "123" str)(delay 1000)))

実行結果

f:id:shuzo_kino:20190709004200p:plain

参考もと

uLisp - Language reference