2026年5月14日木曜日

tinygo and esp01 on raspico(ドラフト)

以下を成功したのでget ?t=21.1&h=45をmock get reqしよう

 package main

import (

"machine"

"time"

)


var uart = machine.UART0

var buf = make([]byte, 256)


// --------------------

// コマンド送信

// --------------------

func send(cmd string) {

for i := 0; i < len(cmd); i++ {

uart.WriteByte(cmd[i])

}

uart.WriteByte('\r')

uart.WriteByte('\n')

}


// --------------------

// 応答待ち

// --------------------

func waitFor(expected string, timeout time.Duration) bool {

start := time.Now()

data := ""


for time.Since(start) < timeout {

n, _ := uart.Read(buf)

if n > 0 {

part := string(buf[:n])

print(part)

data += part


if contains(data, expected) {

return true

}

if contains(data, "ERROR") {

return false

}

}

}

return false

}


// --------------------

// 文字列検索

// --------------------

func contains(s, sub string) bool {

for i := 0; i <= len(s)-len(sub); i++ {

if s[i:i+len(sub)] == sub {

return true

}

}

return false

}


func main() {


// ★ ESP-01はまず115200か9600を試す

uart.Configure(machine.UARTConfig{

BaudRate: 115200, // ← 合わなければ115200に変更

TX:       machine.GPIO0,

RX:       machine.GPIO1,

})


time.Sleep(5 * time.Second)


// --------------------

// AT確認

// --------------------

send("AT")

if !waitFor("OK", 3*time.Second) {

println("AT failed")

return

}


// --------------------

// リセット

// --------------------

send("AT+RST")

time.Sleep(5 * time.Second)


// 再確認

send("AT")

if !waitFor("OK", 3*time.Second) {

println("AT after reset failed")

return

}


// --------------------

// ステーションモード

// --------------------

send("AT+CWMODE=1")

if !waitFor("OK", 3*time.Second) {

println("CWMODE failed")

return

}


// --------------------

// WiFi接続

// --------------------

send(`AT+CWJAP="Buffalo-2G-8340","636nsa535ds3v"`)


// ★ busy p... の後に OK が出れば成功

if !waitFor("OK", 30*time.Second) {

println("WiFi connect failed")

return

}


println("\nWiFi Connected!")


for {

time.Sleep(10 * time.Second)

}

}

2026年5月11日月曜日

tinygo on raspico/w

https://github.com/neildavis/pi_pico_tinygo_examples はpico用 picow用は以下

git cloneでhttps://github.com/soypat/cyw43439/、念の為cyw43439でgo mod tidy

seigojp@fseigojp-PC-LS700RSR-E3:~/cyw43439/examples/cywnet/credentials$ ls

credentials.go  password.text  ssid.text

fseigojp@fseigojp-PC-LS700RSR-E3:~/cyw43439/examples/cywnet/credentials$ cat password.text 

************

fseigojp@fseigojp-PC-LS700RSR-E3:~/cyw43439/examples/cywnet/credentials$ cat ssid.text 

Buffalo-2G-8340

で設定したのちreadmeにあるとおり

 tinygo version 0.35.0 linux/amd64 (using go version go1.23.8 and LLVM version 18.1.2)

fseigojp@fseigojp-PC-LS700RSR-E3:~/cyw43439/examples/dhcp$ go version

go version go1.23.8 linux/amd64

の条件で

https://github.com/soypat/cyw43439/tree/main#:~:text=tinygo%20flash%20%2Dtarget%3Dpico%20%2Dstack%2Dsize%3D8kb%20%2Dscheduler%3Dtasks%20%2Dmonitor%20%20./examples/blinky で成功

詳しくは https://github.com/soypat/cyw43439/tree/mainを参照してください



2026年5月6日水曜日

kallumajs and color-oled/kaluma http and node express

color oled 成功(ssd1306)

npm i https://github.com/niklauslee/ssd1306 してnode_modules/examples/

に入りkaluma flash ./ex _128x128.js --bundleで成功 うれしい

ーーーーーーーーーーーーーーーーーーーーーーーーーー

https://javascript.plainenglish.io/physical-computing-with-javascript-8-8-connecting-to-internet-151ba3dfce59にある例題  まずdht,exp8266-httpをnpm install(kalumajsサイトpackages参考)

kalumaはfirwareこわれやすいのでkaluma flash ./index.js --bundle で止まる時は入れ直す

node app.jsで頓死おこるならPC再起動ポート番号も変更せんといかんときもある

--------nodejs-------app.js--------node app.js--で先に起動

const express = require('express');

const ip = require('ip');


const app = express();

const addr = ip.address();

const port = 3000;


let temperature = '0.0';

let humidity = '0';


app.get('/update', (req, res) => {

  if (req.query.t) temperature = req.query.t;

  if (req.query.h) humidity = req.query.h;

  res.status(200).send('OK');

});


app.get('/', (req, res) => {

  res.setHeader('Content-Type', 'text/html');

  res.send(`

<html>

  <body>

   <h1>${temperature}</h1>

   <h1>${humidity}</h1>

  </body>

</html>

  `);

});


app.listen(port, () => {

  console.log(`Server running at http://${addr}:${port}`);

});

-----kalumajs--index.js---flash後にkaluma shellで.load----

const { DHT } = require('dht');

const { ESP8266HTTPClient } = require('esp8266-http-client');


// 設定

const WIFI_SSID = 'Buffalo-2G-8340';

const WIFI_PASSWORD = '636nsa535ds3v';


const ADDRESS = '192.168.11.8';

const PORT = '3001';


// DHT11

const dht = new DHT(15, DHT.DHT11);


// ESP8266

const esp = new ESP8266HTTPClient();


function start() {


  setInterval(() => {


    try {


      dht.read();


      let t = dht.temperature.toFixed(1);

      let h = dht.humidity.toFixed(0);


      console.log(`TEMP=${t} HUM=${h}`);


      const url =

        `http://${ADDRESS}:${PORT}/update?t=${t}&h=${h}`;


      console.log(url);


      esp.http(url)

        .then(res => {

          console.log('send ok');

        })

        .catch(err => {

          console.log('http error');

          console.log(err);

        });


    } catch(err) {


      console.log('dht error');

      console.log(err);


    }


  }, 10000);


}


// WiFi接続

esp.wifi(WIFI_SSID, WIFI_PASSWORD)

  .then(() => {


    console.log('wifi connected');


    start();


  })

  .catch(err => {


    console.log('wifi connect failed');

    console.log(err);


  });

2026年5月5日火曜日

開発系まとめ(platformなど)

https://docs.sunfounder.com/projects/kepler-kit/ja/latest/pyproject/for_micropython_user.html#iot :: raspberry py picow mpy

https://docs.sunfounder.com/projects/elite-explorer-kit/ja/latest/components/component_uno.html  :: arduino uno r4 wifi

https://docs.sunfounder.com/projects/esp32-starter-kit/ja/latest/?utm_source=chatgpt.com ::  esp32

https://randomnerdtutorials.com/projects-esp8266/ :: esp8266 ただし英語。。。

----------------------------------------------------------------------------------------------------

esp32はIDE1.8は遅くplatformIOが推奨(差分コンパイルなしのせいかだろう)

https://qiita.com/nextfp/items/f54b216212f08280d4e0にesp32 devkitcが詳述されている

unoR3/esp8266はIDE1.8は差分コンパイルなしだがコンパイルそこそこ早いので使用OK

unoR4はIDE2.3が必須、ubuntu では 

./arduino-ide_2.3.6_Linux_64bit.AppImage  --no-sandbox で!

2026年5月4日月曜日

Tinygo on windows11(unoR3)

 https://github.com/neildavis/pi_pico_tinygo_examples for pico

https://github.com/soypat/cyw43439/tree/main for picow

上記は例題サイト

ーーーーーーーーーーーーーーーーー

wslでないやりかた 簡単だった

https://qiita.com/ysaito8015@github/items/148a28ee20f5a48d3cb8

for /F "tokens=*" %x in ('tinygo env TINYGOROOT') do dir %x\src\examples

上記はcmdでないと動かんかった

tinygo targets    で       arduino-uno だった 

すでにArduino IDEある場合

avrdudeの場所をPATHに追加

典型パス(例):

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin

または新しいIDEだと: 私のは、こっちだった

C:\Users\ユーザー名\AppData\Local\Arduino15\packages\arduino\tools\avrdude\...\bin


tinygo flash --target=arduino-uno main.go で成功

2026年5月2日土曜日

Kalumajs LED問題(picoOKだが。。。)/tinygoではpicowでOKなおUNOR3ok

picowの場合ビルトインledは特殊なコードが必要(ドキュメントよめ)

以下はpico/picow両方でうごく

pinMode(15, OUTPUT); // Set the pin 1 to output mode.

digitalWrite(15, HIGH); // Set the pin 1 to HIGH.

// Toggle the LED.

const { LED } = require('led');

const led = new LED(28); // LED connected to pin 0.

led.on();

delay(1000); // wait for 1sec

led.off();

delay(1000); // wait for 1sec

led.toggle(); // on

delay(1000); // wait for 1sec

led.toggle(); // off

ーーーーーーーーtinygoならPICOW OKーーーーーーーーーーーーーーーーーーー

tinygo flash -target=pico-w main.go うまくいかんときはpicowをブートモードでやる!


package main


import (

"machine"

"time"

)


func main() {

led := machine.GPIO28

led.Configure(machine.PinConfig{Mode: machine.PinOutput})


for {

led.High() // ON

time.Sleep(1 * time.Second)


led.Low() // OFF

time.Sleep(1 * time.Second)

}

}

ーーーーーーーーー

tinygo target=arduino main.gで

package main


import (

"machine"

"time"

)


func main() {

led := machine.LED

led.Configure(machine.PinConfig{Mode: machine.PinOutput})

for {

led.Low()

time.Sleep(time.Millisecond * 900)

led.High()

time.Sleep(time.Millisecond * 500)

}

}

2026年4月23日木曜日

ラズピコ TinyGo-dht/MMBasic

 package main

import (

"fmt"

"machine"

"time"

"tinygo.org/x/drivers/dht"

)


func main() {

// ボードに合わせて変更(Picoなら machine.GP2, Arduinoなら machine.D2等)

pin := machine.GP2

sensor := dht.New(pin, dht.DHT11)

fmt.Println("--- DHT11 Reading Start ---")

for {

// 多くのバージョンで共通して実装されている ReadRaw (または RawRead) を試すか

// 最新の標準インターフェースに基づいた Measurements を使用します。

// それでもエラーが出る場合は、ドライバのバージョンが極端に古い可能性があります。

temp, humid, err := sensor.Measurements()

if err != nil {

fmt.Printf("Read Error: %v\n", err)

} else {

fmt.Printf("Temp: %.1f°C  Humid: %.1f%%\n", float32(temp)/10, float32(humid)/10)

}

time.Sleep(10* time.Second)

}

}

 tinygo flash -target=pico -monitor . でコマンドプロンプトで確認できた

データ読み取りに10秒間隔で正常なデータがでるようになった

湿度は正確だが、温度やや高めに推移(購入個体の問題か。。。)

----------------------------------------------------------------------

https://yumeiroandroid.blog.fc2.com/blog-entry-374.html ここでLチカ成功