https://zenn.dev/askua/articles/05e143091c150c :: tinygo for pico
esp01でat commandつかっていく picowはめんどげ
https://zenn.dev/askua/articles/05e143091c150c :: tinygo for pico
esp01でat commandつかっていく picowはめんどげ
まずはwifi-connectから
chap4_jpeg 以下のように変更(チャットくんにきいた)
tinygo build -target=wioterminal -o wioterminal_blink.uf2 main.go flashうまくいかん
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
lsblk
Arduino というラベルや、FAT16/FAT32の小さなドライブ(数MB程度)が見つかるか確認します。/media/arduino にマウントする場合)。sudo mkdir -p /media/arduino
sudo mount /dev/sdX1 /media/arduino # /dev/sdX1はlsblkで確認したデバイス名に変更
/media/arduino を開いて .uf2 ファイルをドラッグ&ドロップまたはコピーします。sudo apt update
sudo apt install gvfs-backends udisks2
lsblk または dmesg コマンドで、接続されたストレージのパス(例: /dev/sdb や /media/...)を確認します。/media/username/Arduino のように自動割当てされているが中身が見えない場合は、直接 cp コマンドで転送を試します。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())
}
}
#include <Wire.h>
#include "Seeed_SHT35.h"
なんとI2C仕様でなかった grove dht11 と同じだった!
#include "Ultrasonic.h"
https://github.com/otakakot/sample-tinygo-raspberry-pi-pico
https://github.com/soypat/cyw43439 これは理解できたらpico2wを買いたいが。。。。
' 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
https://gihyo.jp/admin/serial/01/ubuntu-recipe/0684で成功した pico-sdk and pico-sdk-examples
https://zenn.dev/waruby/articles/080ab591fab3b1 は未踏。。。
main.cpp (ソースコード)#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
CMakeLists.txt (ビルド設定)cmake_minimum_required(VERSION 3.10)
project(HelloWorld)
add_executable(hello main.cpp)
mkdir build
cd build
cmake ..
cmake --build .CMakeLists.txt(CMakeの設定ファイル)cmake_minimum_required(VERSION 3.10)
project(HelloWorld)
add_executable(helloworld main.cpp)
main.cpp(C++のソースコード) [1]#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
mkdir build
cd build
cmake ..
cmake --build .
./helloworld
Hello, World! と表示されます。