Bonsoir,
et bon dimanche soir.
0 - Installation de RASPBIAN STRETCH LITE :
https://www.raspberrypi.org/downloads/raspbian/
Rien de particulier à noter, c'est facile à installer par "dd" sur carte SD.
Configuration standard par "raspi-config".
(Clavier FR, Locale, SSH,...)
J'ai donc reçu mon relais 4 canaux, le KS0212 de chez Keyestudio.
La partie câblage "test" : http://brezh.free.fr/temp/ln/relaisb/
C'est assez simple à installer, si même le Wiki n'est pas très "bavard".
Il doit s'adresser aux spécialistes du genre, "domotique"...
http://wiki.keyestudio.com/index.php/KS0212_keyestudio_RPI_4-channel_Relay_Shield
1 - Copie des sources sur le Raspberry :
***@kali64f:~$ scp /home/brezh/Downloads/KS0212\ keyestudio\ RPI\
4-channel\ Relay\ Shield/SourceCode/rpi_relay_4/*
***@192.168.0.37:/rpi_shield/rpi_relay_4/
***@192.168.0.37's password:
Makefile 100% 75 95.8KB/s 00:00
relay 100% 6664 3.9MB/s 00:00
relay.c 100% 530 676.9KB/s 00:00
relay.o 100% 1456 1.8MB/s 00:00
***@raspberrypi:~ $ cd /rpi_shield/rpi_relay_4
***@raspberrypi:/rpi_shield/rpi_relay_4 $ make
make: « relay » est à jour.
***@raspberrypi:/rpi_shield/rpi_relay_4 $ ./relay
./relay: error while loading shared libraries: libwiringPi.so: cannot
open shared object file: No such file or directory
***@raspberrypi:/rpi_shield/rpi_relay_4 $ su
Mot de passe :
***@raspberrypi:/rpi_shield/rpi_relay_4# gpio -v
bash: gpio : commande introuvable
(bin OUI, bien sûr, il faut installer les librairies d'interface GPIO...
2 - Installation de GPIO :
https://www.windtopik.fr/utiliser-gpio-raspberry-pi/
***@raspberrypi:/rpi_shield/rpi_relay_4# apt-get install git-core
Les NOUVEAUX paquets suivants seront installés :
git git-core git-man liberror-perl
***@raspberrypi:/rpi_shield# git clone git://git.drogon.net/wiringPi
Clonage dans 'wiringPi'...
Résolution des deltas: 100% (805/805), fait.
***@raspberrypi:/rpi_shield# cd wiringPi
***@raspberrypi:/rpi_shield/wiringPi# git pull origin
Déjà à jour.
***@raspberrypi:/rpi_shield/wiringPi# ls
build debian devLib gpio newVersion pins
update version.h wiringPiD
COPYING.LESSER debian-template examples INSTALL People README.TXT
VERSION wiringPi
***@raspberrypi:/rpi_shield/wiringPi# ./build
wiringPi Build script
=====================
WiringPi Library
[UnInstall]
[Compile] wiringPi.c
[Compile] wiringSerial.c
[Compile] wiringShift.c
.../...
GPIO Utility
[Compile] gpio.c
[Compile] pins.c
[Compile] readall.c
[Link]
[Install]
All Done.
NOTE: To compile programs with wiringPi, you need to add:
-lwiringPi
to your compile line(s) To use the Gertboard, MaxDetect, etc.
code (the devLib), you need to also add:
-lwiringPiDev
to your compile line(s).
***@raspberrypi:/rpi_shield/wiringPi# cd ..
***@raspberrypi:/rpi_shield/rpi_relay_4# make
cc -c -o relay.o relay.c
relay.c: In function ‘main’:
relay.c:10:3: warning: implicit declaration of function ‘printf’
[-Wimplicit-function-declaration]
printf("relay testing!\n");
^~~~~~
relay.c:10:3: warning: incompatible implicit declaration of built-in
function ‘printf’
relay.c:10:3: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
gcc relay.c -o relay -lwiringPi
relay.c: In function ‘main’:
relay.c:10:3: warning: implicit declaration of function ‘printf’
[-Wimplicit-function-declaration]
printf("relay testing!\n");
^~~~~~
relay.c:10:3: warning: incompatible implicit declaration of built-in
function ‘printf’
relay.c:10:3: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
***@raspberrypi:/rpi_shield/rpi_relay_4# ls
Makefile relay relay.c relay.o wiringPi.h
***@raspberrypi:/rpi_shield/rpi_relay_4# exit
3 - Premiers tests :
***@raspberrypi:/rpi_shield/rpi_relay_4 $ ./relay
relay testing!
^C
Vidéo :
Le script en vidéo est celui par défaut :
***@raspberrypi:/rpi_shield/rpi_relay_4 $ cat relay.c
#include <wiringPi.h>
int main()
{
wiringPiSetup();
pinMode(7,OUTPUT);
pinMode(3,OUTPUT);
pinMode(22,OUTPUT);
pinMode(25,OUTPUT);
while(1)
{
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
digitalWrite(3,HIGH);
delay(500);
digitalWrite(3,LOW);
digitalWrite(22,HIGH);
delay(500);
digitalWrite(22,LOW);
digitalWrite(25,HIGH);
delay(500);
digitalWrite(25,LOW);
delay(500);
}
}
Cela semble plutôt simple au niveau programmation :
pin(7) = relais 1 ;
pin(3) = relais 2 ;
pin(22) = relais 3 ;
pin(25) = relais 4 ;
LOW = fermé / basculé ;
HIGH = ouvert / basculé ;
Si vous modifiez "relay.c", ne pas oublier de faire un "make" pour
compiler :
***@raspberrypi:/rpi_shield/rpi_relay_4 $ make
cc -c -o relay.o relay.c
gcc relay.c -o relay -lwiringPi
4 - Et c'est donc maintenant que l'on commence à s'amuser...
Oui, car c'est bien de programmer l'ouverture/fermeture de 4 relais à
bascule, mais encore faut-il connaître :
1 - la position du soleil ;
2 - l'orientation du panneau ;
3 - le gain énergétique ;
Pour cela, j'ai 4 relais et 4 contacts à ouverture/fermeture.
Je ne vais donc pouvoir gérer que 4 positions du panneau solaire :
matin, midi, après-midi et soir.
Autre impératif : si le système consomme trop d'énergie à orienter le
panneau, le gain est nul, et mon projet aussi...
A+
//Brezh