package main
import (
"machine"
"time"
)
func main(){
led := machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
for {
led.Low()
time.Sleep(1000*time.Millisecond)
led.High()
time.Sleep(1000*time.Millisecond)
}
}
雑感
2026年11月30日月曜日
tinygo wioterminal(blink)
2026年11月15日日曜日
golang mttn sample code(57,167)
simple wifi server and client
-------server and client-------------------------------
package main
import (
"fmt"
"log"
"net"
"time"
)
func main() {
// TCPサーバーに接続
conn, err := net.Dial("tcp", "127.0.0.1:8088")
if err != nil {
log.Fatal("Connect error:", err)
}
defer conn.Close()
fmt.Println("TCP Server Connected!")
// データ送信
for i := 1; i <= 10; i++ {
message := fmt.Sprintf(
"Hello TCP Server! Count=%d\n", i,
)
_, err := conn.Write([]byte(message))
if err != nil {
log.Println("Write error:", err)
return
}
fmt.Print("Send: ", message)
time.Sleep(2 * time.Second)
}
fmt.Println("Client finished.")
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
package main
import (
"fmt"
"io"
"log"
"net"
)
func handleData(conn net.Conn) {
defer conn.Close()
var b [512]byte
for {
n, err := conn.Read(b[:])
if err != nil {
if err != io.EOF {
log.Println("Read error:", err)
}
break
}
if n > 0 {
fmt.Print(string(b[:n]))
}
}
}
func main() {
lis, err := net.Listen("tcp", ":8088")
if err != nil {
log.Fatal(err)
}
defer lis.Close()
fmt.Println("TCP Server started on port 8088")
for {
conn, err := lis.Accept()
if err != nil {
log.Println(err)
continue
}
go handleData(conn)
}
}
----------------------------------------------
p57
package main
import(
"fmt"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
for i:=0;i<20;i++ {
wg.Add(1)
go func(){
defer wg.Done()
fmt.Println(i)
}()
}
for i:=0;i<10;i++ {
fmt.Println("heloo")
time.Sleep(time.Second)
}
wg.Wait()
}
}()
}
for i:=0;i<10;i++ {
fmt.Println("heloo")
time.Sleep(time.Second)
}
wg.Wait()
}
p167
package main
import (
"fmt"
"time"
)
func generator(msg string) <-chan string{
ch:=make(chan string)
go func() {
for i:=0; ; i++ {
ch <- fmt.Sprintf("%s %d", msg, i)
time.Sleep(2*time.Second)
}
}()
return ch
}
func main(){
ch:=generator("hello")
for i:= 0; i<5;i++{
fmt.Println(<-ch)
}
}
2026年11月13日金曜日
tinygo on esp01 wifi access and get ip
esp01:: tinygo flash -target pico -monitor ./main.go このやりかたでないとモニター不調
Connected to /dev/ttyACM0. Press Ctrl-C to exit.
================================
Raspberry Pi Pico + ESP-01
WiFi connection
================================
=> Send: AT
AT
OK
=> Send: AT+CWMODE=1
AT+CWMODE=1
OK
Connecting to WiFi...
SSID: HUAWEInovalite3+
=> Send: AT+CWJAP="HUAWEInovalite3+","99991111"
AT+CWJAP="HUAWEInovalite3+","99991111"
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP
OK
Getting IP address...
=> Send: AT+CIFSR
AT+CIFSR
+CIFSR:STAIP,"192.168.43.33"
+CIFSR:STAMAC,"bc:dd:c2:e7:1e:5c"
OK
==============================
WiFi connected!
IP address: 192.168.43.33
==============================
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
main.go for above response
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package main
import (
"fmt"
"machine"
"strings"
"time"
)
const (
SSID = "HUAWEInovalite3+"
PASSWORD = "99991111"
)
// ==================================================
// ATコマンドをESP-01へ送信して応答を表示
// ==================================================
func sendAT(uart *machine.UART, cmd string, wait time.Duration) string {
fmt.Println("=> Send:", cmd)
// ATコマンド送信
uart.Write([]byte(cmd + "\r\n"))
var buf [256]byte
var response strings.Builder
start := time.Now()
for time.Since(start) < wait { // wait時間内は応答をまつ
// TinyGoでは Read() は (int, error)
n, _ := uart.Read(buf[:])
if n > 0 {
s := string(buf[:n])
// 応答を保存
response.WriteString(s)
// 受信内容を表示
fmt.Print(s)
// OKなら終了
if strings.Contains(response.String(), "OK") {
break
}
// ERRORなら終了
if strings.Contains(response.String(), "ERROR") {
break
}
}
time.Sleep(10 * time.Millisecond)
}
return response.String()
}
// ==================================================
// ESP-01のAT+CIFSR応答からIPアドレスを抽出
//
// 例:
// +CIFSR:STAIP,"192.168.1.20"
// ==================================================
func extractIP(s string) string {
lines := strings.Split(s, "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if strings.Contains(line, "STAIP") {
// 最初の " を探す
start := strings.Index(line, `"`)
if start < 0 {
continue
}
// 2個目の " を探す
end := strings.Index(line[start+1:], `"`)
if end < 0 {
continue
}
return line[start+1 : start+1+end]
}
}
return ""
}
// ==================================================
// メイン
// ==================================================
func main() {
// ==================================================
// Raspberry Pi Pico
//
// GP0 = UART0 TX -> ESP-01 RX
// GP1 = UART0 RX <- ESP-01 TX
//
// GND ------------- GND
// ==================================================
uart := machine.UART0
uart.Configure(machine.UARTConfig{
BaudRate: 115200,
TX: machine.GP0,
RX: machine.GP1,
})
// ESP-01起動待ち
time.Sleep(3 * time.Second)
fmt.Println()
fmt.Println("================================")
fmt.Println(" Raspberry Pi Pico + ESP-01")
fmt.Println(" WiFi connection")
fmt.Println("================================")
fmt.Println()
// ==================================================
// UART受信バッファをクリア 空読みで
// ==================================================
var dummy [64]byte
for uart.Buffered() > 0 {
_, _ = uart.Read(dummy[:])
}
// ==================================================
// ESP-01動作確認
// ==================================================
response := sendAT(
uart,
"AT",
1*time.Second,
)
if strings.Contains(response, "ERROR") {
fmt.Println("ESP-01 did not respond.")
return
}
// ==================================================
// Wi-Fi Stationモード
// ==================================================
sendAT(
uart,
"AT+CWMODE=1",
1*time.Second,
)
// ==================================================
// Wi-Fiアクセスポイントへ接続
// ==================================================
cmd := `AT+CWJAP="` + SSID + `","` + PASSWORD + `"`
fmt.Println()
fmt.Println("Connecting to WiFi...")
fmt.Println("SSID:", SSID)
// 十分時間をとってアクセスする
response = sendAT(
uart,
cmd,
20*time.Second,
)
// Wi-Fi接続エラー
if strings.Contains(response, "ERROR") {
fmt.Println()
fmt.Println("WiFi connection failed.")
return
}
// ==================================================
// IPアドレス取得
// ==================================================
fmt.Println()
fmt.Println("Getting IP address...")
response = sendAT(
uart,
"AT+CIFSR",
3*time.Second,
)
// ==================================================
// IPアドレス抽出
// ==================================================
ip := extractIP(response)
fmt.Println()
if ip != "" {
fmt.Println("==============================")
fmt.Println(" WiFi connected!")
fmt.Println()
fmt.Println(" IP address:", ip)
fmt.Println("==============================")
} else {
fmt.Println("==============================")
fmt.Println(" IP address could not be obtained.")
fmt.Println("==============================")
}
// ==================================================
// ここで停止
// ==================================================
for {
time.Sleep(1 * time.Second)
}
}
2026年11月9日月曜日
tinygo on raspberry pi pico (aqm0802)
import (
"fmt"
"machine"
"time"
)
const (
LCD_ADDR = 0x3E
)
var i2c = machine.I2C0
// LCDコマンド送信
func lcdCommand(cmd byte) {
data := []byte{0x00, cmd}
err := i2c.Tx(LCD_ADDR, data, nil)
if err != nil {
fmt.Println("LCD Command ERROR:", err)
}
time.Sleep(2 * time.Millisecond)
}
// LCDデータ送信
func lcdData(value byte) {
data := []byte{0x40, value}
err := i2c.Tx(LCD_ADDR, data, nil)
if err != nil {
fmt.Println("LCD Data ERROR:", err)
}
}
// LCD初期化
func lcdInit() {
time.Sleep(50 * time.Millisecond)
lcdCommand(0x38)
lcdCommand(0x39)
lcdCommand(0x14)
lcdCommand(0x70)
lcdCommand(0x56)
lcdCommand(0x6C)
time.Sleep(200 * time.Millisecond)
lcdCommand(0x38)
lcdCommand(0x0C)
lcdCommand(0x01)
time.Sleep(5 * time.Millisecond)
lcdCommand(0x06)
fmt.Println("LCD Initialize OK")
}
// カーソル位置指定
func lcdPosition(row byte, col byte) {
if row == 0 {
lcdCommand(0x80 + col)
} else {
lcdCommand(0xC0 + col)
}
}
// 文字列表示
func lcdPrint(str string) {
for i := 0; i < len(str); i++ {
lcdData(str[i])
}
}
// メイン処理
func main() {
fmt.Println("AQM0802 Start")
// I2C0設定 GP4 / GP5
err := i2c.Configure(machine.I2CConfig{
SDA: machine.GP4,
SCL: machine.GP5,
Frequency: 100000,
})
if err != nil {
fmt.Println("I2C ERROR:", err)
for {
time.Sleep(time.Second)
}
}
fmt.Println("I2C Configure OK")
time.Sleep(500 * time.Millisecond)
// LCD初期化
lcdInit()
// 1行目
lcdPosition(0, 0)
lcdPrint("TinyGo!!")
// 2行目
lcdPosition(1, 0)
lcdPrint("AQM0802")
fmt.Println("LCD Display OK")
for {
time.Sleep(time.Second)
}
}
tinygo with esp01でhttp get (ドラフト)
以下をリファクタする。。。。tinygo flash -target pico -monitor ./main.goで成功
tinygo monitorを独立に実行はなかなか起動しない。。。
package main
import (
"fmt"
"machine"
"strings"
"time"
)
const (
SSID = "HUAWEInovalite3+"
PASSWORD = "99991111"
)
// ==================================================
// ATコマンドをESP-01へ送信して応答を表示
// ==================================================
func sendAT(uart *machine.UART, cmd string, wait time.Duration) string {
fmt.Println("=> Send:", cmd)
// ATコマンド送信
uart.Write([]byte(cmd + "\r\n"))
var buf [256]byte
var response strings.Builder
start := time.Now()
for time.Since(start) < wait { // wait時間内は応答をまつ
// TinyGoでは Read() は (int, error)
n, _ := uart.Read(buf[:])
if n > 0 {
s := string(buf[:n])
// 応答を保存
response.WriteString(s)
// 受信内容を表示
fmt.Print(s)
// OKなら終了
if strings.Contains(response.String(), "OK") {
break
}
// ERRORなら終了
if strings.Contains(response.String(), "ERROR") {
break
}
}
time.Sleep(10 * time.Millisecond)
}
return response.String()
}
// ==================================================
// ESP-01のAT+CIFSR応答からIPアドレスを抽出
//
// 例:
// +CIFSR:STAIP,"192.168.1.20"
// ==================================================
func extractIP(s string) string {
lines := strings.Split(s, "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if strings.Contains(line, "STAIP") {
// 最初の " を探す
start := strings.Index(line, `"`)
if start < 0 {
continue
}
// 2個目の " を探す
end := strings.Index(line[start+1:], `"`)
if end < 0 {
continue
}
return line[start+1 : start+1+end]
}
}
return ""
}
// ==================================================
// メイン
// ==================================================
func main() {
// ==================================================
// Raspberry Pi Pico
//
// GP0 = UART0 TX -> ESP-01 RX
// GP1 = UART0 RX <- ESP-01 TX
//
// GND ------------- GND
// ==================================================
uart := machine.UART0
uart.Configure(machine.UARTConfig{
BaudRate: 115200,
TX: machine.GP0,
RX: machine.GP1,
})
// ESP-01起動待ち
time.Sleep(3 * time.Second)
fmt.Println()
fmt.Println("================================")
fmt.Println(" Raspberry Pi Pico + ESP-01")
fmt.Println(" WiFi connection")
fmt.Println("================================")
fmt.Println()
// ==================================================
// UART受信バッファをクリア 空読みで
// ==================================================
var dummy [64]byte
for uart.Buffered() > 0 {
_, _ = uart.Read(dummy[:])
}
// ==================================================
// ESP-01動作確認
// ==================================================
response := sendAT(
uart,
"AT",
1*time.Second,
)
if strings.Contains(response, "ERROR") {
fmt.Println("ESP-01 did not respond.")
return
}
// ==================================================
// Wi-Fi Stationモード
// ==================================================
sendAT(
uart,
"AT+CWMODE=1",
1*time.Second,
)
// ==================================================
// Wi-Fiアクセスポイントへ接続
// ==================================================
cmd := `AT+CWJAP="` + SSID + `","` + PASSWORD + `"`
fmt.Println()
fmt.Println("Connecting to WiFi...")
fmt.Println("SSID:", SSID)
// 十分時間をとってアクセスする
response = sendAT(
uart,
cmd,
20*time.Second,
)
// Wi-Fi接続エラー
if strings.Contains(response, "ERROR") {
fmt.Println()
fmt.Println("WiFi connection failed.")
return
}
// ==================================================
// IPアドレス取得
// ==================================================
fmt.Println()
fmt.Println("Getting IP address...")
response = sendAT(
uart,
"AT+CIFSR",
3*time.Second,
)
// ==================================================
// IPアドレス抽出
// ==================================================
ip := extractIP(response)
fmt.Println()
if ip != "" {
fmt.Println("==============================")
fmt.Println(" WiFi connected!")
fmt.Println()
fmt.Println(" IP address:", ip)
fmt.Println("==============================")
} else {
fmt.Println("==============================")
fmt.Println(" IP address could not be obtained.")
fmt.Println("==============================")
}
// ==================================================
// ここで停止
// ==================================================
for {
time.Sleep(1 * time.Second)
}
}
2026年11月6日金曜日
池澤の日本文学全集 近現代作家3冊
近現代作家1
明治以降の作家の名品を精選し、作品の時代背景順に収める『近現代作家集』。三巻 にわたってお届けする。モダニズム、自然主義、プロレタリア久生十蘭「無月物語」
神西清「雪の宿り」
芥川龍之介「お富の貞操」泉鏡花「陽炎座」
永井荷風「松葉巴」
宮本百合子「風に乗って来るコロポックル」
金子光晴「どくろ杯(抄)」
佐藤春夫「女誡扇綺譚」
横光利一「機械」
高村薫「晴子情歌(抄)」 *
岡本かの子「鮨」*
武田泰淳 汝の母を!
長谷川四郎 駐屯軍演芸大会
里見弴 いろおとこ
安岡章太郎 質屋の女房
色川武大 空襲のあと
坂口安吾 青鬼の褌を洗う女
結城昌治 終着駅(抄)
中野重治 五勺の酒
太宰治 ヴィヨンの妻*
井上ひさし 父と暮せば
井伏鱒二 白毛
吉行淳之介 鳥獣虫魚
久保田万太郎 三の酉
安部公房 誘惑者
室生犀星 鮠の子
川端康成 片腕*
三島由紀夫 孔雀
上野英信 地の底の笑い話(抄)
大庭みな子 青い狐
日本文学の未来を切り拓く名品18篇
内田百閒 日没閉門
野呂邦暢 鳥たちの河口
幸田文 「崩れ」(抄)
富岡多惠子 動物の葬禮
村上春樹 午後の最後の芝生
鶴見俊輔 イシが伝えてくれたこと
池澤夏樹 連夜
津島佑子 鳥の涙
筒井康隆 魚籃観音記
河野多惠子 半所有者
堀江敏幸 スタンス・ドット
向井豊昭 ゴドーを尋ねながら
金井美恵子 『月』について、
稲葉真弓 桟橋
多和田葉子 雪の練習生(抄)なお全部読んだ*
川上弘美 神様/神様2011
川上未映子 三月の毛糸
円城塔 The History of the Decline and Fall of the Galactic Empire