2026年8月29日土曜日

tinygo wioterminal(blink,button interrup,usb cdc)

tinygo build -target=wioterminal -o wioterminal_blink.uf2 main.go flashうまくいかん

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

UbuntuでWio Terminalをブートローダーモード(リセット2回)にした際、ポート(シリアル)としては認識されるものの「Arduino」という名前のマスストレージ(UF2書き込み用フォルダ)が自動で開かない・マウントされない原因は、Ubuntu側の自動マウント設定やファイルマネージャー(Nautilusなど)の挙動、あるいは権限の問題であることが多いです。 [1, 2]
この問題を解決するための具体的な手順は以下の通りです。
1. 手動でマウント状況を確認・実行する
自動でウィンドウが開かない場合でも、OS側ではドライブとして認識されている可能性があります。
  1. 端末(ターミナル)を開き、デバイスが認識されているか確認します。
    bash
    lsblk
    
    コードは注意してご使用ください。
  2. リストの中に Arduino というラベルや、FAT16/FAT32の小さなドライブ(数MB程度)が見つかるか確認します。
  3. マウントされていない場合は、手動でマウントを試します(例として /media/arduino にマウントする場合)。
    bash
    sudo mkdir -p /media/arduino
    sudo mount /dev/sdX1 /media/arduino  # /dev/sdX1はlsblkで確認したデバイス名に変更
    
    コードは注意してご使用ください。
    マウントできたら、ファイルマネージャーで /media/arduino を開いて .uf2 ファイルをドラッグ&ドロップまたはコピーします。
2. パッケージの追加(gvfs-backends 等)
Ubuntuの環境によっては、FATファイルシステムの自動マウントに必要なパッケージが不足している場合があります。
bash
sudo apt update
sudo apt install gvfs-backends udisks2
コードは注意してご使用ください。
インストール後、再度Wio Terminalをリセット2回(青いLEDが呼吸するように明滅するモード)にして、ファイルマネージャーにアイコンが出るか確認してください。 [1]
3. 別解:コマンドライン(dd または cp)で直接書き込む
フォルダが開かなくても、デバイスとして認識されていればコマンドラインから直接書き込むことができます。
  1. lsblk または dmesg コマンドで、接続されたストレージのパス(例: /dev/sdb/media/...)を確認します。
  2. マウントポイントが /media/username/Arduino のように自動割当てされているが中身が見えない場合は、直接 cp コマンドで転送を試します。
    bash
    cp firmware.uf2 /media/username/Arduino/

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

まずはblinkから行ってみる

import (

        "machine"

        "time"

)


func main() {

        // 内蔵LEDのピン(LED_BUILTIN)を出力モードに設定

        led := machine.LED

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


        for {

                // LEDを点灯

                led.High()

                time.Sleep(time.Millisecond * 500)


                // LEDを消灯

                led.Low()

                time.Sleep(time.Millisecond * 500)

        }

}

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

package main
import(
    "machine"
    "time"
)

func main(){
    button1 := machine.BUTTON_1
    button1.Configure(machine.PinConfig{Mode: machine.PinInput})
    led := machine.LED
    led.Configure(machine.PinConfig{Mode: machine.PinOutput})

        button1.SetInterrupt(machine.PinToggle, func(machine.Pin){
    // button1が変化したときledを操作する
        led.Set(button1.Get())
    })

    for {   
          // simulate heavy work
      time.Sleep(1*time.Second)
     }

 }

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


 package main
import (
    "bufio"
    "fmt"
    "os"
    "time"
)

func main(){
    time.Sleep(2 * time.Second)
    fmt.Printf("hello tinygo\r\n")

    msg := ""
    fmt.Scanf("%s\r\n", &msg)
    fmt.Printf("msg: %q\r\n",msg)

        scanner := bufio.NewScanner(os.Stdin)
    for scanner.Scan(){
        fmt.Printf("you typed: %s\r\n",scanner.Text())
    }
}

2026年8月27日木曜日

wioterminal and grove sht35(I2C)

#include <Wire.h>

#include "Seeed_SHT35.h"

#define SCL_PIN SCL // preset variables, ie builtin

SHT35 sensor(SCL_PIN, 0x45); // 0x45 by I2C scan,in my case

void setup()
{
Serial.begin(115200);
delay(1000);

Wire.begin();

Serial.println("Wio Terminal + Grove SHT35");

if (sensor.init())
{
Serial.println("SHT35 init failed!");
return;
}

Serial.println("SHT35 init OK");
}

void loop()
{
float temperature;
float humidity;

int ret = sensor.read_meas_data_single_shot(
HIGH_REP_WITH_STRCH,
&temperature,
&humidity
);

Serial.print("ret = ");
Serial.println(ret);

if (ret == NO_ERROR)
{
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
else
{
Serial.println("SHT35 read failed!");
}

delay(2000);
}

2026年8月26日水曜日

wioterminal and grove hc-sr04ranger(no I2C!)

なんとI2C仕様でなかった grove dht11 と同じだった!

 #include "Ultrasonic.h"


Ultrasonic ultrasonic(0);#include "Ultrasonic.h"

Ultrasonic ultrasonic(0);

void setup()
{
Serial.begin(115200);
delay(1000);

Serial.println("Grove Ultrasonic Ranger");
Serial.println(" cm");

delay(500);
}

void setup()
{
Serial.begin(115200);
delay(1000);

Serial.println("Grove Ultrasonic Ranger");
}

void loop()
{
float distance;

distance = ultrasonic.MeasureInCentimeters();

Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

delay(500);
}

tinygo on raspberry pi pico (not picow)

 https://github.com/otakakot/sample-tinygo-raspberry-pi-pico

2026年8月24日月曜日

mmbasic web-led-controll-server成功

 ' command lineでOPTION WIFI "Pikara2-91d8e4","090e219cbdbf5" 

' つづいて option tcp server port 80

'再設定のためのリセットはoption wifi off,option tcp server 0 

ーーーーーーーーーーー WebMite V6.02.01 最小Webサーバーーーーーーーーー

' HTMLファイルを作成

Open "index.html" For Output As #1

Print #1, "<!DOCTYPE html>"

Print #1, "<html>"

Print #1, "<head>"

Print #1, "<meta charset=""UTF-8"">"

Print #1, "<title>WebMite</title>"

Print #1, "</head>"

Print #1, "<body>"

Print #1, "<h1>Hello WebMite!</h1>"

Print #1, "<p>Pico2W WebMite V6.02.01</p>"

Print #1, "</body>"

Print #1, "</html>"

Close #1

' TCPサーバーからの要求を受け取る

WEB TCP INTERRUPT WebInterrupt


Print "Web server started"

Print "IP address = "; MM.INFO(IP ADDRESS)

Do

    Pause 1000

Loop


' HTTPリクエスト処理

Sub WebInterrupt


    Local a%, p%, t%

    Local buff%(4096/8)


    For a% = 1 To MM.INFO(MAX CONNECTIONS)

        WEB TCP READ a%, buff%()

        p% = LINSTR(buff%(), "GET")

        t% = LINSTR(buff%(), "HTTP")

        If (p% <> 0) And (t% > p%) Then

            WEB TRANSMIT PAGE a%, "index.html"

        EndIf

    Next a%

End Sub

---------最終的にled-on-off-serverは以下のとうり

' ==========================================

' WebMite V6.02.01

' LED ON/OFF Webサーバー

' LED = GP15

' ==========================================

' --- HTMLファイル作成 ---

Open "index.html" For Output As #1

Print #1, "<!DOCTYPE html>"

Print #1, "<html>"ーーーーーーーー

Print #1, "<head>"

Print #1, "<meta charset=""UTF-8"">"

Print #1, "<meta name=""viewport"" content=""width=device-width,initial-scale=1"">"

Print #1, "<title>WebMite LED Control</title>"

Print #1, "</head>"

Print #1, "<body style=""font-family:sans-serif;text-align:center;padding-top:50px"">"

Print #1, "<h1>WebMite LED Control</h1>"

Print #1, "<p>GP15 LED</p>"

Print #1, "<p>"

Print #1, "<a href=""/?cmd=on"">"

Print #1, "<button style=""font-size:24px;padding:15px 30px"">LED ON</button>"

Print #1, "</a>"

Print #1, "</p>"

Print #1, "<p>"

Print #1, "<a href=""/?cmd=off"">"

Print #1, "<button style=""font-size:24px;padding:15px 30px"">LED OFF</button>"

Print #1, "</a>"

Print #1, "</p>"

Print #1, "</body>"

Print #1, "</html>"

Close #1


' --- LED設定 ---

SetPin GP15, DOUT

Pin(GP15) = 0


' --- TCP要求を割り込みで受け取る ---

WEB TCP INTERRUPT WebInterrupt


Print "Web server started"

Print "IP address = "; MM.INFO(IP ADDRESS)


' --- メインループ は、なにもしない---

Do

    Pause 1000

Loop


' ==========================================

' HTTPリクエスト処理

' ==========================================

Sub WebInterrupt

    Local a%, p%, t%

    Local buff%(4096/8)

    For a% = 1 To MM.INFO(MAX CONNECTIONS) // connectionごとの処理

        WEB TCP READ a%, buff%()

        p% = LINSTR(buff%(), "GET") 

// LINSTR(buff%(), "GET") は、MMBasicで 文字列配列 buff%() の中から

// "GET" が出てくる位置を探す       

 t% = LINSTR(buff%(), "HTTP")

// 以上も同様

        If (p% <> 0) And (t% > p%) Then

            ' LED ON

            If LINSTR(buff%(), "?cmd=on") <> 0 Then

                Pin(GP15) = 1

                Print "LED ON"

            EndIf

            ' LED OFF

            If LINSTR(buff%(), "?cmd=off") <> 0 Then

                Pin(GP15) = 0

                Print "LED OFF"

            EndIf

            ' HTMLを送信

            WEB TRANSMIT PAGE a%, "index.html" // connection a%へHTMLを送る

        EndIf

    Next a%

End Sub

2026年8月23日日曜日

tinygo for pico and pico-sdk and pico-examples

 cf https://zenn.dev/askua/articles/05e143091c150c :: tinygo for pico

https://gihyo.jp/admin/serial/01/ubuntu-recipe/0684で成功した pico-sdk and pico-sdk-examples


CMakeを使った「Hello, World!」プログラムの最も簡単な作り方と実行手順は、設定ファイルとソースコードを作成してビルドすることです。 [1, 2]
1. ファイルの準備
同じディレクトリに以下の2つのファイルを作成します。
  • CMakeLists.txt(CMakeの設定ファイル)
cmake
cmake_minimum_required(VERSION 3.10)
project(HelloWorld)

add_executable(helloworld main.cpp)
コードは注意してご使用ください。
  • main.cpp(C++のソースコード) [1]
cpp
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
コードは注意してご使用ください。
2. ビルドと実行の手順
ターミナル(コマンドプロンプト)を開き、プロジェクトのディレクトリで以下のコマンドを順番に実行します。 [1]
bash
mkdir build
cd build
cmake ..
cmake --build .
コードは注意してご使用ください。
3. 実行ファイルの動かし方
ビルドが成功すると build ディレクトリ内に実行ファイル(Windowsでは helloworld.exe、Linux/Macでは helloworld)が作成されます。 [1]
  • 実行コマンド(Linux/Macの場合):
bash
./helloworld
コードは注意してご使用ください。
画面に Hello, World! と表示されます。