ð£RaspberryPi Picoãšãã©ãŠã¶ã§éä¿¡ãã
RaspberryPi Picoã«ç¡ç·æ©èœãæèŒããRaspberryPi Pico Wãçºå£²ãããŸãããïŒ
ããã䜿ãã°ããŠã§ããã©ãŠã¶ããç°¡åã«ã©ãºãã³ãæäœã§ããã¿ããã§ãã
ãããããã«ã¯æ®éã®ã©ãºãã³ãããããŸããã®ã§ãé³æ³¢éä¿¡ã§ãã©ãŠã¶ããã©ãºãã³ãæäœããŠã¿ãŸãããïŒ
å®æå³
é»æ³¢ã®ä»£ããã«ãé³æ³¢ã䜿ã£ãŠéä¿¡ããŸãã
é床ã¯160bpsãéä¿¡è·é¢ã¯é³å£°åšãã®ã¢ããã°åè·¯ã貧匱ãªå Žåã¯æ°cmã§ãã
â»ã¢ããã°åè·¯ããã¡ããšäœãã°ïœ1mã§ãããã¯é 匵ãããšããïŒ
ãã©ãŠã¶ã¯éä¿¡ç»é¢ã®çºã ãã«å©çšããŠãã©ãºãã³ãšãã©ãŠã¶ã¯çŽæ¥é³æ³¢ã§ã話ãããŸãã
楜ãããã§ããïŒ
ã©ãºãã³
ãŸãã©ãºãã³åŽããäœã£ãŠãããŸãããã
ããŒãã®æºå
ä¿è·åè·¯ãçµç±ããŠïŒæã®å§é»çŽ åãã©ãºãã³ã«çŽçµããŸãã
ãã®è²§çžãªåè·¯ã¯ãæ¬æ¥å¥ã
ã«çšæããã¹ãé³å£°å
¥å/åºååè·¯ãäžäœåããŠããããšãŠããŸãšãã«åãããã«æããŸããããïŒéåžžã«ã·ãã¢ã§ããïŒåäœããŸããã
æå ã®è£ 眮ã§ã¯ãå§é»çŽ åã«ç§æé»åã§è³Œå ¥ããSPT08ã䜿ããŸãããããã®èŸºã«èœã¡ãŠããçŽåŸïŒïœïœãããã®ãã®ãªãäœã§ãããããããšæããŸãã
åè·¯å³ã¯ãã®ããã«ãªããŸããããã£ãœããªãŒãã£ãªå
¥ååè·¯ãšéé»å§ä¿è·åè·¯ã§ãã
ïŒã¢ããã°åè·¯ã®ãããæ¹ã®çªã£èŸŒã¿ããåŸ
ã¡ããŠãããŸããïŒ
éèŠ ãããã€ãªã©ãºãã³ãç Žå£ããªãããã«ãã¯ãªããã³ã°çšã®ä¿è·ãã€ãªãŒããå¿ããã«ïŒ
â»éé»å§åã¯3.3Vã®ã©ã€ã³ã«æšãŠãŠããŸãããã©ãºãã³ã®åè·¯çã«ã¯å°ã
å±éºãªæ°ãããŸãããã®å Žåã©ããããããã®ãâŠã
å§é»çŽ åã¯äž¡é¢ããŒãã§ãã£ãããšåºå®ããŠãã ãããæ¯åãããšæ³¢åœ¢ãä¹±ããŠè¯ããããŸããã
ãœããã®æºå
ã©ã¹ãã³ã®ãœãããŠã§ã¢ã¯ãTBSKmodemMicroã®Arudinoçã䜿ããŸããTBSKmodemMicroã¯32ããããã€ã³ã³åãã«C++14ã§å®è£ ããã©ã€ãã©ãªã§ãã
ãã¥ãŒããªã¢ã«ã«åŸã£ãŠã©ã€ãã©ãªãArduinoIDEã«ã»ããã¢ããããŠãã ããã
- https://github.com/nyatla/TBSKmodemMicro/releasesããTbskModemMicro-Ardiuno.zipãããŠã³ããŒãããŸãã
- Arduino IDEãèµ·åããã¹ã±ããâã©ã€ãã©ãªãã€ã³ã¯ã«ãŒãâZip圢åŒã®ã©ã€ãã©ãªãã€ã³ã¹ããŒã«...ãéžæããŸãã
- ããŠã³ããŒãããã©ã€ãã©ãªãéžæããŸãã
- ã©ã€ãã©ãªãæå¹åããããã«Arduino IDEãåèµ·åããŠãã ããã
éä¿¡ãã¹ã
éä¿¡ãã¹ããããŸãã
ãµã³ãã«ã«ãããSendHelloãå°ãæ¹é ããŠäœ¿ããŸãã
SendHelloã¯ãæ°ç§ééã§ã¡ãã»ãŒãžãéä¿¡ããããŒã³ã³ã®ã¹ã±ããã§ãã
ãã¡ãŒã«âã¹ã±ããäŸâTBSKmodemMicroâSendHelloãéžæããŸãã
ã¹ã±ãããéããSPK_PINãAD0(26)ã«æžãæããŸãã
ã³ã³ãã€ã«ããŠãã©ãºãã³ã«ãã€ããªãæžã蟌ãã§ãã ããã
#include "TbskModemMicro.h"
using namespace TBSKmodemMicro;
#define LED_PIN 25
#define SPK_PIN 26 //âããïŒïŒïŒ
TbskPulseModulator<100> tpm;
void setup() {
pinMode(LED_PIN, OUTPUT); //LED
pinMode(SPK_PIN, OUTPUT); //OutputPin
}
void loop()
{
digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
tpm.write(SPK_PIN,16000,"Hello arduino"); //send message via GPIO pulse audio.
digitalWrite(LED_PIN, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000);
}
ã©ãºãã³ããïŸïœ°ïœŒïŸïœ°ãšé³ã鳎ã£ãããé©åœãªã¹ãããPCã§https://nyatla.jp/tbskmodem/ ãéããŠStartãã¿ã³ãæŒããŸãã
ã¢ããªåŽã«ã«ã¡ãã»ãŒãžã衚瀺ãããã°OKã§ãïŒ
ïŒTBSKå€èª¿ã¯ãšã©ãŒèšæ£ããªãã®ã§ãæååããçºçããããšããããŸãããŸããç掻é³ç°å¢äžã§ã¯æ«å°Ÿã«ãŽããæ··ããããããªããŸããïŒ
éåä¿¡ãã¹ã
éåä¿¡ãã§ããããã¹ãããŸãã
å§é»çŽ åãã»ã³ãµã«ããé³æ³¢åä¿¡ã¯çµæ§ã·ãã¢ãªã®ã§å¿èåãå¿
èŠã§ãã
ãµã³ãã«ã«ãããEchoBackã®ã¹ã±ããã䜿ããŸãã
#include "TbskModemMicro.h"
using namespace TBSKmodemMicro;
TbskPulseModulator<100> tpm;
TbskDemodulator<100> dem;
#define LED_PIN 25
#define AD_PIN 26
#define SP_PIN 26
void setup() {
pinMode(LED_PIN, OUTPUT); //LED
}
void loop()
{
int r=-1;
TMM_UINT8 recv[10] = {};
digitalWrite (LED_PIN,HIGH);
analogReadResolution(12);
while(r==-1){
r=dem.read(AD_PIN,16000,recv,10,5000);
}
digitalWrite (LED_PIN,LOW);
delay(1000);
//send back data
TMM_UINT8 send[16]={};
memcpy(send,"echo:",5);
memcpy(send+5,recv,r);
pinMode(SP_PIN, OUTPUT);
tpm.write(SP_PIN,16000,(const char*)send,r+5);
return;
}
ãã®ã¹ã±ããã¯ãé³æ³¢éä¿¡ãåä¿¡ãããšããã®å 容ã«"echo:"ãã¬ãã£ã¯ã¹ãã€ããŠãã®ãŸãŸéãè¿ããŠãããŸãã
ã³ã³ãã€ã«ããŠãã©ãºãã³ã«ãã€ããªãæžã蟌ãã§ãã ããã
ã©ã¹ãã³åºæ¿ã«ããLEDãç¹ç¯ãããæºåå®äºã§ãã
éä¿¡åŽã¯ãhttps://nyatla.jp/tbskmodem/ ã䜿çšããŸãã
ãã©ãŠã¶ã§éããŠStartãã¿ã³ãæŒããããéä¿¡æ¬ã«"test"ãå
¥åããŠéä¿¡ãã¿ã³ãæŒããŸãã
ããŠãããã§ïŒã€å€§ããªåé¡ããããŸãã
å§é»çŽ åããã€ã¯ã®ä»£ããã«äœ¿ãåè·¯ã§ã¯ãæ°ã»ã³ãã®è³è¿è·é¢ã§å§é»çŽ åãšæ°Žå¹³ã«éä¿¡åŽã®åºåãé
眮ãã倧ããã®é³ã§éä¿¡ããªããšãé³æ³¢ãã©ãºãã³ã®ã»ã³ãµã«å°éããŸããã
éåä¿¡æ©ã¯åºæ¥ãã ãæ°Žå¹³ã«åããåããã§é
眮ããå¿
èŠããããŸãã
äœåºŠãé³ãåºããŠåä¿¡ããŠãããé 眮ãæ¢ãããšãç¹°ãè¿ããŠãã ãããã©ãºãã³ãåä¿¡ã«æåãããšãLEDãäžæŠæ¶ç¯ããä¿¡å·ãéãè¿ããŠãããã¯ãã§ãã
æ°ååè©ŠããŠããã¡ãªå Žåã¯ãå¥ã«ãã€ã¯ã¢ãžã¥ãŒã«ãçšæããŠãå ¥åãšåºååè·¯ã®åé¢ãæ€èšããŸãããã
ã©ãºãã³ã®ãã¡ãŒã ãäœã
Echobackã®ã³ãŒããåºã«ã"ON"ãåä¿¡ãããLEDãONã"OFF"ãåä¿¡ãããLEDãOFFããããã«æ¹é ããŸãã
#include "TbskModemMicro.h"
using namespace TBSKmodemMicro;
TbskPulseModulator<100> tpm;
TbskDemodulator<100> dem;
#define LED_PIN 25
#define AD_PIN 26
#define SP_PIN 26
bool current_led=true;
void setup() {
pinMode(LED_PIN, OUTPUT); //LED
pinMode(AD_PIN, INPUT);
pinMode(SP_PIN, OUTPUT);
analogReadResolution(12);
}
void loop()
{
int r=-1;
TMM_UINT8 recv[10] = {};
digitalWrite (LED_PIN,current_led?HIGH:LOW);
pinMode(AD_PIN, INPUT);
while(r==-1){
r=dem.read(AD_PIN,16000,recv,10,5000);
}
char status[7+3+1];
if(memcmp(recv,"on",2)==0){
//on
sprintf(status,"status:on\0");
current_led=true;
}else if(memcmp(recv,"off",3)==0){
//off
sprintf(status,"status:off\0");
current_led=false;
}else{
sprintf(status,"ERROR");
}
delay(.5);
pinMode(SP_PIN, OUTPUT);
tpm.write(SP_PIN,16000,(const char*)status);
return;
}
ãã®ã³ãŒãã¯ãåä¿¡ããããŒã¿ãifæå€å®ãããã©ã°ãåãæ¿ããŠããŸãã
LEDåæ¿ã ãã ãšã€ãŸããªãã®ã§ãã€ãã§ã«å¿çãè¿ãããã«ããŸããã
ããããšåããã³ã®pinModeãæäœããŠããŸãããããã¯å§é»çŽ åãå ¥åºåå ŒçšããŠããããã§ããADCãã³ãšDIGITALOUTãïŒãã³ã§åãæ¿ããå Žåãpinã¢ãŒãããã®é çªã§æäœããªããšADCãæ£åžžåäœããªãããšããããŸãã
ã³ã³ãã€ã«ããŠãã©ãºãã³ã«æžã蟌ãã§ãããŸãããã
ãã©ãŠã¶ã¢ããª
次ã¯æäœããããã®ãã©ãŠã¶ã¢ããªã±ãŒã·ã§ã³ãäœããŸãã
ã©ã€ãã©ãªã¯ãJavascriptçšã®TbskmodemJSã䜿ããŸãã
ã©ã€ãã©ãªã®æºå
https://github.com/nyatla/TBSKmodemJS/releases ããTBSKmodemJS.zipãããŠã³ããŒãããŸãã
TBSKmodemJS.zipãå±éãããããµã³ãã«ãèµ·åããŸãããã
ãµã³ãã«ã®èµ·åã«ã¯WebãµãŒããå¿
èŠã§ããããã§ã¯Pythonã®ãŠã§ããµãŒããå©çšããŸãã
$cd TBSKmodemJS
$python -m http.server 8000
http://127.0.0.1:8000 ã«ã¢ã¯ã»ã¹ããŠãã ãããgetstarted/*.htmlã«ã¹ã¿ã³ãã¢ãã³çã®ãµã³ãã«ããããŸãã
ç¶ããŠãtbsksocket_send.htmlãéããŸããããã¯éä¿¡ãã¿ã³ãæŒããšçãã¡ãã»ãŒãžãéä¿¡ãããµã³ãã«ã¢ããªã±ãŒã·ã§ã³ã§ãã
Startãã¿ã³ãæŒããåŸã«Sendãã¿ã³ãæŒããšãïŸïœŒïŸïœŒïŸïœŒïŸïœŒïŸïœŒïŸãšé³æ³¢ãéä¿¡ãããŸãã
éäžã§ãã€ã¯ã¢ã¯ã»ã¹ãæ±ããéç¥ããããŸãã®ã§ãèš±å¯ããŠãã ããã
(ãã£ãããããŒããŒã«ã®ConsoleãèŠããšè³ããã«ãªããŸãã)
ããã§ãã©ãŠã¶ã¢ããªã®å®è¡ç°å¢ãæŽããŸããã
泚æ WebAudioã®APIã¯ãHTTPSãµãŒãããããã¯ããŒã«ã«PCäžã®HTTPãµãŒãã§ããåäœããŸãããããã¯ãã©ãŠã¶ã®ä»æ§ã§ãã
LEDãã€ãããæ¶ãããããã¢ããªãäœã
tbsksocket_send.htmlãããŒã¹ã«ããŠãã©ãºãã³ã®LEDãON/OFFããã¢ããªãäœã£ãŠãããŸãã
ã¯ãïŒã§ããŸããïŒ
<!doctype html>
<html lang=en-us>
<head>
<meta charset=utf-8>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>TBSKmodemJS</title>
</head>
<body>
<h1>LED ON/OFF.</h1>
<hr/>
<script async src="../dist/tbskmodem.js"></script>
<script>
window.addEventListener('load', ()=>
{
window.addEventListener('unload',()=>{
console.log("Shutdown sequence.");
shutdown=true;
socket.close();
});
let started=false;
document.getElementById("start").addEventListener("click",()=>{
if(started){
return;
}
started=true;
let env=TBSKmodemJS.checkEnvironment();
if(env.success!=true){
alert("Insufficient environment required for TBSKmodemJS");
console.log(JSON.stringify(env)+"\n");
throw Error();
}
console.log("env",env);
//tbsk setup
TBSKmodemJS.load().then((tbsk)=>{
console.log(tbsk.version);
socket=new tbsk.misc.TbskSocket({carrier:16000,encoding:"utf8"});
socket.addEventListener("open",(event)=>{
console.log("Socket open!");
document.getElementById("on").addEventListener("click",()=>{
socket.send("on");
});
document.getElementById("off").addEventListener("click",()=>{
socket.send("off");
});
});
let msg;
socket.addEventListener("detected",(event)=>{
msg="";
});
socket.addEventListener("message",(event)=>{
msg+=event.data;
});
socket.addEventListener("lost",(event)=>{
alert(msg);
});
});
});
});
</script>
<style>
body{text-align:center;}
#start,#on,#off{font-size:3em;width:5em;margin:.2em auto;}
</style>
<div>
<button id="start">START</button><br/>
<button id="on">ON</button><br/>
<button id="off">OFF</button>
</div>
</body>
</html>
äž»ãªå€æŽç¹ã¯ãã¿ã³ã®è¿œå ãšããã®äžã§ã€ãã³ããåŠçããéšåã§ãã
ãã¡ã€ã«ãä¿åããŠããµãŒããŒã«é 眮ããŠãããã©ãŠã¶ããéããŸããããStartãã¿ã³ãæŒããšã¢ããªã±ãŒã·ã§ã³ãéå§ãããON/OFFãã¿ã³ãæŒããšïœŒïŸïœŒïŸïœŒïŸïœŒïŸãšé³ãåºããšæããŸãã
ãµãŒãã«é 眮ããã®ãé¢åãªæ¹ã¯ãã¡ãããã©ããã
ã³ãŒãã®èª¬æ
ãŸãã©ã€ãã©ãªãåæåããŸãã
TBSKmodemJS.loadé¢æ°ã¯éåæé¢æ°ãªã®ã§è§£æ±ºããŠãã次ã«ç§»ããŸãã
TBSKmodemJS.load().then((tbsk)=>{
æ¬éæ³¢åšæ³¢æ°ãæå®ããŠTbskSocketã®ã€ã³ã¹ã¿ã³ã¹ãçæããŸãã
TbskSocketã¯ã©ã¹ã¯éä¿¡ã·ã¹ãã ã®äžæ žã§ããWebsocketãšåãïŒãããªïŒã€ã³ã¿ãã§ã€ã¹ã§é³æ³¢éä¿¡ã䜿ãããšãã§ããŸãã
socket=new tbsk.misc.TbskSocket({carrier:16000,encoding:"utf8"});
ã€ã³ã¹ã¿ã³ã¹ãçæããããã€ãã³ããã³ãã©ãèšå®ããŠãããŸãã
openã€ãã³ãã¯ãœã±ãããæå¹ã«ãªããšåŒã³åºããããã³ãã©ã§ããæå¹ã«ãªããŸã§ã¯ãã¿ã³ãç¡å¹åããŠããããã®ã§ããã®ãã³ãã©ã®äžã§ãã¿ã³ã®ã€ãã³ããèšå®ããŸããã
socket.addEventListener("open",(event)=>{
detected,message,lostã¯ã¡ãã»ãŒãžã®åä¿¡ã«é¢ããã€ãã³ãã§ããTbskSocketã®éä¿¡é床ã¯é ãã®ã§ã1ã€ã®ã¡ãã»ãŒãžãåä¿¡ãçµããã®ã«é·ãæéãããããŸãã
ããã§ããŸãåãã«detected(æ€åº)ã€ãã³ããåŒã³åºããäžæåã¥ã€messageã§éç¥ããŠãæåŸã«ä¿¡å·ãèŠå€±ã£ãããšãäŒããlostã€ãã³ããåŒã³åºãããã«ãªã£ãŠããŸãã
detectedã¯å¿ ãlostã€ãã³ãã§çµäºããŸãããã®éã«ããmsgãçµåããŠãã¡ãã»ãŒãžå šäœã埩å ããŠããŸãã
let msg;
socket.addEventListener("detected",(event)=>{
msg="";
});
socket.addEventListener("message",(event)=>{
msg+=event.data;
});
socket.addEventListener("lost",(event)=>{
alert(msg);
});
ãã¹ã
äœæããWebã¢ããªãã¹ããã§éããŠãã©ãºãã³ã®è¿ãã§ããã¿ã³ãæŒããšãLEDãã€ãããæ¶ãããã§ããŸãããã£ããïŒ
èšçœ®æžã¿ã®ã¹ããã¢ããª
ããšãã
æ§èœã®æ¹å
ä»åã®ããŒããŠã§ã¢ã¯ãåçºã®å§é»çŽ åã§ããžã¿ã«ããŒã¿éä¿¡ãã§ãããšã«ãã³è¯ãããã ã£ãã®ã§ãã®åœ¢ã«ãªããŸããããâŠâŠãå®çšäžã¯ããªãèŸãæãã§ããïŒç¹ã«åä¿¡åŽïŒ
å ¥åºååè·¯ãåé¢ããŠãå ¥åãã³ã³ãã³ãµãã€ã¯ãåºåãå°åã®ã¹ããŒã«ãŒã«çœ®ãæããã°ãéåä¿¡ã®æ§èœã¯ããªãè¯ããªããšæããŸãã
䜿ãã©ãã
TBSKã®é³æ³¢éä¿¡ã¯ãæ®åããŠããéä¿¡æ¹åŒãšæ¯ã¹ããšé床ãé ãå°éè·é¢ãçãã®ã§ãä»ã®æè¡ã®ä»£ããã«ïŒã®ãããªç®çã«ã¯é©ããŸããã
ããããªãããåçŽãªãœãããŠã§ã¢ãšèŠå¶ã®ãªãé³æ³¢ã ãã§å®è£ ã§ãããããç¹æ®ãªãã©ã³ã·ãŒããŒããã€ã¹ããã®ããã®è€éæªå¥ãªç°å¢èšå®ãäžèŠã§ãé»æ³¢ãšéã£ãŠæé©ã®å¿é ããããŸãããã
ãã©ãŠã¶çµç±ã§ã¡ãã£ãšããããŒã¿ããªã³ã©ã€ã³ãšäº€æããããä»ã®ç¡ç·æ¹åŒã®åæã³ã³ãã£ã®ã¥ã¬ãŒã·ã§ã³äº€æãç¡ç·æ©èœã®ç¡ãããã€ã¹ã§ã·ãªã¢ã«åç·ãçããããæçã«ã䟿å©ã«äœ¿ãããšæããŸãã
ã¡ãªã¿ã«ãã©ãºãã€ããéä¿¡ã ãã§ããã°ãMicroPythonã§ãå¯èœã§ãã
詳ããã¯ãã¡ããã芧ãã ããã
Discussion