Bye Bye Moore

猫マンション建築の野望を胸に零細事業主として資本主義の荒波に漕ぎ出したアラサー男の技術メモ

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/obniz@2.2.0/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