Hi,
I have a problem with connecting the TFT screen to Pro Micro. I will thankful for any help.
I'm not any specialist in Arduino. This is one of my first projects, so please explain very simply :).
I created a program code compile and load onto Arduino Uno. Everything was fine, program worked properly. But due to problem with place I decided to buy a Pro Micro and now its a problem because the program doesn't work and I do not have any idea whats is wrong. If somebody can help my, provide my some ideas I will thankful.
Chosen device on IDE: Arduino Leonardo (according to instruction)
Arduino ProMicro TFT screen 1.44
pin 8 ---> DC
pin 10 ---> TCS
pin 16 ---> MOSI
pin 14 ---> RESET
pin 15 ---> SCK
Code of my program ( I know nothing special ):
#include <dht.h>
#define DHT22PIN 2
dht DHT22;
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#if defined(SAM3X8E)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
#define TFT_CS 10
#define TFT_RST 14
#define TFT_DC 8
#define ST7735_ORANGE 0xFD20
#define TFT_SCLK 15
#define TFT_MOSI 16
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
int Bat1 = A1;
int Bat2 = A2;
int Bat3 = A3;
float vout1 = 0.0;
float vout2 = 0.0;
float vout3 = 0.0;
float napiecie = 0.0;
float napiecie1 = 0.0;
float napiecie2 = 0.0;
float napiecie3 = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float stanbaterii = 0;
int wartosc1 = 0;
int wartosc2 = 0;
int wartosc3 = 0;
const int barW=12,nBars=8, x_axis=0, y_axis=0, x0=0, y0=0;
void setup(void) {
Serial.begin(9600);
tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, green tab
tft.fillScreen(ST7735_BLUE);
tft.drawRect(0, 2, 127, 126, ST7735_WHITE);
tft.drawRect(1, 3, 125, 124, ST7735_WHITE);
tft.setCursor(20,110);
tft.setTextColor(ST7735_ORANGE);
tft.setTextSize(1);
tft.print("Three Wheel Fun");
/////////////////////////////////////////////////////////
tft.drawFastHLine(0,100, 128, ST7735_WHITE);
tft.drawFastVLine(64, 0,100,ST7735_WHITE);
/////////////////////////////////////////////////////////
tft.setCursor(5, 15);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("Napiecia:");
pinMode(Bat1, INPUT);
tft.setCursor(5, 35);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("Bat1:");
tft.setCursor(55, 35);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("V");
pinMode(Bat2, INPUT);
tft.setCursor(5, 55);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("Bat2:");
tft.setCursor(55, 55);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("V");
pinMode(Bat3, INPUT);
tft.setCursor(5, 75);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("Bat3:");
tft.setCursor(55, 75);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("V");
//////////////////////////////////////////////////////////////////
tft.setCursor(70, 15);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("Prad:");
tft.setCursor(103, 30);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(2);
tft.print("A");
//////////////////////////////////////////////////////////////////
tft.setCursor(70, 55);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("Stan");
tft.setCursor(70, 65);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.print("baterii:");
tft.setCursor(109, 80);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(2);
tft.print("%");
}
void loop() {
tft.fillRect(35,30,19,55,ST7735_BLUE);//Refresh napiec
tft.fillRect(70,25,33,25,ST7735_BLUE);//Refresh pradu
tft.fillRect(70,75,33,22,ST7735_BLUE);//Refresh stanu baterii
int chk = DHT22.read(DHT22PIN);
/////////////////////////////////////////////////////////////Wartosc Napiecia 1
wartosc1 = analogRead(Bat1);
vout1 = (wartosc1 * 5.0) / 1024.0;
napiecie1 = vout1 / (R2/(R1+R2));
tft.setCursor(40, 35);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1); //wyświetlenie temperatury
tft.print((float)napiecie1, 0);
///////////////////////////////////////////////////////////Wartosc Napiecia 2
wartosc2 = analogRead(Bat2);
vout2 = (wartosc2 * 5.0) / 1024.0;
napiecie2 = vout2 / (R2/(R1+R2));
tft.setCursor(40, 55);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1); //wyświetlenie wartości wilgotności
tft.println((float)napiecie2, 0);
///////////////////////////////////////////////////////////Wartosc Napiecia 3
wartosc3 = analogRead(Bat3);
vout3 = (wartosc3 * 5.0) / 1024.0;
napiecie3 = vout3 / (R2/(R1+R2));
tft.setCursor(40, 75);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.println((float)napiecie3, 0);
///////////////////////////////////////////////////////////Wartosc Pradu
tft.setCursor(77, 30);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(2); //wyświetlenie temperatury
tft.print((float)DHT22.temperature, 0);
////////////////////////////////////////////////////////////Wartosc Stanu Baterii
tft.setCursor(70, 80);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(2); //wyświetlenie temperatury
napiecie=napiecie1+napiecie2+napiecie3;
if(napiecie>=28)
{
stanbaterii=100;
}
if(napiecie<=28)
{
stanbaterii=50;
}
if(napiecie<=25.5)
{
stanbaterii=0;
}
tft.print((float)stanbaterii, 0);
delay(10000); //opóźnienie między kolejnymi odczytami - 1 s
}