Giter Site home page Giter Site logo

triacd's Introduction

OpenIndoor Opto-TRIAC Raspberry Pi HAT driver

User-mode and Kernel-mode driver for Opto-TRIAC HAT

Getting Started

Board can be purchased online:

Opto-TRIAC board is not a toy for begginers. Despite all precautory measures taken into account during design stage, board works with AC mains. So, improper mounting or touching live parts of the board while it is plugged in can lead to electrocution, serious injury or death.

Prerequisites

  • It is expected that you already have some experience with Raspberry Pi.
  • Only 40-pin GPIO header supported. HAT will not work with old 26-pin header.
  • Due to multi-threaded Kernel module driver, only Quad-core ARM processors are supported, that means this driver will only work on Raspberry Pi 2 model B or better.

Installation support is based on official Raspbian Buster Lite image. It can be downloaded on the following link:

https://downloads.raspberrypi.org/raspbian_lite_latest

For instructions on how to write the image to the SD card read the following link:

https://www.raspberrypi.org/documentation/installation/installing-images/README.md

WAIT!!: Before booting the Raspi with your freshly downloaded Raspbian image, we need to do some minor changes.

Mount the SD card on your PC/Laptop computer and create an empty file named ssh inside boot partition of SD card. If that file is not present, SSH won't be enabled on boot time, so we will have no access to our headless Raspi.

Ensure your Raspi has a working Internet connection. I prefer cabled one so don't have to mess with WiFi passwords.

Boot your Raspi and wait till it finishes doing all stuff (rezising partition, etc).

You will need to know your Raspberry Pi IP address. Either assign a static IP based on Raspi MAC address or check your router's DHCP pool to see what IP got assigned.

Login (SSH) to your Raspi and perform packages update and upgrades (Reboot after upgrade):

sudo apt update && sudo apt upgrade

NOTE: Do not perform rpi-update. There is no need to do that, and it can f*ck up Kernel

Installing

Hardware

Power off Raspi. Mount Opto-TRIAC HAT on top of Raspberry Pi. Use supplied 40-pin header extender, 20mm nylon hex-spacers, nylon nuts and nylon bolts. DO NOT USE metallic spacers, or shorter ones. You can also mount HAT next to Raspberry Pi, connecting them with a 40-pin ribbon cable.

Power on Raspberry Pi. Login again and check if HAT was properly autodetected:

cat /proc/device-tree/triacboard/product

Output should read:

Quad Opto-TRIAC board

If triacboard/product does not exist, it means HAT was not detected during boot-up. Things to check in that case:

  1. Are JSDA1 and JSCL1 on place?

  2. If still not working, check this link: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=108134

  3. Check that no other peripherals are messing with I²C-0 bus

  4. Check for proper HAT header contact

  5. Check if EEPROM is properly soldered to HAT PCB

Software

You will need to compile from sources, sorry for that. But it's quite easy.

Install Kernel headers and build tools:

sudo apt install raspberrypi-kernel-headers build-essential git

Now clone Git repository:

git clone https://github.com/vpreatoni/triacd.git

cd triacd/

Start building the easy part: the user-mode triacd daemon (Install script will also create a systemd entry, so everytime your Raspi starts up, daemon will be automatically loaded):

make

sudo make install

Now the hard thing, kernel modules (do not proceed to sudo make install if make was not successfull. Module compilation must be a clean and straight forward process, otherwise you can f*ck up things):

cd modules

make

sudo make install

Running the tests

Plug in your HAT to AC mains. Reboot Raspi with sudo reboot command. After boot up, login (SSH) again and run:

dmesg

Last lines should read something like:

[   12.232407] AC LINE: optocoupler hysteresis = 289us
[   12.232457] AC LINE: ready
[   19.009843] TRIAC1: GPIO 06 - /sys/triacd/TRIAC1
[   19.010330] TRIAC1: ready
[   19.839931] TRIAC2: GPIO 13 - /sys/triacd/TRIAC2
[   19.840728] TRIAC2: ready
[   19.876487] TRIAC3: GPIO 19 - /sys/triacd/TRIAC3
[   19.880765] TRIAC3: ready
[   19.912769] TRIAC4: GPIO 26 - /sys/triacd/TRIAC4
[   19.913193] TRIAC4: ready

That means your HAT was successfully detected on boot-up!

  • AC LINE phase feedback input was detected and optocoupler successfully calibrated
  • TRIAC1 to 4 outputs were detected, and they are user-accesible on /sys/triac/TRIAC1-4 sysfs node

Using triacd daemon

triacd daemon should automatically start every time Raspi boots-up.

To test if daemon is running:

service triacd status

Output:

● triacd.service - Opto-TRIAC board daemon
Loaded: loaded (/etc/systemd/system/triacd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-09-28 00:04:46 -03; 20min ago
Main PID: 279 (triacd)
Tasks: 1 (limit: 2200)
Memory: 948.0K
CGroup: /system.slice/triacd.service
└─279 /usr/local/bin/triacd

Sep 28 00:04:46 raspberrypi systemd[1]: Started Opto-TRIAC board daemon.

To stop daemon:

service triacd stop

To start it again:

service triacd start

Sending commands to daemon

triacd daemon can be used in stand-alone mode to send commands thru a message queue to running daemon. Stand-alone executable do not need root privileges to send commands, so any high level API can call triacd with apropiate parameters to control TRIAC channels.

For usage info, run triacd -?

Examples:

triacd -c4 -f -t5000 -p110			to start fading channel 4 for 5sec up to 110deg
triacd -c1 -p110 -n30				to set channel 1 to 110deg positive / 30deg negative
triacd -c2							to turn off channel 2
triacd -c3 -t3000					to turn off channel 3 after 3sec			**TODO, still not working
triacd -c1 -t20000 -p180			to fully turn on channel 1 after 20sec		**TODO, still not working

Contributing and bug reporting

Please contact me at "my GitHub user" at gmail dot com

Authors

License

This project is licensed under the GPL License

triacd's People

Contributors

vpreatoni avatar

Stargazers

 avatar

Watchers

 avatar

triacd's Issues

No funciona en Raspberry Pi OS 2023

Al parecer no es compatible con esta versión:

Release date: October 10th 2023
System: 64-bit
Kernel version: 6.1
Debian version: 12 (bookworm)

el error se da al instalar modules

admin@raspberrypi:~/Documents/triacd/modules $ make
make -C "/lib/modules/6.1.0-rpi4-rpi-v8/build" M=/home/admin/Documents/triacd/modules modules
make[1]: Entering directory '/usr/src/linux-headers-6.1.0-rpi4-rpi-v8'
CC [M] /home/admin/Documents/triacd/modules/aclinedrv.o
In file included from /home/admin/Documents/triacd/modules/aclinedrv.c:19:
/home/admin/Documents/triacd/modules/aclinedrv.h:94:12: error: static declaration of ‘int_pow’ follows non-static declaration
94 | static u64 int_pow(u64 base, unsigned int exp);
| ^~~~~~~
In file included from /usr/src/linux-headers-6.1.0-rpi4-common-rpi/include/linux/math64.h:6,
from /usr/src/linux-headers-6.1.0-rpi4-common-rpi/include/linux/time.h:6,
from /usr/src/linux-headers-6.1.0-rpi4-common-rpi/arch/arm64/include/asm/stat.h:12,
from /usr/src/linux-headers-6.1.0-rpi4-common-rpi/include/linux/stat.h:6,
from /usr/src/linux-headers-6.1.0-rpi4-common-rpi/include/linux/module.h:13,
from /home/admin/Documents/triacd/modules/aclinedrv.h:5:
/usr/src/linux-headers-6.1.0-rpi4-common-rpi/include/linux/math.h:177:5: note: previous declaration of ‘int_pow’ with type ‘u64(u64, unsigned int)’ {aka ‘long long unsigned int(long long unsigned int, unsigned int)’}
177 | u64 int_pow(u64 base, unsigned int exp);
| ^~~~~~~
/home/admin/Documents/triacd/modules/aclinedrv.c: In function ‘acline_irq_calibrate’:
/home/admin/Documents/triacd/modules/aclinedrv.c:193:36: warning: cast between incompatible function types from ‘irqreturn_t (* (*)(unsigned int, void *, struct pt_regs ))(int, void )’ {aka ‘enum irqreturn ( ()(unsigned int, void *, struct pt_regs *))(int, void )’} to ‘irqreturn_t ()(int, void )’ {aka ‘enum irqreturn ()(int, void )’} [-Wcast-function-type]
193 | if (request_irq(irqNumber, (irq_handler_t)acline_calibration_irq_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "calibrateAC", (void )(acline_calibration_irq_handler)))
| ^
/home/admin/Documents/triacd/modules/aclinedrv.c: In function ‘acline_irq_start’:
/home/admin/Documents/triacd/modules/aclinedrv.c:271:36: warning: cast between incompatible function types from ‘irqreturn_t (
(
)(unsigned int, void *, struct pt_regs ))(int, void )’ {aka ‘enum irqreturn ( ()(unsigned int, void *, struct pt_regs *))(int, void )’} to ‘irqreturn_t ()(int, void )’ {aka ‘enum irqreturn ()(int, void *)’} [-Wcast-function-type]
271 | if (request_irq(irqNumber, (irq_handler_t)acline_gpio_irq_handler, IRQF_TRIGGER_RISING | IRQF_SHARED, "lineAC", (void *)(acline_gpio_irq_handler))) {
| ^
make[2]: *** [/usr/src/linux-headers-6.1.0-rpi4-common-rpi/scripts/Makefile.build:255: /home/admin/Documents/triacd/modules/aclinedrv.o] Error 1
make[1]: *** [/usr/src/linux-headers-6.1.0-rpi4-common-rpi/Makefile:2039: /home/admin/Documents/triacd/modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.1.0-rpi4-rpi-v8'
make: *** [Makefile:18: all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.