Affichage des articles dont le libellé est realtime. Afficher tous les articles
Affichage des articles dont le libellé est realtime. Afficher tous les articles

mardi 16 juillet 2019

Arduino Episode 19 : Projet Reveil (tout va bien)

Arduino Episode 19 : Projet Reveil (tout va bien)

J'ajoute juste mon code où le superflu est supprimé, et les effets me conviennent.
Prochaine étape : Le tilt

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <stdint.h>

RTC_DS3231 rtc;
char str [20];
char joursemaine[12];
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
char jourmois[12];
char anneefull[4];
char horaire[12];

#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
int j = 0;

void setup () {
P.begin();
P.setIntensity(0);
Serial.begin(9600);
delay(3000); // wait for console opening

if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}

if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
rtc.adjust(DateTime(2019, 7, 15, 10, 01, 0));
}
}

void loop () {
DateTime now = rtc.now();

int anneefull = now.year();
int annee= (now.year()-2000);
int mois = now.month();
int jour = now.day();
int heure = now.hour();
int minutes = now.minute();

if (P.displayAnimate())
{
sprintf(joursemaine,daysOfTheWeek[now.dayOfTheWeek()]);
sprintf(jourmois,"%02d/%02d",jour,mois);
sprintf(anneefull,"%02d",anneefull);
sprintf(horaire,"%02d:%02d",heure,minutes);

switch (j) {
case 0:
P.displayText(joursemaine, PA_CENTER, 25 , 2000, PA_DISSOLVE, PA_DISSOLVE);
break;
case 1:
P.displayText(jourmois, PA_CENTER, 25 , 2000, PA_DISSOLVE, PA_DISSOLVE);
break;
case 2:
P.displayText(anneefull, PA_CENTER, 25 , 2000, PA_DISSOLVE, PA_DISSOLVE);
break;
case 3:
P.displayText(horaire, PA_CENTER, 25 , 30000, PA_DISSOLVE, PA_DISSOLVE);
break;
default:
break;
}
j = j + 1;
if (j > 5) j = 0;
}

Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(j);
Serial.println();
}

dimanche 7 avril 2019

Arduino Episode 18 : Projet Reveil

Voici un projet qui s'impose à moi,
après un achat sur le bon coin, je me retrouve avec quelques éléments qui ne m'interesse pas vraiment.
-arduino
-matrice 7219
-une horloge temps réel ds3231m


et l'idée à germée.
 Je vais faire un reveil,  juste ajouter un buzzer un tilt et je pourrais faire une horloge qui affiche l'heure, sonne, et s'éteint lorsqu'on lui met la tête en bas.
on pourra toujours changer l'arduino nano par un esp8266 pour le mettre sur Internet.

Voici rapidement les branchements
Max7219 - Nano
VCC - 5V
GND - GND
DIN - PIN 11
CS -  PIN 10
CLK - PIN 13

DS3231M - Nano
VCC - 3V
GND - GND
SCL - SCL or A5
SDA - SDA or A4


Pour la librairie du DS3231M, j'opte pour RTCLib, plus rapide que DS3231M  ou DS3231 ou DS3231F
Il configure l'heure tout seul, l'affiche, et fait meme un test de prévision (ici ca ne marche pas)

2019/4/8 (Monday) 18:10:47
 since midnight 1/1/1970 = 1554714647s = 17994d
 now + 7d + 30s: 2019/4/16 06:40:53

Voici la partie code pour le RTC :
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include
#include "RTClib.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(9600);

  delay(3000); // wait for console opening

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop () {
    DateTime now = rtc.now();

    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");

    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.year(), DEC);
    Serial.print(' ');
   
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
   
    Serial.print(" Depuis le 1/1/1970 minuit = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
   
    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));
   
    Serial.print(" Maintenant + 7d + 12h + 30minutes +6s: ");
    Serial.print(future.day(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.year(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
   
    Serial.println();
    delay(5000);
}

vendredi 22 février 2019

Arduino Episode 14 : Tiny RTC Module (Real Time Clock) Horloge temps réel

Arduino Episode 14 : Tiny RTC Module (Real Time Clock) Horloge temps réel

1er problème, je n'ai pas de broche et de kit de soudure pour tester le matériel.
J'utilise alors des câbles durant glissé dans les trous sans être retenu, et calé sur le bureau sans le bouger, le résultat fonctionne directement.
Attention aux achats car je vais devoir souder ceci pour que ce soit pérènne.

Branchements :

On pourra déjà remarquer que nous avons 2 serie de brochage
A gauche, DS, SCL, SDA, VCC, GND
A droite , SQ,DS, SCL, SDA, VCC, GND, BAT

A gauche pour être branché directement à un arduino
A droite pour être branché en plus qu'a gauche en arduino, sur un autre périphérique IC2 (ici pas utile)


NANO <-> Tiny RTC
GND --- GND
5V --- VCC
A4 --- SDA
A5 --- SCL

Code: 
Croquis, Inclure une Bibliothèque, Gerer les bibliothèques, "RTClib" by Adafruit
https://github.com/adafruit/RTClib
Fichier; exemple, RTClib, DS1307

Résultat:
Dans la console COM à 57600bauds :
2019/2/22 (Friday) 16:2:5
 since midnight 1/1/1970 = 1550851325s = 17949d
 now + 7d + 30s: 2019/3/2 4:32:11



Sources:
https://www.elecrow.com/wiki/index.php?title=Tiny_RTC
https://www.hobbyist.co.nz/?q=real_time_clock 
https://www.youtube.com/watch?v=OmVoR3mTP00