雑感

2025年4月29日火曜日

ArduinoUnoR4Wifi(SDcard,PIEZO,DHT11,SERVO,CDS)



https://docs.sunfounder.com/projects/elite-explorer-kit/ja/latest/iot_projects/00_iot_project.html
un r4 wifi 日本語サイト

https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-dc-motor
r4の詳しい説明あり
-------------------------------------------------

 PIEZO,DHT11,SERVO,WS2812(真ん中が信号、赤Vcc、白Gnd)OK

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

https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-micro-sd-card

---------------- first :: file create on sdcard ----------------------

#include <SD.h>

#define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard module

File myFile;

void setup() {

  Serial.begin(9600);

  if (!SD.begin(PIN_SPI_CS)) {

    Serial.println(F("SD Card is either missing or has failed!"));

    while (1); // don't do anything more:

  }

  Serial.println(F("SD Card is ready"));

  if (!SD.exists("arduino.txt")) {

    Serial.println(F("arduino.txt doesn't exist. Creating arduino.txt file..."));

    // create a new file by opening a new file and immediately close it

    myFile = SD.open("arduino.txt", FILE_WRITE);

    myFile.close();

  }


  // recheck if file is created or not

  if (SD.exists("arduino.txt"))

    Serial.println(F("arduino.txt exists on SD Card."));

  else

    Serial.println(F("arduino.txt doesn't exist on SD Card."));

}


void loop() {

}

-----------------second :: data write (append) on sdcard--------------------------------------

#include <SD.h> #define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard module File myFile; void setup() { Serial.begin(9600); if (!SD.begin(PIN_SPI_CS)) { Serial.println(F("SD Card is either missing or has failed!")); while (1); // don't do anything more: } Serial.println(F("SD Card is ready")); // open file for writing myFile = SD.open("arduino.txt", FILE_WRITE); if (myFile) { myFile.println("Created by newbiely.com"); // write a line to Arduino myFile.println("Learn Arduino and SD Card"); // write another line to Arduino myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } // open file for reading myFile = SD.open("arduino.txt", FILE_READ); if (myFile) { int line_count = 0; while (myFile.available()) { char line[100]; // maximum is 100 characters, change it if needed int line_length = myFile.readBytesUntil('\n', line, 100); // read line-by-line from Micro SD Card line_count++; Serial.print(F("Line ")); Serial.print(line_count); Serial.print(F(": ")); Serial.write(line, line_length); // print the character to Serial Monitor // \n character is escaped by readBytesUntil function Serial.write('\n'); // print a new line charactor } myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } } void loop() { }

-------------third:: file read on sdcard------------------------------

#include <SD.h> #define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard module File myFile; void setup() { Serial.begin(9600); if (!SD.begin(PIN_SPI_CS)) { Serial.println(F("SD Card is either missing or has failed!")); while (1); // don't do anything more: } Serial.println(F("SD Card is ready")); // open file for writing myFile = SD.open("arduino.txt", FILE_WRITE); if (myFile) { myFile.println("Created by newbiely.com"); // write a line to Arduino myFile.println("Learn Arduino and SD Card"); // write another line to Arduino myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } // open file for reading myFile = SD.open("arduino.txt", FILE_READ); if (myFile) { int line_count = 0; while (myFile.available()) { char line[100]; // maximum is 100 characters, change it if needed int line_length = myFile.readBytesUntil('\n', line, 100); // read line-by-line from Micro SD Card line_count++; Serial.print(F("Line ")); Serial.print(line_count); Serial.print(F(": ")); Serial.write(line, line_length); // print the character to Serial Monitor // \n character is escaped by readBytesUntil function Serial.write('\n'); // print a new line charactor } myFile.close(); } else { Serial.print(F("Error: Unable to open file arduino.txt")); } } void loop() { }

--------------- file delete is dangerous ---
単なるテキストファイルのremoveなのでsdcardからファイルを移してシェルでできる。。。

基本プロジェクト

センサー

  • フォトレジスタ
  • サーミスタ
  • 土壌湿度
  • チルトスイッチ
  • PIR動作センサーモジュール
  • 超音波
  • 湿度・温度センサーモジュール
  • RFID-RC522モジュール
  • GY-87 IMUモジュール

ディスプレイ

  • LEDモジュール
  • RGB LED
  • WS2812 RGB LEDストリップ
  • 7セグメントディスプレイ
  • I2C LCD1602
  • OLED

サウンド

  • アクティブブザー
  • パッシブブザー
  • オーディオモジュールとスピーカー

コントローラー

  • ボタン
  • ポテンショメータ
  • ジョイスティックモジュール
  • キーパッド
  • 赤外線レシーバー
  • MPR121

アクチュエーター

  • モーター
  • 水ポンプ
  • ステッピングモーター
  • サーボ
  • リレー

チップ

  • 74HC595
 
投稿者 fseigojp 時刻: 16:53 0 件のコメント:
メールで送信BlogThis!X で共有Facebook で共有するPinterest に共有

nodejs or go sqlite3 examples

----nodejs and sqlite3--------------

https://iifx.dev/ja/articles/73325552 

const db = require('better-sqlite3')('database.sqlite');


// データベースに接続する

const db = require('better-sqlite3')('database.sqlite');


// テーブルが存在しなければ作成する

db.exec(`

CREATE TABLE IF NOT EXISTS users (

  id INTEGER PRIMARY KEY AUTOINCREMENT,

  name TEXT NOT NULL,

  email TEXT UNIQUE NOT NULL

)

`);


// ユーザーを挿入する

db.prepare('INSERT INTO users (name, email) VALUES (?, ?)').run('Taro Yamada', 'taro.yamada@example.com');

db.prepare('INSERT INTO users (name, email) VALUES (?, ?)').run('Hanako Sato', 'hanako.sato@example.com');


// 全てのユーザーを取得する

const rows = db.prepare('SELECT * FROM users').all();

console.log(rows);


// 特定のユーザーを取得する

const user = db.prepare('SELECT * FROM users WHERE id = ?').get(1);

console.log(user);


--go and sqite3-----------------------------------------------

 https://zenn.dev/tara_is_ok/articles/15b04694466bec :: examples

--- test2.go --- create table if not exist ------------

package main

import (

"database/sql"

"log"

_ "github.com/mattn/go-sqlite3" //ビルド時にコンパイルすることでSQLにアクセス出来る

)

var DbConnection *sql.DB


func main(){

DbConnection, _ := sql.Open("sqlite3", "./example.db")

defer DbConnection.Close()

cmd := `CREATE TABLE IF NOT EXISTS person(

name STRING,

age INT

)`

//cmdを実行する

_, err := DbConnection.Exec(cmd) 

//データベースの情報を反映する必要はないため、_を使用

if err != nil{

log.Fatalln(err)

}

}


投稿者 fseigojp 時刻: 16:07 0 件のコメント:
メールで送信BlogThis!X で共有Facebook で共有するPinterest に共有

2025年4月27日日曜日

go sqlite on ubuntu OK

 https://zenn.dev/teasy/articles/go-sqlite3-sample でドライバ導入

https://zenn.dev/tara_is_ok/articles/15b04694466bec でも成功

例題のexample.sqlはexample.dbと改変した

table create,data insert,data delete 成功

https://wp.kobore.net/2022/01/03/post-4905/ で成功


package main

import (
	"database/sql"
	"fmt"
	"log"
	"os"

	_ "github.com/mattn/go-sqlite3"
)

func main() {
	os.Remove("./foo.db") // あれば消去!
	fmt.Println("----->10")

	db, err := sql.Open("sqlite3", "./foo.db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	sqlStmt := `
	create table foo (id integer not null primary key, name text);
	delete from foo;
	`
	_, err = db.Exec(sqlStmt)
	if err != nil {
		log.Printf("%q: %s\n", err, sqlStmt)
		return
	}

	fmt.Println("----->9")

	tx, err := db.Begin()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("----->8")

	stmt, err := tx.Prepare("insert into foo(id, name) values(?, ?)")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()
	for i := 0; i < 100; i++ {
		_, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i))
		if err != nil {
			log.Fatal(err)
		}
	}
	tx.Commit()

	fmt.Println("----->7")

	rows, err := db.Query("select id, name from foo")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()
	for rows.Next() {
		var id int
		var name string
		err = rows.Scan(&id, &name)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(id, name)
	}

	fmt.Println("----->6")

	err = rows.Err()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("----->5")

	stmt, err = db.Prepare("select name from foo where id = ?")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()
	var name string
	err = stmt.QueryRow("3").Scan(&name)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(name)

	fmt.Println("----->4")

	_, err = db.Exec("delete from foo")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("----->3")

	_, err = db.Exec("insert into foo(id, name) values(1, 'foo'), (2, 'bar'), (3, 'baz')")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("----->2")

	rows, err = db.Query("select id, name from foo")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()
	for rows.Next() {
		var id int
		var name string
		err = rows.Scan(&id, &name)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(id, name)
	}

	fmt.Println("----->1")

	err = rows.Err()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("----->0")

}

投稿者 fseigojp 時刻: 19:42 0 件のコメント:
メールで送信BlogThis!X で共有Facebook で共有するPinterest に共有
新しい投稿 前の投稿 ホーム
登録: コメント (Atom)

自己紹介

fseigojp
詳細プロフィールを表示

ブログ アーカイブ

  • ▼  2025 (127)
    • ►  11月 (15)
    • ►  10月 (17)
    • ►  9月 (7)
    • ►  5月 (41)
    • ▼  4月 (21)
      • ArduinoUnoR4Wifi(SDcard,PIEZO,DHT11,SERVO,CDS)
      • nodejs or go sqlite3 examples
      • go sqlite on ubuntu OK
      • go and firestore データ操作の成功例
      • Python3 or Nodejs uart to uno
      • unoR4wifiからuartでgoでdhtデータ受信(picocomで十分だが。。)
      • ArduinoUnoR4Wifi(dht11,rtc,L298,buzzer)
      • UNO TO GO VIA UART / go and firestore (最重要)
      • esp8266 led-server
      • Cloud Firestore 一応の到達点
      • Nodejs:: firebase firestore function
      • golang in raspi/gobot-firmata(led,lm35,servo)
      • NoJohnny5-Nodejs for RasPi::ledpwm,aqm0802,onoff/b...
      • raspberry pi :: nvm (nodejs and npm latest install...
      • Arduino R4 WiFi tutorial ウブンツで成功!
      • golang ubuntuついでにgobot-firmata成功
      • Kaluma(3)-esp01-AT (tutorial:connecting to internet)
      • FirebaseRtdb一応の到達点
      • Kaluma(2nd) speaker,tm1367,hcsr04,max7219,mcp3008,...
      • Nodejs :: xcratch/ cnako3 / Johynny5 &express&fbrt...
      • RasPicoWでfirebase-rtdb(単なるhttps get)
    • ►  3月 (13)
    • ►  2月 (5)
    • ►  1月 (8)
  • ►  2024 (62)
    • ►  12月 (3)
    • ►  11月 (2)
    • ►  10月 (1)
    • ►  9月 (2)
    • ►  8月 (3)
    • ►  7月 (6)
    • ►  6月 (9)
    • ►  5月 (7)
    • ►  4月 (4)
    • ►  3月 (9)
    • ►  2月 (9)
    • ►  1月 (7)
  • ►  2023 (51)
    • ►  12月 (4)
    • ►  11月 (5)
    • ►  10月 (4)
    • ►  9月 (2)
    • ►  8月 (2)
    • ►  7月 (8)
    • ►  6月 (3)
    • ►  5月 (4)
    • ►  4月 (5)
    • ►  3月 (5)
    • ►  2月 (4)
    • ►  1月 (5)
  • ►  2022 (44)
    • ►  12月 (2)
    • ►  11月 (6)
    • ►  10月 (4)
    • ►  9月 (2)
    • ►  8月 (4)
    • ►  7月 (4)
    • ►  6月 (3)
    • ►  5月 (4)
    • ►  4月 (5)
    • ►  3月 (1)
    • ►  2月 (3)
    • ►  1月 (6)
  • ►  2021 (26)
    • ►  12月 (5)
    • ►  11月 (5)
    • ►  10月 (4)
    • ►  9月 (1)
    • ►  8月 (2)
    • ►  7月 (2)
    • ►  6月 (1)
    • ►  5月 (2)
    • ►  3月 (1)
    • ►  2月 (1)
    • ►  1月 (2)
  • ►  2020 (16)
    • ►  12月 (1)
    • ►  11月 (2)
    • ►  10月 (3)
    • ►  9月 (1)
    • ►  8月 (1)
    • ►  7月 (2)
    • ►  6月 (2)
    • ►  5月 (2)
    • ►  4月 (1)
    • ►  3月 (1)
  • ►  2019 (11)
    • ►  12月 (1)
    • ►  11月 (2)
    • ►  10月 (4)
    • ►  4月 (1)
    • ►  2月 (2)
    • ►  1月 (1)
  • ►  2018 (13)
    • ►  12月 (1)
    • ►  8月 (1)
    • ►  7月 (1)
    • ►  5月 (2)
    • ►  2月 (1)
    • ►  1月 (7)
  • ►  2017 (32)
    • ►  12月 (2)
    • ►  11月 (1)
    • ►  10月 (2)
    • ►  9月 (1)
    • ►  7月 (1)
    • ►  6月 (2)
    • ►  5月 (4)
    • ►  4月 (18)
    • ►  2月 (1)
  • ►  2016 (24)
    • ►  11月 (2)
    • ►  10月 (2)
    • ►  9月 (3)
    • ►  8月 (1)
    • ►  7月 (1)
    • ►  6月 (3)
    • ►  5月 (5)
    • ►  4月 (5)
    • ►  3月 (2)
  • ►  2015 (10)
    • ►  11月 (1)
    • ►  10月 (2)
    • ►  6月 (1)
    • ►  5月 (1)
    • ►  4月 (1)
    • ►  2月 (2)
    • ►  1月 (2)
  • ►  2014 (8)
    • ►  9月 (5)
    • ►  8月 (1)
    • ►  4月 (1)
    • ►  3月 (1)
「シンプル」テーマ. Powered by Blogger.