Ein Thermometer für alle Fälle
Revision as of 08:33, 1 September 2023 by Nabla (talk | contribs) (Created page with "{{Infobox Experiment | Name = Ein Thermometer für alle Fälle | Category = Arduino library experiments | Sensors = DS18B20 }} Text File:Amontons_Glas_1.jpg ==Aufba...")
Ein Thermometer für alle Fälle
| Experiment | Ein Thermometer für alle Fälle |
|---|---|
| Category | Arduino library experiments |
| Used sensors | DS18B20 |
Text
Aufbau
Der Temperatursensor liefert seine Daten über den OneWire-Bus: 3V3 – Vin, Gnd – Gnd, 4 - Datenbus.
Programmierung
Der ESP32 wird über die Arduino IDE programmiert. Es müssen die Definitionen für den ESP32 und die phyphox-Bibliothek installiert sein. Siehe dazu das Video unter Category: Arduino library experiments.
Es ist darauf zu achten, dass jeder ESP32 eine eigene Kennung hat (diese wird in PhyphoxBLE::start("Baro_Therm_01") festgelegt). Anschließend kann über das Plus-Symbol in phyphox ein Bluetooth-Experiment hinzugefügt werden, das Experiment wird dann automatisch geladen.
#include <Wire.h>
#include "Adafruit_MPRLS.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#include <phyphoxBle.h>
float p;
#define RESET_PIN -1
#define EOC_PIN -1
Adafruit_MPRLS mpr = Adafruit_MPRLS(RESET_PIN, EOC_PIN);
void setup() {
PhyphoxBLE::start("Baro_Therm_01");
//Experiment
PhyphoxBleExperiment experiment;
experiment.setTitle("Baro_Therm_01");
experiment.setCategory("Arduino Experiments");
experiment.setDescription("Plot the pressure over time.");
//View
PhyphoxBleExperiment::View view;
//Value
PhyphoxBleExperiment::Value Value1;
Value1.setLabel("p = ");
Value1.setUnit("hPa");
Value1.setChannel(1);
PhyphoxBleExperiment::Value Value2;
Value2.setLabel("Theta = ");
Value2.setUnit("°C");
Value2.setChannel(2);
//Graph
PhyphoxBleExperiment::Graph graph1;
graph1.setLabel("Druck");
graph1.setUnitX("s");
graph1.setUnitY("hPa");
graph1.setLabelX("time");
graph1.setLabelY("p");
graph1.setChannel(0,1);
PhyphoxBleExperiment::Graph graph2;
graph2.setLabel("Temperatur");
graph2.setUnitX("s");
graph2.setUnitY("°C");
graph2.setLabelX("time");
graph2.setLabelY("Theta");
graph2.setChannel(0,2);
PhyphoxBleExperiment::Graph graph3;
graph3.setLabel("p over Theta");
graph3.setUnitX("°C");
graph3.setUnitY("hPa");
graph3.setLabelX("Theta");
graph3.setLabelY("p");
graph3.setStyle("dots");
graph3.setChannel(2,1);
view.addElement(graph1);
view.addElement(Value1);
view.addElement(graph2);
view.addElement(Value2);
view.addElement(graph3);
experiment.addView(view);
PhyphoxBLE::addExperiment(experiment);
Serial.begin(38400);
sensors.begin();
mpr.begin();
}
void loop() {
p=0;
for(int i=0;i<37;i++){
p+=mpr.readPressure();
delay(10);
}
p=p/37;
sensors.requestTemperatures();
float T = sensors.getTempCByIndex(0);
PhyphoxBLE::write(p,T);
Serial.print(p);
Serial.print(" ");
Serial.println(T);
delay(10);
}
