Guten Morgen Arduino - Freunde,
ich habe meinen Nano mit einem OLed Display vorbereitet um Temperaturen zu messen. Nur leider spuckt das kleine Display alles aus nur keine Temperatur.
Angeschlossen ist der Sensor so:
GND - GND
VCC - 5V
SCK - D13
CS - D10
SO - D12
Der zugehörige Code:
// Add libraries
#include "U8glib.h"
#include <SPI.h>
#include <Wire.h>
#include "max6675.h"
// change between Centigrade and Fahrenheit here
// REM out the line not needed
//
boolean centigrade = true; //Un REM this for Centigrade and REM out line below
// boolean centigrade = false; // Un REM this for Fahrenheit and REM out line above
//
// setup u8g object
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
//
double max = 215; // maximum temperature
double min = -215; // minimum temperature
float currentTemp = 0.00;
String thisTemp = "";
int maxTemp = 0; // maximum temperature reached
int minTemp = 0; // minimum temperature reached
int pad = 0;
//
// Thermocouple MAX 6675
//
int thermoDO = 13;
int thermoCS = 12;
int thermoCLK = 10;
MAX6675 thermocouple(thermoDO, thermoCS, thermoCLK);
int vccPin = 10;
int gndPin = 2;
//
//
void draw(void) {
u8g.setFont(u8g_font_profont12);
u8g.drawStr(20,10, "Oil Temperature");
u8g.setFont(u8g_font_profont12);
u8g.drawStr(0,60, "Subaru Impreza Spec C") ;
u8g.setFont(u8g_font_profont12);
// show max temp reached
u8g.drawStr(85,25, "max");
if(maxTemp <= int(currentTemp)){ maxTemp = int(currentTemp);}
thisTemp = String(maxTemp);
if(centigrade){
thisTemp = thisTemp + "\260C";
}
else{
thisTemp = thisTemp + "\260F";
}
const char* maxTempC = (const char*) thisTemp.c_str();
u8g.drawStr(105,25, maxTempC);
// show the min temp reached
u8g.drawStr(5,25, "min");
if(minTemp >= int(currentTemp)){ minTemp = int(currentTemp);}
thisTemp = String(minTemp);
if(centigrade){
thisTemp = thisTemp + "\260C";
}
else{
thisTemp = thisTemp + "\260F";
}
const char* minTempC = (const char*) thisTemp.c_str();
u8g.drawStr(30,25, minTempC);
u8g.setFont(u8g_font_profont29);
if(currentTemp > 99){pad = 2;}
if(currentTemp > 9 && currentTemp < 100){pad = 10;}
if(currentTemp < 10){pad = 18;}
thisTemp = String(currentTemp);
if(centigrade){
thisTemp = thisTemp + "\260C";
}
else{
thisTemp = thisTemp + "\260F";
}
const char* newDispC = (const char*) thisTemp.c_str();
u8g.drawStr(pad,50, newDispC);
}
void setup(void) {
Serial.begin(9600);
Wire.begin();
// use Arduino pins
pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
delay(500); // wait for MAX chip to stabilise
if(centigrade){
currentTemp = thermocouple.readCelsius();
minTemp = int(thermocouple.readCelsius());
maxTemp = int(thermocouple.readCelsius());
}
else{
currentTemp = thermocouple.readFahrenheit();
minTemp = int(thermocouple.readFahrenheit());
maxTemp = int(thermocouple.readFahrenheit());
}
}
void loop(void) {
currentTemp = 0;
for(int f = 0; f <25; f++){
if(centigrade){
currentTemp = thermocouple.readCelsius() + currentTemp;
}
else{
currentTemp = thermocouple.readFahrenheit() + currentTemp;
}
}
currentTemp = currentTemp/25; // averages out 25 readings
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(50);
}
Fehler habe ich keine nur wie gesagt keine Ausgabe. Habt Ihr eine Idee? Display zeigt alles an.
Vielen Dank