Scratch2 : WF8266R.js Extension


2017年 WF8266R 只能使用 ScratchX 操作, 如果你想要使用 Scratch2 請參考 WFduino 平台教學 http://wfduino.com, 這篇教學可能不適用

WF8266R.js 積木擴增了 Scratch2 對網路以及物聯網硬體的可能性, 透過這個套件讓 Scratch2 也能做像到 S4A 對 Arduino 的支援. 而且, 透過 UART 的支援, 你可以用 Scratch2 操入 WF8266R, 用 S4A 操作 Arduino, 然後 Arduino 和 WF8266R 彼此透過 UART 交流, 便能發揮各自平台的優點.


 安裝 Scratch2 離線版


下載位址 : https://scratch.mit.edu/scratch2download


 設置 Extension


因為 WF8266R 是一塊以網路為基礎的開發板, 在下方 host 需要改為 WF8266R 的 mDNS 名稱或是 IP 位址(建議使用IP會比較穩定), 才能順利讓 Scratch 找到 WF8266R 開發板.

下載 WF8266R.js Extension

{
   "host": "mywfxxxx.local",
   "extensionName": "WF8266R.js",
   "extensionPort": 80,
   "useHTTP": true, 
   "blockSpecs": [
     [" ", "腳位 %d.gpio 模式設為 %m.mode", "pinmode",5,"OUTPUT"],
     [" ", "腳位 %d.gpio 數位輸出 %m.level", "gpio",5,1],
     [" ", "腳位 %d.gpio 類比輸出 %n", "pwm", 5, 1023],
     [" ", "DHT%m.dhtType 溫濕度感測器,接在腳位 %d.gpio" ,"dht", 11,12],
     [" ", "DS18B20 溫度感測器,接在腳位 %d.gpio" ,"ds", 4],
     [" ", "UART 速率 %m.uartBaud" ,"baud", "115200"],
     [" ", "HCSR 超音波感測器,Echo 在腳位 %d.gpio Trig 在腳位 %d.gpio" ,"distance", 5,4],
     [" ", "紅外線接收器,接在腳位 %d.gpio" ,"irrecv", 14],
     [" ", "紅外線發射器,接在腳位 %d.gpio 發送資料 %s" ,"irsend", 15, "0"],
     [" ", "停止紅外線接收" ,"irstop"],
     [" ", "UART Tx 送出 %m.uartCode %s 結尾換行 %m.boolType" ,"tx", "text", "Hi", "true"],
     [" ", "%m.flushType 清空", "flush", "UART"],
     [" ", "HTTP %m.restfulType 資料 %s 到 %s %s" ,"http", "POST", "key=xxxxxx&field1=1&field2=2","api.thingspeak.com", "update"],
     [" ", "HTTP %m.restfulType 資料 %s 從 %s %s" ,"http", "GET", "api_key=EM18B52PSHXZB4DD", "api.thingspeak.com", "apps/thinghttp/send_request"],
     ["r", "讀取數位腳位 %d.gpio" ,"read", 5],
     ["r", "讀取感測器 %m.sensor 參數 %m.sensorParam" ,"sensor", "DHT", "C"],
     ["r", "讀取類比腳位 ADC","adc"]
   ],
   "menus":{
    "mode":["INPUT","OUTPUT"],
    "sensor":["DHT","DS","HCSR","IR","Rx","RESTfulGET"],
    "sensorParam":["Value","C","F","H"],
    "dhtType":["11","22","21"],
    "restfulType":["GET","POST"],
    "flushType":["UART","RESTful","IR"],
    "level":["0","1"],
    "uartCode":["text","hex"],
    "uartBaud":["9600","19200","38400","57600","115200"],
    "boolType":["true","false"],
    "gpio":["5","4","12","13","14","15","16","0","1","2","3"]
   }
}

 載入 Extension


按著 SHIFT 鍵不放並同時點選 File 開啟選單, 點擊 Import experimental HTTP extension 載入 WF8266R.json 積木檔


 積木介紹


下圖為 2016.04.05 版本的 S4W 積木功能, 左邊腳位控制和讀取, 中間是感測器讀取以及右邊 UART 和 雲端伺服器功能積木