Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
yvesmorele
Published © GPL3+

Dual circular gauge display on screen ST7735

Use of a DHT11 to display the temperature and humidity on a circular gauge on an ST7735 screen

BeginnerFull instructions provided2,517
Dual circular gauge display on screen ST7735

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Proto Shield
Arduino Proto Shield
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long

Story

Read more

Schematics

wiring DHT 11

Code

circular gauge on ST7735

Arduino
 

#define cs   10
#define dc   9
#define rst  8 
#include <Adafruit_GFX.h>    
#include <Adafruit_ST7735.h> 
#include <SPI.h>
#include "DHT.h"
#define DHTPIN 2     
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);

#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);

#define BLACK   0x0000                                                                            
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GRAY    0xA514
#define DARKRED 0x8800
#define ORANGE  0xFC62

float anglef = 0.0;                                                                               
float rayonf = 30.0;                                                                              

float anglefh = 0.0;                                                                               
float rayonfh = 30.0;

int xo = 40;                                                                                     
int yo = 48;                                                                                     

int xo1 = 120;                                                                                     
int yo1 = 48;

float x1f = 0.0;                                                                                  
float y1f = 0.0;                                                                                  
int x1 = 0;                                                                                       
int y1 = 0;                                                                                       

float x1fh = 0.0;                                                                                  
float y1fh = 0.0;                                                                                  
int x1h = 0;                                                                                       
int y1h = 0;                                                                                       

float x2f = 0.0;                                                                                  
float y2f = 0.0;                                                                                  
int x2 = 0;                                                                                       
int y2 = 0;                                                                                       

float x2fh = 0.0;                                                                                  
float y2fh = 0.0;                                                                                  
int x2h = 0;                                                                                       
int y2h = 0;                                                                                       

float x1Bordf = 0.0;                                                                              
float y1Bordf = 0.0;                                                                              
int x1Bord = 0;                                                                                   
int y1Bord = 0;                                                                                   

float x1Bordfh = 0.0;                                                                              
float y1Bordfh = 0.0;                                                                              
int x1Bordh = 0;                                                                                   
int y1Bordh = 0;                                                                                   

float x2Bordf = 0.0;                                                                              
float y2Bordf = 0.0;                                                                              
int x2Bord = 0;                                                                                   
int y2Bord = 0;                                                                                   

float x2Bordfh = 0.0;                                                                              
float y2Bordfh = 0.0;                                                                             
int x2Bordh = 0;                                                                                   
int y2Bordh = 0;                                                                                   


int couleur = 0;                                                                                  

int numeroBlocSeg = 0;                                                                            
int LastnumeroBlocSeg = 0;                                                                        

int numeroBlocSegHum = 0;                                                                            
int LastnumeroBlocSegHum = 0;   

float temperatureCourante = 0;                                                                    
float LasttemperatureCourante = -1;                                                               
float MaxTemp = -1;                                                                              
float MinTemp = -1;                                                                              

float humiditeCourante = 0;                                                                    
float LasthumiditeCourante = -1;                                                               
float MaxHum = -1;                                                                               
float MinHum = -1;               

void setup(){
  Serial.begin(9600);
  
  tft.initR(INITR_REDTAB);
  tft.setRotation(1);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(1,1);
  tft.setTextSize(2);
  tft.setTextColor(ST7735_CYAN,ST7735_BLACK);
      tft.print("initilisation");
      delay(200);
      tft.fillScreen(ST7735_BLACK);
      tft.setCursor(1,10);
      tft.setTextSize(1);
      tft.println("    DHT11 " );
      tft.println("");
      tft.setTextSize(1);
      tft.println(" mesure Humidite ");
      tft.println("");
       tft.println("");
      tft.print(" mesure temperature");
      tft.println("");
      tft.println("");
      tft.println("");
      tft.println("");
      tft.println("");
      tft.setTextColor(ST7735_CYAN,ST7735_BLACK);
     
      delay(2000);
      dht.begin();
       tft.fillScreen(ST7735_BLACK);
       FonctionTraceJauge();
       FonctionTraceJauge2();
}  

void loop(){
  tft.setTextSize(1);
  tft.setTextColor(ST7735_CYAN,ST7735_BLACK);
 
   tft.setCursor(1,20);
      tft.setTextSize(1);
      
  float h = dht.readHumidity();
 temperatureCourante = dht.readTemperature(); 
 humiditeCourante = dht.readHumidity();
  if (isnan(temperatureCourante)) {return;}

  static int CompteurRelevesTemperature = 0;                                                      
  static float SommeRelevesTemperature = 0.0;

    static int CompteurRelevesHumidite = 0;                                                      
  static float SommeRelevesHumidite = 0.0;
  
  CompteurRelevesTemperature++;                                                                   
  SommeRelevesTemperature = SommeRelevesTemperature + temperatureCourante;   

CompteurRelevesHumidite++;                                                                   
  SommeRelevesHumidite = SommeRelevesHumidite + humiditeCourante ; 
  tft.setCursor(112,4);
      tft.setTextSize(1);

  tft.print(int (h));
  tft.print(" %");
  
   

  numeroBlocSeg = int(h);
  if (CompteurRelevesTemperature >= 50) 
  {
    temperatureCourante = SommeRelevesTemperature / 50.0; 
    humiditeCourante = SommeRelevesHumidite / 50.0;   
    
    CompteurRelevesTemperature = 0; SommeRelevesTemperature = 0.0;                                
    CompteurRelevesHumidite = 0; SommeRelevesHumidite = 0.0;
    
         if (temperatureCourante > 38) {temperatureCourante = 38.0;} 
    else if (temperatureCourante < 0)  {temperatureCourante = 0.0;}

    if (humiditeCourante > 100) {temperatureCourante = 100.0;} 
    else if (humiditeCourante < 0)  {humiditeCourante= 0.0;}
    
    tft.setTextColor(GRAY, BLACK);                                                             
    tft.setTextSize(1);                                                                           
    if (temperatureCourante >= 10) 
    {
      tft.setCursor(35,4); tft.print(temperatureCourante, 0);                                  
      tft.setTextSize(1); tft.print((char)247);                                                   
    }
    else 
    {
      tft.setCursor(35, 4); tft.print(temperatureCourante, 0);                                 
      tft.setTextSize(1); tft.print((char)247);                                                   
    }
    
    if (temperatureCourante > MaxTemp || MaxTemp == -1) {MaxTemp = temperatureCourante;}          
    if (temperatureCourante < MinTemp || MinTemp == -1) {MinTemp = temperatureCourante;}        

    if (humiditeCourante  > MaxHum || MaxHum == -1) {MaxHum = humiditeCourante;}          
    if (humiditeCourante  < MinHum || MinHum == -1) {MinHum = humiditeCourante;}          

    
    tft.setTextSize(1);                                                                           
    tft.setTextColor(BLUE, BLACK);                                                                
    tft.setCursor(12, 102); tft.print(MinTemp, 0); tft.print((char)247);                          
    tft.setTextColor(RED, BLACK);                                                                
    tft.setCursor(50, 102); tft.print(MaxTemp, 0); tft.print((char)247);                         

    tft.setTextSize(1);                                                                       
    tft.setTextColor(BLUE, BLACK);                                                              
    tft.setCursor(96, 102); tft.print(MinHum, 0); tft.print(" %");                          
    tft.setTextColor(RED, BLACK);                                                                
    tft.setCursor(130, 102); tft.print(MaxHum, 0); tft.print(" %");                         
   
  }
  else {return;} 
  
  numeroBlocSeg = int(temperatureCourante);                                                       
  
  if (temperatureCourante > LasttemperatureCourante) 
  {
    for (int i = LastnumeroBlocSeg; i <= numeroBlocSeg; i++) 
    {
      for (int j = 0; j <= 4; j++) 
      {
        int AngleSegBloc = 263 - ((9 * i) + j);                                                   
        
        anglef = float(AngleSegBloc);                                                             
        anglef = anglef * 3.14159;
        anglef = anglef / 180.0;
        
        x1f = cos(anglef);                                                                        
        x1f = rayonf*x1f;
        x1 = int(x1f);
        
        y1f = sin(anglef);                                                                     
        y1f = rayonf*y1f;
        y1 = int(y1f);
        
        x2f = cos(anglef);                                                                      
        x2f = rayonf/1.5*x2f;
        x2 = int(x2f);
        
        y2f = sin(anglef);                                                                        
        y2f = rayonf/1.5*y2f;
        y2 = int(y2f);
        
             if (i >= 0 && i <= 7)   {couleur = CYAN;}                                            
        else if (i >= 8 && i <= 18)  {couleur = ORANGE;}
        else if (i >= 19 && i <= 30) {couleur = GREEN;}
        else if (i >= 31 && i <= 38) {couleur = RED;}
        
        tft.drawLine(xo+x2, yo-y2, xo+x1, yo-y1, couleur);                                        
      }
    }
    
    LastnumeroBlocSeg = numeroBlocSeg;                                                           
    LasttemperatureCourante = temperatureCourante;                                               
  }
  else if (temperatureCourante < LasttemperatureCourante) 
  {
    for (int i = LastnumeroBlocSeg; i >= numeroBlocSeg; i--) 
    {
      for (int j = 0; j <= 4; j++) 
      {
        int AngleSegBloc = 263 - ((9 * i) + j);                                                   
        
        anglef = float(AngleSegBloc);                                                             
        anglef = anglef * 3.14159;
        anglef = anglef / 180.0;
        
        x1f = cos(anglef);                                                                     
        x1f = rayonf*x1f;
        x1 = int(x1f);
        
        y1f = sin(anglef);                                                                        
        y1f = rayonf*y1f;
        y1 = int(y1f);
        
        x2f = cos(anglef);                                                                   
        x2f = rayonf/1.5*x2f;
        x2 = int(x2f);
        
        y2f = sin(anglef);                                                                        
        y2f = rayonf/1.5*y2f;
        y2 = int(y2f);
        
        tft.drawLine(xo+x2, yo-y2, xo+x1, yo-y1, BLACK);                                          
      }
    }
    
    LastnumeroBlocSeg = numeroBlocSeg;                                                           
    LasttemperatureCourante = temperatureCourante;  

  
    }

    numeroBlocSegHum = int(humiditeCourante)/2.4;                                                     
  Serial.print(humiditeCourante);
  if (humiditeCourante > LasthumiditeCourante) 
  {
    for (int i = LastnumeroBlocSegHum; i <= numeroBlocSegHum; i++) 
    {
      for (int j = 0; j <= 4; j++)
      {
        int AngleSegBloch = 263 - ((9 * i) + j);                                                  
        
        anglefh = float(AngleSegBloch);                                                             
        anglefh = anglefh * 3.14159;
        anglefh = anglefh / 180.0;
        
        x1fh = cos(anglefh);                                                                 
        x1fh = rayonfh*x1fh;
        x1h = int(x1fh);
        
        y1fh = sin(anglefh);                                                                        
        y1fh = rayonfh*y1fh;
        y1h = int(y1fh);
        
        x2fh = cos(anglefh);                                                                       
        x2fh = rayonfh/1.5*x2fh;
        x2h = int(x2fh);
        
        y2fh = sin(anglefh);                                                                       
        y2fh = rayonfh/1.5*y2fh;
        y2h = int(y2fh);
        
             if (i >= 0 && i <= 7)   {couleur = CYAN;}                                          
        else if (i >= 8 && i <= 18)  {couleur = ORANGE;}
        else if (i >= 19 && i <= 30) {couleur = GREEN;}
        else if (i >= 31 && i <= 38) {couleur = RED;}
        
        tft.drawLine(xo1+x2h, yo1-y2h, xo1+x1h, yo1-y1h, couleur);                                       
      }
    }
    
    LastnumeroBlocSegHum = numeroBlocSegHum;                                                         
    LasthumiditeCourante = humiditeCourante;                                             
  }
  else if (humiditeCourante < LasthumiditeCourante) 
  {
    for (int i = LastnumeroBlocSegHum; i >= numeroBlocSegHum; i--) 
    {
      for (int j = 0; j <= 4; j++)
      {
        int AngleSegBloch = 263 - ((9 * i) + j);                                                   
        
        anglefh = float(AngleSegBloch);                                                             
        anglefh = anglefh * 3.14159;
        anglefh = anglefh / 180.0;
        
        x1fh = cos(anglefh);                                                                       
        x1fh = rayonfh*x1fh;
        x1h = int(x1fh);
        
        y1fh = sin(anglefh);                                                                       
        y1fh = rayonfh*y1fh;
        y1h = int(y1fh);
        
        x2fh = cos(anglefh);                                                                        
        x2fh = rayonfh/1.5*x2fh;
        x2h = int(x2fh);
        
        y2fh = sin(anglefh);                                                                        
        y2fh = rayonfh/1.5*y2fh;
        y2h = int(y2fh);
        
        tft.drawLine(xo1+x2h, yo1-y2h, xo1+x1h, yo1-y1h, BLACK);                                          
      }
    
    }
    LastnumeroBlocSegHum = numeroBlocSegHum;                                                        
    LasthumiditeCourante = humiditeCourante;  

  
    }
}

 void FonctionTraceJauge ()
{
  for (int i = 266; i >= -86; i--) 
  {
    anglef = float(i);                                                                           
    anglef = anglef * 3.14159;
    anglef = anglef / 180.0;
    
    x1Bordf = cos(anglef);                                                                        
    x1Bordf = rayonf*1.04*x1Bordf;
    x1Bord = int(x1Bordf);
    
    y1Bordf = sin(anglef);                                                                        
    y1Bordf = rayonf*1.04*y1Bordf;
    y1Bord = int(y1Bordf);
    
    x2Bordf = cos(anglef);                                                                        
    x2Bordf = rayonf/1.6*x2Bordf;
    x2Bord = int(x2Bordf);
    
    y2Bordf = sin(anglef);                                                                   
    y2Bordf = rayonf/1.6*y2Bordf;
    y2Bord = int(y2Bordf);
    
    if (i == 266 || i == -86) {tft.drawLine(xo+x2Bord, yo-y2Bord, xo+x1Bord, yo-y1Bord, BLUE);}   
    tft.drawPixel(xo+x2Bord, yo-y2Bord, BLUE);                                                    
    tft.drawPixel(xo+x1Bord, yo-y1Bord, BLUE);                                                    
  }
  
  for (int i = 0; i <= 38; i++) 
  {
    int AngleSegBloc = 263 - ((9 * i));                                                        
    
    anglef = float(AngleSegBloc);                                                                 
    anglef = anglef * 3.14159;
    anglef = anglef / 180.0;
    
    x1f = cos(anglef);                                                                          
    x1f = rayonf*x1f;
    x1 = int(x1f);
    
    y1f = sin(anglef);                                                                            
    y1f = rayonf*y1f;
    y1 = int(y1f);
    
    x2f = cos(anglef);                                                                           
    x2f = rayonf*1.1*x2f;
    x2 = int(x2f);
    
    y2f = sin(anglef);                                                                          
    y2f = rayonf*1.1*y2f;
    y2 = int(y2f);
         if (i >= 0 && i <= 7)   {couleur = CYAN;}                                                
    else if (i >= 8 && i <= 18)  {couleur = YELLOW;}
    else if (i >= 19 && i <= 30) {couleur = ORANGE;}
    else if (i >= 31 && i <= 38) {couleur = RED;}
        
    if (i % 2 == 0) {tft.drawLine(xo+x2, yo-y2, xo+x1, yo-y1, couleur);}                        
  }
  
  
  
  tft.setTextColor(WHITE, BLACK);                                                                
 
  
  tft.fillCircle(xo, yo, 13, CYAN);                                                             
  tft.fillCircle(xo, yo, 6, RED);                                                            
  
  tft.setTextColor(GRAY, BLACK);                                                                 
  tft.setTextSize(1);                                                                        
  tft.setCursor(15, 86); tft.print(F("TMin"));                                                    
 tft.setCursor(50, 86); tft.print(F("TMax"));                                                  
  
  
  
}

 void FonctionTraceJauge2 ()
{
  for (int i = 266; i >= -86; i--) 
  {
    anglef = float(i);                                                                            
    anglef = anglef * 3.14159;
    anglef = anglef / 180.0;
    
    x1Bordf = cos(anglef);                                                                       
    x1Bordf = rayonf*1.04*x1Bordf;
    x1Bord = int(x1Bordf);
    
    y1Bordf = sin(anglef);                                                                        
    y1Bordf = rayonf*1.04*y1Bordf;
    y1Bord = int(y1Bordf);
    
    x2Bordf = cos(anglef);                                                                        
    x2Bordf = rayonf/1.6*x2Bordf;
    x2Bord = int(x2Bordf);
    
    y2Bordf = sin(anglef);                                                                        
    y2Bordf = rayonf/1.6*y2Bordf;
    y2Bord = int(y2Bordf);
    
    if (i == 266 || i == -86) {tft.drawLine(xo1+x2Bord, yo1-y2Bord, xo1+x1Bord, yo1-y1Bord, BLUE);}  
    tft.drawPixel(xo1+x2Bord, yo1-y2Bord, BLUE);                                                 
    tft.drawPixel(xo1+x1Bord, yo1-y1Bord, BLUE);                                                 
  }
  
  for (int i = 0; i <= 38; i++) 
  {
    int AngleSegBloc = 263 - ((9 * i));                                                          
    
    anglef = float(AngleSegBloc);                                                                 
    anglef = anglef * 3.14159;
    anglef = anglef / 180.0;
    
    x1f = cos(anglef);                                                                           
    x1f = rayonf*x1f;
    x1 = int(x1f);
    
    y1f = sin(anglef);                                                                           
    y1f = rayonf*y1f;
    y1 = int(y1f);
    
    x2f = cos(anglef);                                                                      
    x2f = rayonf*1.1*x2f;
    x2 = int(x2f);
    
    y2f = sin(anglef);                                                                            
    y2f = rayonf*1.1*y2f;
    y2 = int(y2f);

         if (i >= 0 && i <= 7)   {couleur = CYAN;}                                                
    else if (i >= 8 && i <= 18)  {couleur = YELLOW;}
    else if (i >= 19 && i <= 30) {couleur = ORANGE;}
    else if (i >= 31 && i <= 38) {couleur = RED;}
        
    if (i % 2 == 0) {tft.drawLine(xo1+x2, yo1-y2, xo1+x1, yo1-y1, couleur);}                        
  }
  
 
  
  tft.setTextColor(WHITE, BLACK);                                                                 
 
  
  tft.fillCircle(xo1, yo1, 13, CYAN);                                                              
  tft.fillCircle(xo1, yo1, 6, RED);                                                           
  
  tft.setTextColor(GRAY, BLACK);                                                                
  tft.setTextSize(1);                                                                             
  tft.setCursor(95, 86); tft.print(F("HMin"));                                                 
 tft.setCursor(135, 86); tft.print(F("HMax"));                                                 
}

Credits

yvesmorele
9 projects • 47 followers
chemical scientist
Contact

Comments

Please log in or sign up to comment.