https://morizyun.github.io/javascript/node-js-npm-library-node-fetch.html node.js でfetchをつかえるようにする
import fetch from 'node-fetch';
var APIKEY = '518c255d266e82b0f903e3ba905c437c';
var location = "Tokyo,jp";
fetch( `http://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${APIKEY}`)
.then(res => res.json())
.then(json => console.log(json));
をindex.mjs(jsでなく)としてnode.mjsでOk
518c255d266e82b0f903e3ba905c437c my weather api
-----------------ポータル----------------
https://iot-gym.com/category/obniz/ オブニズ ポータル very instructable
https://iot-gym.com/ws2811-obniz/ ws2811 短いのから0,1、2とつける長いのはフリ
このかたのサイトは参考になる! たとえばarducm mini などは
https://iot-gym.com/arducammini-obniz/ とくわしい
ーーーーーーー uart between microbit and obniz ーーーーー
^^^^^^
serial.redirect( to-obniz.js
SerialPin.P0,
SerialPin.P1,
BaudRate.BaudRate115200
)
serial.writeString("from microbit")
serial.redirect( from-obniz.js
SerialPin.P0,
SerialPin.P1,
BaudRate.BaudRate115200
)
basic.forever(function () {
basic.showString(serial.readUntil(serial.delimiters(Delimiters.NewLine)))
})
<textarea id="data" cols="32" rows="12"></textarea> from-microbit.html
<div id="obniz-debug"></div>
<script>
var obniz = new Obniz("5312-1232");
var result="";
obniz.onconnect = async function () {
obniz.io0.output(false); // GND
obniz.uart0.start({tx: 1, rx: 2 });
obniz.uart0.onreceive = function(data, text){
result += text;
$("#data").val(result);
}
}
^^^^^^^^^^^^^^^^^^^^^^^^^
</script><html lang="ja"> to-microbit.html
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"
></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
/>
</head>
<body>
<h3 id="bploading" style="text-align:center;">ロード中...</h3>
<div id="OBNIZ_OUTPUT"></div>
<br />
<script
src="https://unpkg.com/obniz@latest/obniz.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/iothome/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/airobot/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ui/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ai/howler2.1.2/howler.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ai/opencv3.4/opencv.js"
crossorigin="anonymous"
></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.3.0"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@2.1.0"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/posenet@2.2.2"></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ai/clmtrackr/clmtrackr.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ai/clmtrackr/emotion_classifier.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ai/clmtrackr/emotionmodel.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ai/clmtrackr/model_pca_20_svm.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/ai/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.16.0/storage/index.js"
crossorigin="anonymous"
></script>
<textarea id="data" cols="32" rows="12"></textarea>
<button id="send">send</button>
<div id="obniz-debug"></div>
<script>
var obniz = new Obniz("5312-1232");
var result="";
obniz.onconnect = async function () {
obniz.io0.output(false); // GND
obniz.uart0.start({tx: 1, rx: 2 });
$("#send").click(function(){
var text=$("#data").val();
obniz.uart0.send(text+'\n');
}
</script> </body>
</html>
-----solenoid and bme280 -----
https://iot-gym.com/bme280-obniz/ の通りで成功 6pinでもOKだった
ソレノイドは、あっさり成功
-------------------------- エアコン操作 -----------------------------------------------------
https://www.kodomonokagaku.com/experience/programming/9416/ 読み取り
https://www.kodomonokagaku.com/experience/programming/9769/ 書き込み
注: アプリはいかに詳しい
https://www.kodomonokagaku.com/experience/programming/3251/
ーーーーーーーーーーーいわゆるLチカーーーーーーーーーー
https://qiita.com/azumabashi/items/77e923574d32a641d60f
<!-- HTML Example -->
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://obniz.com/js/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/obniz@3.3.0/obniz.js"></script>
</head>
<body>
<div id="obniz-debug"></div>
<h1>LED</h1>
<button id="on">on</button>
<button id="off">off</button>
<button id="tikatika">チカチカ</button>
<script>
var obniz = new Obniz("5312-1232");
obniz.onconnect = async function () {
var led = obniz.wired("LED", { anode:0, cathode:1 } );
obniz.display.clear();
obniz.display.print("Hello World");
obniz.switch.onchange = function(state) {
$('#print').text(state);
obniz.display.clear();
obniz.display.print(state);
}
$('#on').click(function () {
led.on();
obniz.display.clear();
obniz.display.print("ON");
});
$('#off').click(function () {
led.off();
obniz.display.clear();
obniz.display.print("OFF");
});
$('#tikatika').click(function () {
for(var i = 1; i < 10; i++){
led.off();
obniz.display.clear();
obniz.display.print("OFF");
led.on();
obniz.display.clear();
obniz.display.print("ON");
}
});
}
</script>
</body>
</html>
------------------------------------
https://obniz.com/ja/sdk/parts/Keyestudio_Buzzer/README.md
passive buzzer sound!
-----------------------------------------------------------------------
https://laboratory.kazuuu.net/use-a-buzzer-connected-to-the-obniz-board/
active buzze play sound!
ーーーーーーーサーボモーターーーー
https://qiita.com/Google_Homer/items/ed3be30e6e559d0395b9 ?
ーーーーーー dual motor driver 不要! dc motor ーーーーーーーーー
https://obniz.com/ja/sdk/parts/DCMotor/README.md
://qiita.com/getapojim/items/857025e1898fd12f6382
を参考に以下のコードで
両輪をスムーズに起動することができた
<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@1.9.4/obniz.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="obniz-debug"></div>
<h1>obniz instant html</h1>
<button id="forward">forward</button>
<button id="reverse">reverse</button>
<div id="print"></div>
<script>
var obniz = new Obniz("5312-1232");
obniz.onconnect = async function () {
var motor1 = obniz.wired("DCMotor", {forward:1, back:0});
var motor2 = obniz.wired("DCMotor", {forward:3, back:2});
//モーターを回転する
$('#forward').click(function () {
motor1.forward();
motor2.forward();
setTimeout(function(){
motor1.stop();
motor2.stop();
}, 1000);
});
//モーターを逆回転する
$('#reverse').click(function () {
motor1.reverse();
motor2.reverse();
setTimeout(function(){
motor1.stop();
motor2.stop();
}, 1000);
});
}
</script>
</body>
</html>