Et bien voilà. j'ai un petit problème de conception avec Arduino. Je continue mon projet de domotique, et maintenant je dois passer à la partie software. Tout va bien de ce côté, si ce n'est lors de l'execution du fichier.
En effet, j'ai pas mal de lignes de code,pour avoir quelque chose de complet, mais j'ai remarqué que lorsque je dépassait les 10'000 bytes sur les 32'000 disponibles, ça ne fonctionne plus. En effet, l'écran de mon LCD affiche des caractères bizarres. Ce qui n'arrive pas quand je ne vais pas plus loin que la limite de 10'000.
J'utilise les libraries des LCD(LiquidCrystal) et celle du temps(Time). Je précise que j'ai une Arduino Uno. Qu'en pensez-vous ? Y-at'il une erreur quelque part, ou bien la limite est véritablement de 10'000 ?
Ce n'est probablement pas a cause de la taille mais plutot a ce qu'il y a d'écris dans ce code...
Les librairies tiers utilisent de temps en temps les memes interruptions ou des choses du genre donc tu as peut etre des conflits qui apparaissent dans ton code sans que tu le voie directement
Mmmmmh ça me semble peu probable, parce que j'avais réussi à faire un réveil, en utilisant les mêmes libraries. Ce qui est bizarre, c'est que quand je le lance, il n'arrive même pas jusqu'à la fin de setup(), qu'il fait un reset()...
Je trouve çaassez étrange, si tu veux je peux poster le code, mais il y a genre 300 lignes.
Désolé de pas avoir répondu plus tôt, mais j'étais principalement dans le train.
Alors pour newSoftSerial, non, tout du moins je crois pas. Par contre, si je fais une sorte de boucle inifinie, qui ne se finit que quand un signal connu est détecté, ça pourrait pas interférer avec la library Time ? Du coup ça pourrait être mon problème...
Sinon, je fais vite une petite explication de comment marche le code avant de le poster:
Tout d'abord, grâce à deux boutons physique, on peut choisir l'heure et la date actuelle. Ensuite, il affiche ces données sur le LCD et les gère grâce à library Time. En parallèle, il prend la température et l'affiche sur une autre ligne du LCD. Pour finir, il "écoute" si il y a des variations sur le capteurs infrarouge et si elles ces variations sont celles pré-enregistrées, il effectue l'action associée. Il faut savoir que du fait que j'ai une boucle infinie, je n'actualiserai mes données sur le LCD que lorsque un certain signal est envoyé.
En tout cas c'est ce que ça devrait faire. Et normalement toute la partie électronique marche. parce que séparément les différents morceaux de codes fonctionnent bien.
Voilà le code:
/*
With the good configuration, this program transforms the Arduino into a
Home-Automation IR-controled tool.
To change the remote, you have to capture the new signals from the new
remote with IRdecoder. And the replace the values of the variables right after this comment
*/
int oneButton[] = {
// The 1 button on the telecommand
892, 430,
64, 44,
66, 44,
64, 46,
64, 44,
66, 44,
64, 46,
64, 46,
64, 44,
66, 154,
64, 156,
64, 154,
66, 154,
64, 156,
64, 156,
64, 44,
64, 156,
64, 46,
64, 44,
66, 44,
64, 46,
64, 156,
64, 44,
64, 46,
64, 46,
64, 154,
66, 154,
64, 156,
64, 156,
64, 44,
64, 156,
64, 154,
66, 154,
64, 4042,
890, 212,
64, 0};
int twoButton[] = {
// The 2 button on the telecommand
888, 434,
60, 50,
60, 50,
60, 48,
62, 48,
62, 48,
60, 50,
60, 50,
60, 48,
62, 158,
60, 160,
60, 160,
60, 158,
62, 158,
60, 160,
60, 50,
60, 158,
62, 158,
62, 48,
62, 48,
60, 50,
60, 160,
60, 48,
60, 50,
60, 50,
60, 48,
62, 158,
62, 158,
60, 160,
60, 50,
60, 160,
60, 158,
60, 160,
60, 4048,
890, 214,
60, 0};
int threeButton[] = {
// the 3 button on the telecommand
890, 432,
62, 48,
60, 50,
60, 50,
60, 48,
62, 48,
62, 48,
60, 50,
60, 48,
62, 158,
62, 158,
60, 160,
60, 158,
62, 158,
62, 158,
60, 50,
60, 160,
60, 50,
60, 158,
62, 48,
62, 48,
60, 160,
60, 48,
62, 48,
60, 50,
60, 160,
60, 48,
62, 158,
62, 158,
60, 50,
60, 160,
60, 158,
62, 158,
62, 0};
int fourButton[] = {
// the 4 button on the telecommand
890, 434,
60, 48,
62, 48,
62, 48,
62, 48,
60, 48,
62, 48,
62, 48,
60, 50,
60, 160,
60, 158,
62, 158,
62, 158,
60, 160,
60, 160,
60, 48,
62, 158,
62, 48,
60, 48,
62, 158,
62, 48,
62, 158,
60, 50,
60, 50,
60, 48,
62, 158,
62, 158,
60, 50,
60, 158,
62, 48,
62, 158,
60, 160,
60, 158,
62, 4046,
890, 214,
62, 0};
int fiveButton[] = {
// the 5 button on the telecommand
888, 434,
62, 48,
60, 50,
60, 50,
60, 50,
60, 48,
60, 50,
60, 50,
60, 48,
62, 158,
62, 158,
60, 160,
60, 160,
60, 158,
62, 158,
62, 48,
60, 160,
60, 160,
60, 50,
60, 158,
60, 50,
60, 160,
60, 48,
62, 48,
60, 50,
60, 50,
60, 160,
60, 48,
62, 158,
60, 50,
60, 160,
60, 158,
62, 158,
60, 4048,
890, 214,
60, 0};
int sixButton[] = {
// the 6 button on the telecommand
892, 432,
64, 46,
62, 46,
64, 46,
64, 46,
64, 46,
64, 46,
62, 46,
64, 46,
64, 156,
64, 156,
62, 156,
64, 156,
64, 156,
64, 156,
64, 44,
66, 154,
64, 46,
64, 156,
64, 156,
64, 46,
62, 156,
64, 46,
64, 46,
64, 46,
62, 156,
64, 46,
64, 46,
64, 154,
66, 44,
64, 156,
64, 156,
64, 156,
64, 4044,
892, 212,
62, 0};
int eightButton[] = {
// the 8 button on the telecommand
892, 430,
66, 44,
62, 48,
66, 44,
64, 46,
64, 46,
64, 44,
64, 46,
64, 46,
64, 156,
64, 156,
64, 154,
66, 154,
64, 156,
64, 156,
64, 44,
66, 154,
66, 154,
64, 46,
64, 46,
64, 156,
64, 156,
64, 44,
66, 44,
64, 46,
64, 46,
64, 154,
66, 154,
66, 44,
64, 46,
64, 156,
64, 154,
66, 154,
64, 4046,
882, 222,
64, 0};
/*Here are the included libraries*/
#include <LiquidCrystal.h>
#include <Time.h>
/*Here are the main things to get the telecomand working*/
#define IRpin_PIN PIND
#define IRpin 6 //Pin where the IR receiver is connected
#define MAXPULSE 65000 //The maximum pulse we will listen for.
#define RESOLUTION 20 //This is the timing resolution.
#define FUZZINESS 50 //The marge error we will admit in our program
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing
/* These are the main variable */
int thermoPin = 0;//The thermometer pin number(Analog)
int alarmButton = 3;//The redifine-the-alarm/set button pin(Digital)
int lightPin = 5;//The pin to control the light
int valueButton = 4;//The change-this-value button pin(Digital)
int buzzer = 2;//The value of the buzzer pin(Digital)
int tempc = 0;//The initial value for the temperatur in Celsius
int thermoSamples[8];//The array for the multi-temperature values
int clockHour = 0;//The hour value for the clock
int clockMinute = 0;//The clock value for the minute
int alarmHour = -1;//The hour value for the alarm
int alarmMinute = -1;//The minute value for the alarm
int timeYear = 2011;//The value for the actual year
int timeMonth = 0;//The value for the actual month
int timeDay = 0; //The value for today
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);//Declaration of the LCD pins
void setup(){
lcd.begin(16, 2);
lcd.setCursor(0, 0);
pinMode(buzzer, OUTPUT);
pinMode(alarmButton, INPUT);
pinMode(valueButton, INPUT);
setTime(clockHour, clockMinute, 0, timeDay, timeMonth, timeYear);
lcd.clear();
/*The following is only for testing !*/
Serial.begin(9600);
Serial.println("Ready to decode IR!");
}
void loop(){
lcd.clear();
printTime();
printTemperature();
checkForAlarm();
beRemoted();
}
//This function will ask the user to set the time of the clock
void askForTime(){
while(digitalRead(alarmButton) == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set time: Minutes");
lcd.setCursor(0, 1);
lcd.print(clockMinute);
clockMinute = getValueModulo(60, clockMinute);
delay(100);
}
delay(250);
while(digitalRead(alarmButton) == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set time: Hour");
lcd.setCursor(0, 1);
lcd.print(clockHour);
clockHour = getValueModulo(24, clockHour);
delay(100);
}
delay(250);
}
void askForDate(){
while(digitalRead(alarmButton) == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set date: day");
lcd.setCursor(0, 1);
lcd.print(timeDay);
timeDay = getValueModulo(32, timeDay);
delay(75);
}
delay(250);
while(digitalRead(alarmButton) == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set date: month");
lcd.setCursor(0, 1);
lcd.print(timeMonth);
timeMonth = getValueModulo(13, timeMonth);
delay(75);
}
delay(250);
while(digitalRead(alarmButton) == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set date: year");
lcd.setCursor(0, 1);
lcd.print(timeYear);
timeYear = getValueModulo(2020, timeYear);
;
delay(75);
}
delay(250);
}
int getValueModulo(int maxValue, int changeValue){
if(digitalRead(valueButton) == HIGH){
return (changeValue+1)%maxValue;
}
return changeValue;
}
void printTime(){
lcd.setCursor(0, 1);
lcd.print(hour());
lcd.print(":");
lcd.print(minute());
lcd.print(", ");
lcd.print(day());
lcd.print("/");
lcd.print(month());
lcd.print("/");
lcd.print(year());
}
void printTemperature(){
tempc = (5.0*analogRead(thermoPin)*100.0)/1024.0;
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(tempc);
lcd.print(" Celsius");
}
void setAlarm(){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set the alarm");
delay(1000);
while(digitalRead(alarmButton) == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set alarm: (Min)");
lcd.setCursor(0, 1);
lcd.print(alarmMinute);
alarmMinute = getValueModulo(60, alarmMinute);
delay(75);
}
delay(250);
while(digitalRead(alarmButton) == LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set alarm:(Hour)");
lcd.setCursor(0, 1);
lcd.print(alarmHour);
alarmHour = getValueModulo(24, alarmHour);
delay(75);
}
delay(250);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Alarm set !");
}
void checkForAlarm(){
while(hour()==alarmHour && minute()==alarmMinute){
buzz();
if(digitalRead(alarmButton)==HIGH || digitalRead(valueButton)==HIGH){
delay(60000);
}
}
}
void buzz(){
digitalWrite(buzzer, HIGH);
delay(330);
digitalWrite(buzzer, LOW);
delay(330);
digitalWrite(buzzer, HIGH);
delay(330);
digitalWrite(buzzer, LOW);
}
/*
This function will check if the signal received is the same as one
of the pre-registered ones and then return true. Otherwise it will
return false.
*/
boolean IRcompare(int numpulses, int Signal[]) {
for (int i=0; i< numpulses-1; i++) {
int oncode = pulses[i][1] * RESOLUTION / 10;
int offcode = pulses[i+1][0] * RESOLUTION / 10;
if ( abs(oncode - Signal[i*2 + 0]) <= (Signal[i*2 + 0] * FUZZINESS / 100)) {
}
else {
return false;
}
if ( abs(offcode - Signal[i*2 + 1]) <= (Signal[i*2 + 1] * FUZZINESS / 100)) {
}
else {
return false;
}
}
return true;
}
/*
This function will listen to for a signal and check if something is received.
It will run until it receives a command from the remote. If it does, it returns the signal received.
*/
int listenForIR(void) {
currentpulse = 0;
while (1) {
uint16_t highpulse, lowpulse;
highpulse = lowpulse = 0;
while (IRpin_PIN & (1 << IRpin)) {
highpulse++;
delayMicroseconds(RESOLUTION);
if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
return currentpulse;
}
}
pulses[currentpulse][0] = highpulse;
while (! (IRpin_PIN & _BV(IRpin))) {
lowpulse++;
delayMicroseconds(RESOLUTION);
if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
return currentpulse;
}
}
pulses[currentpulse][1] = lowpulse;
currentpulse++;
}
}
/*
This function wait for a signal form the remote, and then analyse it. If it is one of
the pre-registered command, it will execute the tsk assigned.
*/
void beRemoted(){
int numberpulses;
numberpulses = listenForIR();
Serial.print("Heard ");
Serial.print(numberpulses);
Serial.println("-pulse long IR signal");
if(numberpulses > 3){
if (IRcompare(numberpulses, oneButton)) {
Serial.println("Switch Ext1");
}
if (IRcompare(numberpulses, twoButton)) {
Serial.println("Refresh");
// printTemperature();
// printTime();
}
if (IRcompare(numberpulses, threeButton)) {
Serial.println("Switch Ext3");
}
if (IRcompare(numberpulses, fourButton)) {
Serial.println("ArLight--");
}
if (IRcompare(numberpulses, fiveButton)) {
Serial.println("Switch ArLight");
}
if (IRcompare(numberpulses, sixButton)) {
Serial.println("ArLight++");
}
if (IRcompare(numberpulses, eightButton)) {
Serial.println("AlarmSet");
//setAlarm();
}
}
}
Voilà, c'est commenté mais si vous avez des questions n'hésitez pas
Seba-1511
Alors, en fait c'est deux gros morceaux de codes qui quand je les mets ensembles me causent mon problème. Mais je crois que j'ai trouver une solution. Dîtes-moi juste si j'ai faux:
Alors vu que pour détecter un signal infrarouge je dois avoir une boucle infinie(ça c'est moi qui l'ai faite, mais comme ça quand un signal apparaît il est tout de suite capté) et que dans la library de Time il doit y avoir une boucle infinie(en quelque sorte(c'est ce dont je doute)), le problème se situe là. Alors, pour résoudre ça on m'a conseillé d'utiliser un interrupteur AVR.
Le problème c'est que je ne sais pas du tout l'utiliser, donc ça va être encore des recherches, pour finalement tomber sur la perle rare (Si vous avez un bon tuto, ce serait le top !)
Si l'un de vous pouvait confirmer cette théorie ça serait bien. En tout cas merci de m'aider !
Seba-1511
P.S: Eskimon m'avait demandé des nouvelles de mon projet, j'ai fait une petite vidéo de quelque chose de concluant: https://docs.google.com/leaf?id=0B8Bo2 [...] MTA4&hl=en_US
Il faut savoir que sur l'Arduino il y a un LCD qui me donne la température. Importantissime !
Je dirais une impulsion, puisque c'est une telecommande que l'on peut trouver dans les marches. Mais si tu veux etre tout a fait sur, regarde le debut du code que j'ai poste. Je definis quelques arrays qui prennent plus de la moitie du code. C'est caque je recois.
P.S: Pardon pour l'oorthographe, mais je suis sur un clavier americain...
Vous en pensez quoi ? Y aura-t'ildes conflits avec Time ?
Le mot de la fin c'est qu'avec cette library, ça fonctionne tip top. Alors merci beaucoup de votre, mon problème est résolu !
Dépassement de mémoire Arduino
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Retrouvez moi sur mon blog et ma chaine Youtube !
Retrouvez moi sur mon blog et ma chaine Youtube !
Retrouvez moi sur mon blog et ma chaine Youtube !
Retrouvez moi sur mon blog et ma chaine Youtube !