/***************************|
|* "version": 1 *|
|* "author": Ihsan ^.^ *|
|* "editor": wokwi *|
|***************************/
// includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <Adafruit_MPU6050.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <SD.h>
// define - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#define ONE_WIRE_BUS 4
#define LED_PIN 16
#define LED_COUNT 16
#define RED ring.Color(255,0,0)
#define GREEN ring.Color(0,255,0)
#define BLUE ring.Color(0,0,255)
#define SD_CS 5
Adafruit_BMP085 bmp;
Adafruit_MPU6050 mpu;
sensors_event_t a, g, temp;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature ds18b20(&oneWire);
Adafruit_NeoPixel ring(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Funktionen - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BMP180();
void DS18B20();
void MPU6050();
void LED_Ring();
void LED_Running();
void LED_Ring_Color();
void LED_off();
void MicroSD();
void setup() { // Setup Base - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Serial.begin(115200);
// bmp connection
if (!bmp.begin()) {
Serial.println("BMP180 nicht gefunden!");
while(1);
}
else
Serial.println("BMP180 gefunden.");
// mpu connection
if (!mpu.begin()) {
Serial.println("MPU6050 nicht gefunden!");
while(1);
}
else
Serial.println("MPU6050 gefunden.");
// DS18B20 connection
ds18b20.begin();
Serial.println("DS18B20 gefunden.");
// LED connection
ring.begin();
ring.show(); // Alle LEDs ausschalten
ring.setBrightness(100);
// SD connection
if (!SD.begin(SD_CS)) {
Serial.println("MicroSD nicht gefunden!");
while (1);
}
else
Serial.println("MicroSD gefunden.");
}
void loop() { // Loop Base - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uint32_t index = 0;
index++;
Serial.print("iteration: ");
Serial.println(index);
BMP180();
MPU6050();
DS18B20();
LED_Ring();
//LED_Running();
MicroSD(index);
delay(10000);
}
void BMP180() { // BMP085 Modul - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Serial.println("------ Temperatur & Luftdruck ------");
Serial.print("Temperatur: ");
Serial.print(bmp.readTemperature());
Serial.println(" °C");
Serial.print("Luftdruck: ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
}
void MPU6050() { //MPU6050 Modul - - - - - - - - - - - - - - - - - - - - - - - - - - - -
mpu.getEvent(&a, &g, &temp);
Serial.println("------ Beschleunigung & Gyroskop ------");
Serial.print("Beschleunigung: X = ");
Serial.print(a.acceleration.x);
Serial.print(" m/s² | Y = ");
Serial.print(a.acceleration.y);
Serial.print(" m/s² | Z = ");
Serial.print(a.acceleration.z);
Serial.println(" m/s²");
Serial.print("Gyroskop: X = ");
Serial.print(g.gyro.x);
Serial.print(" rad/s | Y = ");
Serial.print(g.gyro.y);
Serial.print(" rad/s | Z = ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
}
void DS18B20() { // DS18B20 Modul - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ds18b20.requestTemperatures();
Serial.println("------ DS18B20 Temperatur ------");
Serial.print("Temperatur: ");
Serial.print(ds18b20.getTempCByIndex(0));
Serial.println(" °C");
}
void LED_Ring() { // LED Modul V1 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Serial.println("------ LED Version 1 ------");
Serial.println("Start");
LED_Ring_Color(RED, "Rot");
delay(5000);
LED_Ring_Color(GREEN, "Grün");
delay(5000);
LED_Ring_Color(BLUE, "Blau");
delay(5000);
LED_off();
}
void LED_Running() { // LED Modul V2 - - - - - - - - - - - - - - - - - - - - - - - - - -
Serial.println("------ LED Version 2 ------");
Serial.println("Start");
ring.clear();
for(int i=0;i<LED_COUNT;i++) {
//ring.clear(); // Deaktivated = Fill | Aktivated = Run
ring.setPixelColor(i, RED);
ring.show();
delay(1000);
}
LED_off(); // filling the circle sequence
}
void LED_Ring_Color(uint32_t led_color, const char* led_color_name) { // LED Color - - -
for(int i = 0; i < LED_COUNT; i++)
ring.setPixelColor(i, led_color);
Serial.print("LED: ");
Serial.println(led_color_name);
ring.show();
}
void LED_off() { // LED Modul OFF - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ring.clear();
ring.show();
Serial.println("End");
}
void MicroSD(uint32_t index) { // MicroSD Modul - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Serial.println("------ MicroSD Content ------");
File file = SD.open("/test.txt", FILE_WRITE);
if(file) {
file.print("Eintrag: ");
file.println(index);
file.println("DS18B20:");
file.print(ds18b20.getTempCByIndex(0));
file.println(" °C");
file.println();
file.println("BMP:");
file.print(bmp.readPressure());
file.println(" Pa");
file.println();
file.println("MPU6050:");
file.print(a.acceleration.x);
file.println(" m/s²");
file.print(a.acceleration.y);
file.println(" m/s²");
file.print(a.acceleration.z);
file.println(" m/s²");
file.println();
file.print(g.gyro.x);
file.println(" rad/s");
file.print(g.gyro.y);
file.println(" rad/s");
file.print(g.gyro.z);
file.println("rad/s");
file.println();
file.close();
Serial.println("Datei geschrieben.");
}
else
Serial.println("Datei konnte nicht erstellt werden.");
if(file) {
Serial.println("Inhalt:");
while(file.available())
Serial.write(file.read());
file.close();
}
}Loading
bmp180
bmp180