Skip to content

Instantly share code, notes, and snippets.

View maxpromer's full-sized avatar

Max maxpromer

View GitHub Profile
#include "driver/gpio.h"
#include "driver/twai.h"
void setup() {
Serial.begin(115200);
twai_general_config_t g_config = { // สร้างต้วแปร g_config ใช้กำหนดค่าเกี่ยวกับบัส CAN
.mode = TWAI_MODE_NORMAL,
.tx_io = GPIO_NUM_26, // กำหนดขา TX ต่อกับ 26
.rx_io = GPIO_NUM_27, // กำหนดขา TX ต่อกับ 27
// Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <CAN.h> // the OBD2 library depends on the CAN library
#include <OBD2.h>
void setup() {
Serial.begin(9600);
while (!Serial);
@maxpromer
maxpromer / BL0940-ESP32.ino
Created July 5, 2025 17:07
Example code for AS-Energy
#include "MCM_BL0940.h"
BL0940 bl0940;
void setup() {
Serial.begin(115200);
bl0940.begin(Serial1, 25, 26); // RX, TX pin
bl0940.Reset();
bl0940.setFrequency(50); // 50[Hz]
#include "driver/gpio.h"
#include "driver/twai.h"
typedef float (*DataConvertFn)(uint32_t);
typedef struct {
int8_t mode; // Mode/UDS
uint16_t pid;
const char * name;
uint8_t size; // in byte
#include "driver/gpio.h"
#include "driver/twai.h"
void setup() {
Serial.begin(115200);
twai_general_config_t g_config = { // สร้างต้วแปร g_config ใช้กำหนดค่าเกี่ยวกับบัส CAN
.mode = TWAI_MODE_NORMAL,
.tx_io = GPIO_NUM_26, // กำหนดขา TX ต่อกับ 26
.rx_io = GPIO_NUM_27, // กำหนดขา TX ต่อกับ 27
const uint8_t io[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 18, 19, 20, 21, 22, 23 };
void setup() {
for (int i=0;i<sizeof(io);i++) {
pinMode(io[i], OUTPUT);
}
}
void loop() {
for (int i=0;i<sizeof(io);i++) {
void setup() {
pinMode(3, OUTPUT); // กำหนดขาเชื่อมต่อรีเลย์ (GPIO3) เป็นดิจิทัลเอาต์พุต
}
void loop() {
digitalWrite(3, HIGH); // สั่งรีเลย์ทำงาน
delay(1000); // หน่วงเวลา 1 วินาที (1000 mS)
digitalWrite(3, LOW); // สั่งรีเลย์หยุดทำงาน
delay(1000); // หน่วงเวลา 1 วินาที (1000 mS)
}
//Parameters
const int gp2y0a21Pin = A0;
//Variables
int gp2y0a21Val = 0;
void setup() {
//Init Serial USB
Serial.begin(9600);
Serial.println(F("Initialize System"));
Alert.begin(<Room token>); // เริ่มต้นใช้ Am Alert กำหนด ROOM token
#include <WiFi.h> // นำเข้าไลบรารี่ WiFi
const char* ssid = "your-ssid"; // ชื่อ WiFi
const char* password = "your-password"; // รหัสผ่าน WiFi
void setup() {
Serial.begin(115200); // เริ่มต้นใช้ Serial ที่ความเร็ว 115200
while(!Serial){delay(100);}
// We start by connecting to a WiFi network