Hallo zusammen,
hab da mal wieder ne Frage.
Ich habe einen MAX6675 Sensor der mit einem 96x96 OLED Display funktioniert.
// 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_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE); //IIC
//
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 = 6;
int thermoCS = 5;
int thermoCLK = 4;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 3;
int gndPin = 2;
//
//
void draw(void) {
u8g.setFont(u8g_font_profont15);
u8g.drawStr(10,10, "Motortemperatur");
u8g.setFont(u8g_font_profont12);
// show max temp reached
u8g.drawStr(10,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(30,25, maxTempC);
// show the min temp reached
u8g.drawStr(70,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(90,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,62, 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);
}
Nun möchte ich diesen mit einem 128x128 Display benutzen. Ich habe den Sketch umgeschrieben, leider
funktiomiert es nicht und das Display bleibt dunkel
// Add libraries
//#include "U8glib.h"
#include <SPI.h>
#include <Wire.h>
#include "max6675.h"
#include <U8g2lib.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_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE); //IIC
U8G2_SSD1327_EA_W128128_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1327_EA_W128128_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ U8X8_PIN_NONE);
//
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 = 6;
int thermoCS = 5;
int thermoCLK = 4;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 3;
int gndPin = 2;
//
//
void draw(void) {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.drawStr(10,10, "Motortemperatur");
u8g2.setFont(u8g2_font_6x10_tf);
// show max temp reached
u8g2.drawStr(10,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();
u8g2.drawStr(30,25, maxTempC);
// show the min temp reached
u8g2.drawStr(70,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();
u8g2.drawStr(90,25, minTempC);
u8g2.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();
u8g2.drawStr(pad,62, 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
u8g2.firstPage();
do {
draw();
} while( u8g2.nextPage() );
// rebuild the picture after some delay
delay(50);
}
wo ist mein Fehler?