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日日曜日

pico-sdk and pico-examples

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


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! と表示されます。

groveシステムのメモ obniz and grove-sht35

 https://qiita.com/nanbuwks/items/b79f53b46f289ec9d411

pin 1 - Yellow (for example, SCL on I2C Grove Connectors)

pin 2 - White (for example, SDA on I2C Grove Connectors)

pin 3 - Red - VCC on all Grove Connectors

pin 4 - Black - GND on all Grove Connectors

これだけわかればOK

------アプリ開発で成功 書斎ではhuaweiのアクセスポイントでのみ成功 電波よわいか-------

html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/obniz@3.x/obniz.js" crossorigin="anonymous" ></script>
</head>
<body>

<div class="container">
<h1>SHT35 温湿度モニター</h1>
<div id="status" class="status">obnizに接続中...</div>
<div class="data">
温度: <span id="temp">--.-</span>
</div>
<div class="data">
湿度: <span id="humi">--.-</span> %
</div>
</div>

<script>

// 1. 自分のobniz IDを指定
const obniz = new Obniz("OBNIZ_ID_HERE");

// 2. obnizに接続完了したときの処理
obniz.onconnect = async function () {

document.getElementById("status").innerText =
"接続成功。データ取得中...";

// 3. SHT35のピン割り当て
const sht35 = obniz.wired("Grove_SHT35Sensor", {
gnd: 0,
vcc: 1,
sda: 2,
scl: 3
});

// 4. 3秒ごとに測定
setInterval(async function () {

try {

// ★ getAllData() ではなく getAllWait()
const data = await sht35.getAllWait();

if (data) {

document.getElementById("temp").innerText =
data.temperature.toFixed(1);

document.getElementById("humi").innerText =
data.humidity.toFixed(1);

document.getElementById("status").innerText =
"データ更新完了(3秒間隔)";

console.log(
"温度:", data.temperature,
"湿度:", data.humidity
);
}

} catch (error) {

document.getElementById("status").innerText =
"データ取得エラー";

console.error(error);
}

}, 3000);
};

// 切断時
obniz.onclose = function () {

document.getElementById("status").innerText =
"obnizとの接続が切断されました";
};
</script>
</body>
</html>

2026年8月19日水曜日

mmbasic led fade 成功

 SetPin GP0, PWM 

PWM 0, 1000, 0  ' PWMチャンネル0を1kHz、デューティ比0%で開始Do

 For duty = 0 To 100 Step 2

    PWM 0, 1000, duty

    Pause 20

 Next duty

 For duty = 0 To 100 Step -2

    PWM 0, 1000, duty

    Pause 20

 Next duty

Loop


2026年8月17日月曜日

FreeRTOS on Raspberry Pi Pico (ツールのOperating SystemでMPを選択)

書き込む際には、予めBOOTbuttonをつかってuf2が書き込めるようにしておく

書き込んだらIDEを閉じて再度開いてシリアルモニタする

 /******************************************************

 * FreeRTOS Mutex例題

 * - タスク2つ

 * 共有データの競合回避

 ******************************************************/

SemaphoreHandle_t xMutex;     

// Mutex変数定義 freertosではSemaphoreをMutexにも使う

volatile int sharedCounter = 0;   // 共有リソース、

// volatile をつけると、「この変数は外部から書き換わるかもしれないので、毎回メモリからちゃんと読み込んで」と指示できます

//==== タスク1 カウント値Serial送信 ====

void Task1(void *pvParameters) {

  while(1){

    if(xSemaphoreTake(xMutex, portMAX_DELAY)== pdTRUE){

// // 例:100ミリ秒だけ待つ設定(pdMS_TO_TICKSでミリ秒をシステム時間に変換) if (xSemaphoreTake(xMutex, pdMS_TO_TICKS(100)) == pdTRUE) { // 100ms以内にMutexを取れた場合の処理 xSemaphoreGive(xMutex); } else { // 100ms待っても取れなかった場合のタイムアウト処理 }

      int temp = sharedCounter;       // 共有データ取得

      temp++;

      vTaskDelay(pdMS_TO_TICKS(10));  // あえて遅延を入れて競合を誘発

      sharedCounter = temp;           // 共有データ更新

      Serial.printf("Task1: counter=%d\n", sharedCounter);

      xSemaphoreGive(xMutex); // MUTEX解放

    }

  }

}

//==== タスク2 カウント値Serial送信 ====

void Task2(void *pvParameters) {

  while(1){

    if(xSemaphoreTake(xMutex, portMAX_DELAY)== pdTRUE){

      int temp = sharedCounter;       // 共有データ取得

      temp++;

      vTaskDelay(pdMS_TO_TICKS(10));  // あえて遅延を入れて競合を誘発

      sharedCounter = temp;           // 共有データ更新

      Serial.printf("Task2: counter=%d\n", sharedCounter);

      xSemaphoreGive(xMutex);  

    }    

  }

}

//==== 初期設定 ====

void setup() {

  Serial.begin(115200);

  delay(1000);

  // 開始メッセージ

  Serial.println("\r\n=== Mutex counter demo ===");

  // Mutex生成

  xMutex = xSemaphoreCreateMutex(); //xTaskCreateで自動的に組み込まれる?

  // タスクの生成

  xTaskCreate(Task1, "task1", 2048, NULL, 1, NULL);

// xTaskCreate(Task1, "task1", 2048, NULL, 1, NULL);

                     ②       ③     ④   ⑤   ⑥
コードは注意してご使用ください。
番号引数意味詳しい説明
Task1実行する関数名タスクとして動かしたいC言語の関数を指定します。
"task1"タスクの作業名人間が見て分かりやすくするための名前です(デバッグ用)。
2048スタックサイズこのタスクがメモリ(スタック)を何バイト使うか(※)の指定です。
NULL関数への引数タスク関数にデータを渡さない場合は NULL にします。
1タスクの優先度数字が大きいほど優先されます。標準的な低い優先度です。
NULLタスクハンドル作成したタスクを後から削除・操作しない場合は NULL にします。
※注意(スタックサイズの単位について)
ESP32(Arduino等)では「バイト数(2048バイト)」ですが、一般的なFreeRTOS(マイコンによる)では「ワード数(4バイト単位なら2048×4=8192バイト)」を意味します。ESP32環境であれば2KBのメモリ確保という意味になります。

  xTaskCreate(Task2, "task2", 2048, NULL, 1, NULL);

}

//= アイドルループ ==

void loop() {}

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