Added DS18B20 Tempertur measurement
This commit is contained in:
parent
ab1325f07f
commit
e6b18d163d
@ -11,7 +11,9 @@
|
||||
#ifndef FANLEDCTL_PINS
|
||||
#define FANLEDCTL_PINS
|
||||
|
||||
#define FAN_PIN 12
|
||||
#define SIGNAL_PIN 13
|
||||
#define FAN_PIN 12 /**< Output Pin, controlling FAN speed via PWM */
|
||||
#define SIGNAL_PIN 13 /**< Input Pin, reading current FANs RPM*/
|
||||
|
||||
#define GPIO_DS18B20 D7 /**< One-Wire used for Dallas temperature sensor */
|
||||
|
||||
#endif /* End FANLEDCTL_PINS */
|
@ -12,3 +12,6 @@
|
||||
platform = espressif8266
|
||||
board = d1_wroom_02
|
||||
framework = arduino
|
||||
|
||||
lib_deps = OneWire
|
||||
DallasTemperature
|
44
src/main.cpp
44
src/main.cpp
@ -1,11 +1,19 @@
|
||||
#include <Arduino.h>
|
||||
#include <DallasTemperature.h>
|
||||
#include <OneWire.h>
|
||||
#include "controller.h"
|
||||
|
||||
|
||||
#define DELAY_TIME 10000 // time between measurements [ms]
|
||||
#define MIN_FAN_SPEED_PERCENT 24 // minimum fan speed [%]
|
||||
#define MIN_TEMP 25 // turn fan off below [deg C]
|
||||
#define MAX_TEMP 40 // turn fan to full speed above [deg C]
|
||||
#define DELAY_TIME 10000 /**< time between measurements [ms] */
|
||||
#define MIN_FAN_SPEED_PERCENT 24 /**< minimum fan speed [%] */
|
||||
#define MIN_TEMP 25 /**< turn fan off below [deg C] */
|
||||
#define MAX_TEMP 40 /**< turn fan to full speed above [deg C] */
|
||||
#define INVALID_TEMP (MAX_TEMP+MAX_TEMP) /**< Invalid temperature (on sensor failures)*/
|
||||
|
||||
#define TEMP_SENSOR_MEASURE_SERIES 5 /**< Maximum resets */
|
||||
|
||||
OneWire oneWire(GPIO_DS18B20);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
/**
|
||||
* @brief Called once at start
|
||||
@ -14,9 +22,17 @@
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
/* Setup FAN Control */
|
||||
pinMode(FAN_PIN, OUTPUT);
|
||||
pinMode(SIGNAL_PIN, INPUT);
|
||||
/* Initialize Temperature sensor */
|
||||
sensors.begin();
|
||||
for(int j=0; j < TEMP_SENSOR_MEASURE_SERIES && sensors.getDeviceCount() == 0; j++)
|
||||
{
|
||||
delay(100);
|
||||
sensors.begin();
|
||||
Serial.println("Reset 1-Wire Bus");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,12 +61,28 @@ void setFanSpeedPercent(int p) {
|
||||
analogWrite(FAN_PIN, value);
|
||||
}
|
||||
|
||||
float readTemperature(void)
|
||||
{
|
||||
int sensorCount = sensors.getDeviceCount();
|
||||
if (sensorCount > 0)
|
||||
{
|
||||
sensors.requestTemperatures();
|
||||
float temp1Raw = sensors.getTempCByIndex(0);
|
||||
if (temp1Raw > 0)
|
||||
{
|
||||
return temp1Raw;
|
||||
}
|
||||
}
|
||||
|
||||
return INVALID_TEMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Endless loop
|
||||
* (is called as fast as possible)
|
||||
*/
|
||||
void loop() {
|
||||
float temp = /* FIXME bme.readTemperature(); */
|
||||
float temp = readTemperature();
|
||||
Serial.print("Temperature is ");
|
||||
Serial.print(temp);
|
||||
Serial.println(" deg C");
|
||||
|
Loading…
Reference in New Issue
Block a user