Hallo
Ich habe es nun geschafft, dass alles funktioniert (LCD-Display, Entfernungsmesser, Neopixel, RTC-Modul, passiver Buzzer).
Aber hänge ich das SD-Card-Modul dazu, bekomme ich die Meldung, dass die RTC nicht gefunden wurde. Das SD-Card-Modul funktioniert. Ich komme nicht dahinter, wo oder wie sich das SD-Card-Modul und die RTC stören. Ich habe auch schon die anderen Module abgehängt und ich bin etwas ratlos.
P.S.: Bitte um Nachsicht - dies ist mein erster Platinenplan.
#include <Wire.h>
#include <VL53L1X.h>
VL53L1X sensor;
#include <LiquidCrystal.h>
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#include <RTClib.h>
DateTime now;
RTC_DS1307 rtc;
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN 6
#define NUMPIXELS 8
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
const byte speakerPin = 12;
int sens_read = 0;
int sens_read_akt = 0;
long previousMillis = 0;
long interval = 20;
void showTime(void);
void setup() {
while (!Serial) {}
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
if (!rtc.begin()) {
Serial.println("Couldn't find RTC Module");
while (1)
;
}
// Nur zum Setzen der Zeit einmal freisetzen
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
sensor.setTimeout(500);
if (!sensor.init()) {
Serial.println("Failed to detect and initialize sensor!");
while (1)
;
}
// Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
// You can change these settings to adjust the performance of the sensor, but
// the minimum timing budget is 20 ms for short distance mode and 33 ms for
// medium and long distance modes. See the VL53L1X datasheet for more
// information on range and timing limits.
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(55000);
// Start continuous readings at a rate of one measurement every 50 ms (the
// inter-measurement period). This period should be at least as long as the
// timing budget.
sensor.startContinuous(50);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pixels.begin();
}
void loop() {
// Serial.print(sensor.read());
if (sensor.timeoutOccurred()) { lcd.print("Time out"); }
sens_read_akt = sensor.read();
if ((sens_read / 100 != sens_read_akt / 100) && (sens_read_akt < 400)) {
tone(speakerPin, 2000, 80);
}
// LED-Ausgabe
pixels.clear();
pixels.setBrightness(10);
if (sens_read_akt < 100) {
pixels.setPixelColor(0, pixels.Color(255, 255, 255));
}
if (sens_read_akt < 200) {
pixels.setPixelColor(1, pixels.Color(255, 255, 255));
}
if (sens_read_akt < 300) {
pixels.setPixelColor(2, pixels.Color(255, 255, 255));
}
if (sens_read_akt < 400) {
pixels.setPixelColor(3, pixels.Color(255, 255, 255));
}
pixels.show();
// Displayausgabe
if (sens_read / 10 != sens_read_akt / 10) {
lcd.setCursor(0, 0);
lcd.print(sens_read_akt / 10 + String(" cm "));
now = rtc.now();
showTime();
showDate();
// Serial.println(sens_read_akt / 10 + String(" cm "));
}
sens_read = sens_read_akt;
}
void showTime() {
lcd.setCursor(8, 0);
lcd.print(now.hour());
lcd.print(':');
lcd.print(now.minute());
lcd.print(':');
lcd.print(now.second());
lcd.print(" ");
}
void showDate() {
lcd.setCursor(0, 1);
lcd.print(now.day());
lcd.print('.');
lcd.print(now.month());
lcd.print('.');
lcd.print(now.year());
lcd.print(" ");
}