実際のところ
ポート的に限界があるため、Mega系列のシリアル2番を使いました。
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){ obniz.uart0.send("1\n"); if(obniz.uart0.isDataExists()){ console.log(obniz.uart0.readByte()); } await obniz.wait(100); //wait for 100ms } } </script> </body> </html>
uLisp側
どこかの莫迦のようにポート指定後速攻でアレしてもだめです。
以下の例のように間をおくか、あるいはavailavle?系関数を自前で作るとよいでしょう。
(with-serial (str 2 96)(delay 500) (loop(print (read-line str))(delay 100)))
実行結果
uLisp 2.7 1213> (with-serial (str 2 96)(delay 500) (loop(print (read-line str))(delay 100))) "1" "1" "1" "1" ...