Skip to content

Instantly share code, notes, and snippets.

/****************************************************************
* ESP32-S3 I2S Mic (MSM261S4030H0R)
* - Stream เสียงออก Web server (WAV)
* - บันทึกลง SD card ต่อเนื่อง ตัดไฟล์ทุก 30 นาที
* - flush + patch header ทุก 2 วิ กันไฟล์เสียเมื่อค้าง/ไฟดับ
* - SD self-test ตอนเริ่ม + สแกนเลขไฟล์กันทับ
* - ตั้งชื่อไฟล์ด้วย timestamp จาก NTP
* - ปุ่มหยุด/เริ่มบันทึกบนหน้าเว็บ
*
* Hardware:
#include <Wire.h>
// I2C Address ของ SCD4x ตาม Datasheet คือ 0x62
const uint8_t SCD4X_ADDRESS = 0x62;
// คำสั่ง (Commands) แบบ 16-bit
const uint16_t CMD_START_PERIODIC_MEASUREMENT = 0x21b1;
const uint16_t CMD_READ_MEASUREMENT = 0xec05;
const uint16_t CMD_GET_DATA_READY_STATUS = 0xe4b8;
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
// ---------------------------------------------------
// กำหนดขา SDA และ SCL ใหม่ตรงนี้ได้ตามใจชอบเลยครับ
// ตัวอย่างนี้ผมสมมติให้ใช้ GPIO 21 และ GPIO 22
// ---------------------------------------------------
#define CUSTOM_SDA 21
#define CUSTOM_SCL 22
#include <Wire.h>
#include <SparkFun_VL53L5CX_Library.h> // ต้องติดตั้งไลบรารีนี้ก่อน
// กำหนดขา I2C สำหรับ ESP32
#define SDA_PIN 21
#define SCL_PIN 22
// สร้างออบเจกต์สำหรับเซ็นเซอร์
SparkFun_VL53L5CX myImager;
VL53L5CX_ResultsData measurementData; // ตัวแปรเก็บค่าที่อ่านได้
// A basic everyday NeoPixel strip test program.
// NEOPIXEL BEST PRACTICES for most reliable operation:
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
// connect GROUND (-) first, then +, then data.
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
/************************************************************
* @file Basic_I2C.ino
* @author 7Semi
* @date 2025-07-09
* @version 1.0.1
* @license MIT
*
* @brief Example sketch to demonstrate BME690_7semi library in I2C mode.
*
* This sketch initializes the BME690 sensor using I2C interface,
/************************************************************
* @file Basic_SPI.ino
* @author 7Semi
* @date 2025-07-09
* @version 1.0.1
* @license MIT
*
* @brief Example sketch to demonstrate BME690_7semi library in SPI mode.
*
* This sketch initializes the BME690 sensor using the SPI interface,
#include <SPI.h>
#include <SD.h>
// --- กำหนดขา Input ---
const int inputPins[] = {1, 3, 4, 5};
const int numInputs = 4;
// --- กำหนดขา Output (Relay) ---
const int relayPins[] = {6, 7, 15, 16};
const int numRelays = 4;
/*
ENS160 eCO2 Sensor with AHT21 T/H Sensor
ens160.ino
Reads TVOC/eCO2/AQI and compensates with AHT21 T/RH
Requires SparkFun_ENS160 Library
Requires Adafruit_AHTX0 Library
Uses Seeeduino XIAO ESP32-S3, adjust pins for other ESP32
DroneBot Workshop 2025
https://dronebotworkshop.com
//ESP32 version 2.0.17
#include <Arduino_GFX_Library.h>
#include <Wire.h>
#include "TCA9554.h"
#define GFX_BL 6 // default backlight pin
#define SPI_MISO 2
#define SPI_MOSI 1