Hallo, :~
Stimmt ist eine blöde Beschreibung
Es ist so das es normal Funtioniert aber halt so langsam wie ohne SPI
Wenn ich das Temperaturshild abnehme und nur das Display anstecke ist der fehler wie immer auch da.
Nur ohne die
int Read_Temperature(void)
{
rotine
Geht es schnell
Was komisch ist
mit der Libery von Adafruit
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
geht die Temperaturanzeige und das Display schnell.
Adafruit hat leider nicht die möglichkeiten der Font´s usw nicht gegenüber UTFT
hier der Code mit Adafruit
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define sclk 13
#define mosi 11
#define cs 10
#define dc 9
#define rst 8 // you can also connect this to the Arduino reset
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
#define CS_TEMP 3 // MAX6674/6675 /CS Line
#define MUX_EN 7 // ADG608 MUX Enable
#define MUX_A0 4 // ADG608 Addr0
#define MUX_A1 5 // ADG608 Arrd1
#define MUX_A2 6 // ADG608 Addr2
byte Zaehler = 0 ;
String Geber = "";
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
// pinMode(10,OUTPUT); // Hardware /SS, need to be output
pinMode(CS_TEMP,OUTPUT); // MAX6675/6674 /CS Line
pinMode(MUX_EN,OUTPUT); // Enable pin on ADG608
pinMode(MUX_A0,OUTPUT); // A0 on ADG608
pinMode(MUX_A1,OUTPUT); // A1 on ADG608
pinMode(MUX_A2,OUTPUT); // A2 on ADG608
pinMode(10, OUTPUT); randomSeed(analogRead(0));
digitalWrite(CS_TEMP,HIGH); // Set MAX7765 /CS High
digitalWrite(MUX_EN,HIGH); // Enable on
tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab
Serial.println("init");
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
time = millis() - time;
Serial.println(time, DEC);
delay(50);
// Serial.println(tft.getRotation(), DEC); // Display drehen
tft.setRotation(tft.getRotation()+1); // Anzeige gedreht
tft.fillScreen(ST7735_BLACK);
tft.setTextSize(3);
tft.println("Hello World!");
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(10);
tft.print(1234.567);
tft.setRotation(tft.getRotation()+1); // Anzeige gedreht
// tft print function!
// a single pixel
tft.drawPixel(tft.width()/2, tft.height()/2, ST7735_GREEN);
delay(50);
// line draw test
testlines(ST7735_YELLOW);
delay(50);
// optimized lines
testfastlines(ST7735_RED, ST7735_BLUE);
delay(50);
testdrawrects(ST7735_GREEN);
delay(50);
testfillrects(ST7735_YELLOW, ST7735_MAGENTA);
delay(50);
tft.fillScreen(ST7735_BLACK);
testfillcircles(10, ST7735_BLUE);
testdrawcircles(10, ST7735_WHITE);
delay(50);
testroundrects();
delay(50);
testtriangles();
delay(50);
Serial.println("done");
delay(1000);
}
void loop() {
int temperature = 0;
Zaehler = 0 ;
tft.fillScreen(ST7735_BLACK);
while(Zaehler < 8 )
{
Zaehler = Zaehler ++ ;
delay(1);
Set_Mux_Channel(Zaehler);
temperature = Read_Temperature();
tft.setTextSize(2);
tft.setCursor(0,Zaehler19-19);
tft.setTextColor(ST7735_YELLOW);
if(temperature == -1)
{
Geber = String(Zaehler);
Serial.println("N/C Sensor " + Geber);
tft.println("N/C " + Geber );
// myGLCD.print("N/C Se", Zaehler * 19 -14,125,270); //
// myGLCD.print("N/C Se" + Geber + " ", Temp * 19 -14,125,270); //
}
else
{
Serial.print(temperature,DEC);
Geber = String(Zaehler);
Serial.println(" C Sensor " + Geber);
tft.println("H" + String(temperature,DEC) +" " + Geber );
// myGLCD.print(String(temperature,DEC)+"Test", Zaehler * 19 -14,125,270); //
// myGLCD.print(String(temperature,DEC)+ " C Se" + Geber + " ", Temp * 19 -14,125,270); //
Serial.println(Geber);
}
}
}
void testlines(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, 0, x, tft.height()-1, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, 0, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, 0, 0, y, color);
}
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, tft.height()-1, x, 0, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
}
}
void testdrawtext(char text, uint16_t color) {
tft.setCursor(0, 0);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
for (int16_t y=0; y < tft.height(); y+=5) {
tft.drawFastHLine(0, y, tft.width(), color1);
}
for (int16_t x=0; x < tft.width(); x+=5) {
tft.drawFastVLine(x, 0, tft.height(), color2);
}
}
void testdrawrects(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
}
}
void testfillrects(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
for (int16_t x=tft.width()-1; x > 6; x-=6) {
tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
}
}
void testfillcircles(uint8_t radius, uint16_t color) {
for (int16_t x=radius; x < tft.width(); x+=radius2) {
for (int16_t y=radius; y < tft.height(); y+=radius2) {
tft.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
for (int16_t x=0; x < tft.width()+radius; x+=radius2) {
for (int16_t y=0; y < tft.height()+radius; y+=radius2) {
tft.drawCircle(x, y, radius, color);
}
}
}
void testtriangles() {
tft.fillScreen(ST7735_BLACK);
int color = 0xF800;
int t;
int w = 63;
int x = 159;
int y = 0;
int z = 127;
for(t = 0 ; t <= 15; t+=1) {
tft.drawTriangle(w, y, y, x, z, x, color);
x-=4;
y+=4;
z-=4;
color+=100;
}
}
void testroundrects() {
tft.fillScreen(ST7735_BLACK);
int color = 100;
int i;
int t;
for(t = 0 ; t <= 4; t+=1) {
int x = 0;
int y = 0;
int w = 127;
int h = 159;
for(i = 0 ; i <= 24; i+=1) {
tft.drawRoundRect(x, y, w, h, 5, color);
x+=2;
y+=3;
w-=4;
h-=6;
color+=1100;
}
color+=100;
}
}
void Set_Mux_Channel(unsigned char chan)
{
switch(chan)
{
case 1:
digitalWrite(MUX_A0,LOW);
digitalWrite(MUX_A1,LOW);
digitalWrite(MUX_A2,LOW);
break;
case 2:
digitalWrite(MUX_A0,HIGH);
digitalWrite(MUX_A1,LOW);
digitalWrite(MUX_A2,LOW);
break;
case 3:
digitalWrite(MUX_A0,LOW);
digitalWrite(MUX_A1,HIGH);
digitalWrite(MUX_A2,LOW);
break;
case 4:
digitalWrite(MUX_A0,HIGH);
digitalWrite(MUX_A1,HIGH);
digitalWrite(MUX_A2,LOW);
break;
case 5:
digitalWrite(MUX_A0,LOW);
digitalWrite(MUX_A1,LOW);
digitalWrite(MUX_A2,HIGH);
break;
case 6:
digitalWrite(MUX_A0,HIGH);
digitalWrite(MUX_A1,LOW);
digitalWrite(MUX_A2,HIGH);
break;
case 7:
digitalWrite(MUX_A0,LOW);
digitalWrite(MUX_A1,HIGH);
digitalWrite(MUX_A2,HIGH);
break;
case 8:
digitalWrite(MUX_A0,HIGH);
digitalWrite(MUX_A1,HIGH);
digitalWrite(MUX_A2,HIGH);
break;
default:
break;
}
}
int Read_Temperature(void)
{
unsigned int temp_reading;
//force conversion now..
delay(5); // Ori 5
digitalWrite(CS_TEMP,LOW); // Set MAX7765 /CS Low
delay(5); // Ori 5
digitalWrite(CS_TEMP,HIGH); // Set MAX7765 /CS High
delay(250); // Ori 250 wait for conversion to finish..
// read result
digitalWrite(CS_TEMP,LOW); // Set MAX7765 /CS Low
delay(1); // Ori 1
temp_reading = SPI.transfer(0xff) << 8;
temp_reading += SPI.transfer(0xff);
digitalWrite(CS_TEMP,HIGH); // Set MAX7765 /CS High
//delay(1);
// check result
if(bitRead(temp_reading,2) == 1) // No Connection
{
return(-1); // Failed / NC Error
}
else
{
return((int)(temp_reading >> 5)); //Convert to Degc
}
}
Grüße
Ratlos