Giter Site home page Giter Site logo

bitwizard_spi_relay's Introduction

Modern C++ API for BitWizard SPI relay card for Raspberry Pi

Introduction

On a lengthy journey to automate the central heating of my house with https://domoticz.com/, I bought by error several SPI versions of the BitWizard relay card for the Raspberry Pi instead of the GPIO version of the card... So instead of a native support of the GPIO pins of the Raspberry Pi by https://domoticz.com/ I had to find some way to deal with the SPI version...

Unfortunately I did not find a library compatible with my modern C++ palate, so here is a small modern C++ library of my own to deal with this card. It may be useful for some other people, so here it is.

Anyway, it is not complete waste of time: I will recycle and extend this SPI library in some other projects.

This has been tested with Raspbian GNU/Linux 11 (Bullseye) with G++ 10.2 on a Raspberry Pi 3.

The library

It is a pure header library to limit usage headache, using only C++14 STL and Linux API. Fortunately, not a single malloc(), free(), new, delete or pointer is used here. Pure organic vegetarian source code.

Basically, you just have to include include/bw_spi_relay.hpp to use it and the documentation is the comments from the public methods of the raspberry_pi::bit_wizard::spi_relay4.

There is a small demo in examples/main.cpp.

The controling daemon uses also some Boost libraries and {fmt} you can get by installing the libboost-all-dev and libfmt-dev package for example.

To use SPI on the Raspberry Pi, it has to be configured to enable it, for example by running raspi-config.

To compile it and run it: :

cd examples
make
./main

and it will animate the relays for a few seconds.

The controller/daemon program for the relays

In the examples, there is also a program to control the relays independently, in a persistent way.

So you can use this program in a Domoticz script for example.

To use it you have first to launch the controlling process attached to the relays with: :

./bw_spi_relay_control --daemon

Then to control a relay, use for example: :

./bw_spi_relay_control --reset
./bw_spi_relay_control --relay 3 --on
./bw_spi_relay_control --relay 1 --off
./bw_spi_relay_control --relay 1 --state 1
./bw_spi_relay_control --relay 1 --state 0

You can stop the daemon with: :

./bw_spi_relay_control --stop

To get the list of the commands: :

./bw_spi_relay_control --help

Some useful information:

bitwizard_spi_relay's People

Contributors

keryell avatar

Watchers

 avatar  avatar

bitwizard_spi_relay's Issues

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.