Skip to content

Instantly share code, notes, and snippets.

View CytronTH's full-sized avatar

Cytron Thailand CytronTH

  • Cytron Thailand
View GitHub Profile
@CytronTH
CytronTH / iriv_ioc_modbus_tcp.py
Created October 21, 2025 09:45
Reading digital input status from IRIV IOC using python via modbus TCP
#!/usr/bin/env python3
"""
Modbus TCP Digital Input Reader for Raspberry Pi
Reads 11 digital inputs (DI0-DI10) from remote I/O
Outputs data in JSON format
"""
from pymodbus.client import ModbusTcpClient
from pymodbus.exceptions import ModbusException
import time
@CytronTH
CytronTH / read_dht.py
Created October 2, 2025 04:12
Reading data from DHT22 sensor connect with Pi 5 on GPIO4 using node-red to run this script via exec node
import adafruit_dht
import board
import sys
# Set the BCM GPIO pin number (4)
DHT_PIN = 4
# The library maps BCM to a board pin. GPIO 4 is board.D4.
dht_device = adafruit_dht.DHT22(board.D4, use_pulseio=False)
@CytronTH
CytronTH / frigate.yaml
Created May 7, 2025 07:49
Basic frigate.yaml for using Hailo-8l with Home Assistant OS
mqtt:
enabled: False
cameras:
your_camera_name: # <------ Name the camera
enabled: True
ffmpeg:
#input_args: preset-rtsp-udp #<---- remove # if your CCTV stream on UDP
inputs:
- path: rtsp://<username>:<password>@<CCTV IP> # <----- The stream you want to use for detection
@CytronTH
CytronTH / PM25.ino
Created January 27, 2025 05:21
PM2.5 sensor with Blynk (HPMA115S0 + NodeMCU ESP32 + eTFT LCD)
// Buffer size and constants
#define BUFFER_SIZE 32
#define DELAY 5000
#define TFT_GREY 0x7BEF
#define TFT_W 160
#define TFT_H 128
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
@CytronTH
CytronTH / check.sh
Created January 23, 2025 10:16
Check file for EDATEC AI camera
#!/bin/bash
F_LOG=$(dirname $(realpath $0))/info.log
echo_info(){
local msg=$*
echo >> ${F_LOG}
echo >> ${F_LOG}
echo "------------[ ${msg} ]---------------" >> ${F_LOG}
}
@CytronTH
CytronTH / pm_meter_rev2.ino
Created December 23, 2024 13:33
HPMA115S0 with TFT
#include <TFT_eSPI.h> // Include the TFT library
// Initialize TFT display
TFT_eSPI myGLCD = TFT_eSPI();
// Buffer size and constants
#define BUFFER_SIZE 32
#define DELAY 5000
#define TFT_GREY 0x7BEF
#define TFT_W 160
@CytronTH
CytronTH / cellularcheck.py
Created November 30, 2024 07:16
Restart board if lost cellular connection
import os
import time
import subprocess
def check_internet_via_usb0():
try:
# Use the ping command with usb0 interface
result = subprocess.run(
["ping", "-I", "usb0", "-c", "3", "8.8.8.8"],
stdout=subprocess.PIPE,
@CytronTH
CytronTH / pwm_fan_config
Created September 8, 2024 14:31
Configuration for who want to make Raspberry Pi as cool as possible (Pi 5 only)
#PWM Fan control
#fan_tempX is temperature range in millicelcius
#fan_temp0_hyst is temperature range ensures that the fan doesn't turn on and off too frequently.
#fan_temp0_speed is speed of fan (min 0, max 255)
#Config below set PWM fan work:
# Fan speed 25% at 35 Celcius
# Fan speed 50% at 40 Celcius
# Fan speed 75% at 45 Celcius
# Fan speed 100% at 50 Celcius
@CytronTH
CytronTH / pzemjetson.py
Created August 27, 2024 09:12
Read data from PZEM-004t via USB using Jetson Nano
import serial
import struct
import time
# Initialize the serial connection to the PZEM-004T
# Replace '/dev/ttyUSB0' with the appropriate port on your Jetson Nano
serial_port = '/dev/ttyUSB0'
baud_rate = 9600
def read_pzem(serial_connection):
@CytronTH
CytronTH / crosshair.py
Created July 5, 2024 10:40
Raspberry Pi 5 access camera module 3 and draw crosshair in the middle
import cv2
from picamera2 import Picamera2
# Initialize the camera
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
picam2.start()
cv2.startWindowThread()