Hi Group
I made a small board with a Wemos D1, a 1.8 tft, and a One wire sensor.
The sensor works fine. Im a bit impressed of the low noiselevel, and the accuracy.
The button input works fine on itself.
The tft is really cool. Works fine, and once I found the right libraries for the tft it was easy to work with.
But combining things causes the button on D2 to not function.
I dis some basic troubleshooting, and with the tft(and libs commenting out everything works fine. But with tft.initR(INITR_BLACKTAB); in the code I do net get any response from the button on D2(GPIO04). Everything else works fine.
Should I look for an error or something using the D2 pin within one of the library files? Or how would you troubleshoot this?
Line 44 is the line that stops De pin from responding. Line 45 is just a small function with some tft screen writing.
With both line 44 and 45 active everything works fine except for the D2 button pin.
Peter
#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 for other chip. just exclude...
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define TFT_CS D1
#define TFT_RST D0
#define TFT_DC D2
#define Relaypin D8
#define PlusPin D3
#define MinusPin D6
#define Relaypin D8 // not used yet, but commenting it out does not change..
#define ONE_WIRE_PIN D4
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature DS18B20(&oneWire);
boolean aButton, PlusButton, KnapPlus, KnapMinus , plus = false;
boolean KnapPlusgl, KnapMinusgl = true;
unsigned long KnapAPressed, KnapPlusPressed, KnapMinusPressed = 0;
float temp = 0;
int sensorValue = 0;
int AnalogInput = A0;
int DebounceTime = 25;
unsigned long currentMillis, previousMillis = 0;
const long interval = 5000;
//********************************* declarations above OK*********************//
void setup() {
pinMode(A0, INPUT);
pinMode(PlusPin, INPUT_PULLUP);
pinMode(MinusPin, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(Relaypin, OUTPUT);
Serial.begin(9600);
DS18B20.begin();
//tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
//velcome();
}
void loop() {
// *********************** READING SENSOR EWERY % SECONDS***********************
currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Serial.println("El Cheapo Interrupt fyrert");
Read_Temperature();
}
sensorValue = analogRead(AnalogInput); // Serial.println(sensorValue);
if (sensorValue < 300) { // Pressing button..
if (!aButton) {
// Serial.println("analog nede");
KnapAPressed = millis();
}
aButton = true;
}
if (sensorValue > 300 && aButton) { // her bliver knappen sluppet
KnapA((millis() - KnapAPressed)); //Button released again
KnapAPressed = millis();
aButton = false;
}
// ****************************** PLUS ****************************************
KnapPlus = !digitalRead(PlusPin); //Checking for the minus button.
if (KnapPlus & KnapPlusgl) { // Pressing button..
KnapPlusPressed = millis();
KnapPlusgl = false;
}
if (!KnapPlus & !KnapPlusgl) { // Button released again
KnapPlusgl = true;
KnapP(millis() - (KnapPlusPressed));
}
//minus virker ikke
// *****************************************************************************
KnapMinus = !digitalRead(MinusPin); //Checking for the minus button.
if (KnapMinus & KnapMinusgl) { // Pressing button..
Serial.println(" Minus Ned trykket.");
KnapMinusPressed = millis();
KnapMinusgl = false;
}
if (!KnapMinus & !KnapMinusgl) { // Button released again
KnapMinusgl = true;
KnapM(millis() - (KnapMinusPressed));
Serial.println(" Minus Sluppet igen..");
// Serial.println("Minus Sluppet");
}
}
//************************** Externe funktioner***********************
void KnapA(unsigned long tid) { // Function funktion for knapA
if (tid > DebounceTime) {
Serial.print("Knappen A er sluppet efter: ");
Serial.print(tid);
Serial.println(" milisekunder.");
}
}
void KnapP(unsigned long tid) { // Function funktion for knapPlus
if (tid > DebounceTime) {
Serial.print("Knappen + er sluppet efter: ");
Serial.print(tid);
Serial.println(" milisekunder.");
}
}
void KnapM(unsigned long tid) { // Function for knapMinus
if (tid > DebounceTime) {
Serial.print("Knappen - er sluppet efter: ");
Serial.print(tid);
Serial.println(" milisekunder.");
}
}
void Read_Temperature() {
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.println(temp);
}
void velcome() {
tft.fillScreen(ST77XX_BLACK);
tft.setTextSize(0);
tft.setCursor(20, 20);
tft.println("Splash Screen Text");
tft.setCursor(20, 60);
tft.println("V. 1.0");
}