Grüße euch,
ich habe einen Sketch wo ich die mittels RTC (DS3231 I2C) ermittelte Zeit in einer Matrix anzeigen lassen will. Beides einzeln für sich funktioniert. Sobald ich aber beides zusammen in einen Sketch werfe, kann ich die Matrix nicht mehr ansprechen. Verursachen ist im setup der Befehl RTC.begin();
Wird dieser auskommentiert, funktioniert die Matrix wieder. Hat da jemand kurzerhand schon direkt eine Ahnung woran das liegen könnte?
Benutze einen Arduino Nano, eine WS2812ECO 8×32 Matrix mit NeoMatrix/NeoPixel Libary und habe schon 2 RTC Libs ausprobiert. (RTClib und I2C_RTC).
Vielen Dank schonmal!
Beste Grüße Tom
Edit: Jetzt funktioniert es mit RTC.begin(); solange ich die Funktion sprintf( time, "%02hhu:%02hhu", RTC.getHours(), RTC.getMinutes() ); auskommentiert habe. Will ich diese nutzen klappt es nicht mehr..
/*
################## RAWDATA OF REMOTE ############################
1 = 0xBA45FF00 69
2 = 0xB946FF00 70
3 = 0xB847FF00 71
4 = 0xBB44FF00 68
5 = 0xBF40FF00 64
6 = 0xBC43FF00 67
7 = 0xF807FF00 7
8 = 0xEA15FF00 21
9 = 0xF609FF00 9
0 = 0xE619FF00 25
* = 0xE916FF00 22
# = 0xF20DFF00 13
OK = 0xE31CFF00 28
hoch = 0xE718FF00 24
runter = 0xAD52FF00 82
links = 0xF708FF00 8
rechts = 0xA55AFF00 90
#################################################################
*/
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <IRremote.hpp>
#include "PinDefinitionsAndMore.h"
#include <Wire.h>
//#include "RTClib.h"
#include <I2C_RTC.h>
//RTC_DS1307 RTC;
static DS3231 RTC;
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#define PIN 6 // LED Pin
int relais = 7; //Relais
int state=0;
decode_results results;
int mode = 0;
#define DEBUG_BUTTON_PIN 9
#define APPLICATION_PIN 2
// MATRIX DECLARATION:
// Parameter 1 = width of the matrix
// Parameter 2 = height of the matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the matrix; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
// rows or in vertical columns, respectively; pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
// in the same order, or alternate lines reverse direction; pick one.
// See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_GRBW Pixels are wired for GRBW bitstream (RGB+W NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
void setup() {
Serial.begin(115200);
RTC.begin();
RTC.setHourMode(CLOCK_H24);
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(100);
theaterChase(colors[0], 25);
matrix.setTextColor(colors[0]);
//########### IR Receiver ###############
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP);
#endif
Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
#endif
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println(F("Enabling IRin..."));
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
Serial.print(F("Ready to receive IR signals of protocols: "));
printActiveIRProtocols(&Serial);
#if defined(IR_RECEIVE_PIN_STRING)
Serial.println(F("at pin " IR_RECEIVE_PIN_STRING));
#else
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
#endif
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
Serial.println();
if (digitalRead(DEBUG_BUTTON_PIN) != LOW) {
Serial.print(F("If you connect debug pin "));
# if defined(APPLICATION_PIN_STRING)
Serial.print(APPLICATION_PIN_STRING);
# else
Serial.print(DEBUG_BUTTON_PIN);
# endif
Serial.print(F(" to ground, "));
}
Serial.println(F("raw data is always printed"));
// infos for receive
Serial.print(RECORD_GAP_MICROS);
Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed"));
Serial.print(MARK_EXCESS_MICROS);
Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding"));
#endif
//##########################
pinMode(relais, OUTPUT);
matrix.clear();
matrix.show();
digitalWrite(relais, LOW);
//Wire.begin();
delay(500);
/*RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}*/
Serial.println();
Serial.print(RTC.getDay());
Serial.print("-");
Serial.print(RTC.getMonth());
Serial.print("-");
Serial.print(RTC.getYear());
Serial.print(" ");
Serial.print(RTC.getHours());
Serial.print(":");
Serial.print(RTC.getMinutes());
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.print(" ");
}
unsigned long last = millis();
int x = 0;
void loop() {
if (IrReceiver.decode()) {
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 1000) {
switch(IrReceiver.decodedIRData.command){
case 22:
if(mode!=22){
Serial.println(F("Blaulicht-Relais an"));
digitalWrite(relais, HIGH);
matrix.clear();
mode=22;
}
break;
case 13:
if(mode!=13){
Serial.println(F("Alles aus"));
digitalWrite(relais, LOW);
matrix.clear();
matrix.show();
mode=13;
}
break;
case 71:
if(mode!=71){
Serial.println(F("Uhrzeit/Datum anzeigen"));
x=1;
//DateTime now = rtc.now();
//digitalWrite(RELAIS, LOW);
//DateTime now = RTC.now();
//char time[6];
// sprintf( time, "%02hhu:%02hhu", RTC.getHours(), RTC.getMinutes() );
//Serial.println(time);
matrix.clear();
matrix.setCursor(x, 0);
matrix.print(F("18:00"));
//matrix.print(time);
matrix.show();
mode=71;
}
break;
case 69:
if(mode!=69){
Serial.println(F("Text1"));
mode=69;
}
break;
case 70:
if(mode!=70){
Serial.println(F("Text2"));
mode=70;
}
break;
}
last = millis();
IrReceiver.resume();
}
}
}
void theaterChase(uint32_t color, int wait) {
for(int a=0; a<10; a++) { // Repeat 10 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
matrix.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for(int c=b; c<matrix.numPixels(); c += 3) {
matrix.setPixelColor(c, colors[0]); // Set pixel 'c' to value 'color'
}
matrix.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}