https://qiita.com/akif999/items/0d49d83718df4e94809b
UART を使ってマイコンボード - PC (Go のプログラム) 間で通信する
FROM UNO::
//# include <SoftwareSerial.h>
//SoftwareSerial mySerial(0, 1);
byte sendData = 0;
// the setup function runs once when you press reset or power the board
void setup() {
//mySerial.begin(115200);
Serial.begin(115200);
}
// the loop function runs over and over again forever
void loop() {
//mySerial.write(sendData);
Serial.write(sendData);
sendData++;
delay(100);
}
でunoからデータを送る、これは色んなものにできる
-------------------
TO GO
import (
"fmt"
"log"
"github.com/tarm/serial"
)
func main() {
c := &serial.Config{Name: "/dev/ttyACM0", Baud: 115200, Parity: serial.ParityNone, StopBits: serial.Stop1}
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
}
buf := make([]byte, 32)
for {
n, err := s.Read(buf)
if err != nil {
log.Fatal(err)
}
fmt.Println(buf[:n])
}
}
これでunoからpcにくるdataを表示している
---------------------------------go and firestore-----------------------------------------------------------
go.mod ::
module github/fseigojp/sample-go-prj
go 1.23.0
と書いておく そして
go mod tidy でgo.sumをつくる
https://qiita.com/kawamou/items/5e71c0b2124f6650bc46を参考にして
export GOOGLE_CLOUD_PROJECT="my-firestore-3cfe2" これが最重要
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package main
2
3import (
4 "context"
5 "log"
6
7 firebase "firebase.google.com/go"
8 "google.golang.org/api/option"
9)
10
11func main() {
12 // Use a service account
13 ctx := context.Background()
14 sa := option.WithCredentialsFile("./path/serviceAccount.json")
15 app, err := firebase.NewApp(ctx, nil, sa)
16 if err != nil {
17 log.Fatalln(err)
18 }
19
20 client, err := app.Firestore(ctx)
21 if err != nil {
22 log.Fatalln(err)
23 }
24 defer client.Close()
25}ここまで一応成功したhttps://rightcode.co.jp/blogs/8047 で挿入成功!
0 件のコメント:
コメントを投稿