TFT.Begin not allowing one wire sensor to display data

Hello,

I am trying to run a reef controller for my aquarium. I am very new to coding and welcome any input to clean up my code but I have an issue that I cannot figure out. When I run a separate code for the Dallas temperature DS18B sensor, the Arduino Nano I am using is able to display temperature on the serial monitor just fine. I also have code for my reef controller which includes the “TFT.Begin” function and all works well on the screen. When I added the sensor code to my reef controller code, the screen worked as usual but unfortunately the sensor no longer sends a temperature. I have narrowed it down to one thing and that is, the “sensors.Begin” function stops working when “TFT.Begin” is also in the code. The temp sensor has a digital pin suppling 5v and a 4.7Kohm resistor. As I said, the sensor works correctly until it is paired with the screen in which case it only displays 85C 185F both on the TFT itself and the serial monitor. What can I do to get this functioning correctly?

Thanks in advance!

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#include <Wire.h>

#include <OneWire.h>
#include <DallasTemperature.h>

// Color definitions
#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 __CS 10
#define __DC 9

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

TFT_ILI9163C tft = TFT_ILI9163C(__CS, 8, __DC);

void setup(void) {

Serial.begin(9600);
sensors.begin();
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);

tft.begin();
tft.setRotation(3);
tft.fillScreen(WHITE);
tft.setTextWrap(true);
tft.setTextColor(BLACK,WHITE);
tft.setCursor(0,0);

//Title & underline
tft.setTextSize(2);
tft.setCursor(10, 18);
tft.print(“NANO WAVE”);
tft.fillRect(0, 33, 128, 3, BLUE);

//Drawing waves
tft.fillCircle(4, 88, 8, BLUE);
tft.fillCircle(20, 88, 8, BLUE);
tft.fillCircle(36, 88, 8, BLUE);
tft.fillCircle(52, 88, 8, BLUE);
tft.fillCircle(68, 88, 8, BLUE);
tft.fillCircle(84, 88, 8, BLUE);
tft.fillCircle(100, 88, 8, BLUE);
tft.fillCircle(116, 88, 8, BLUE);
tft.fillCircle(132, 88, 8, BLUE);
tft.fillRect(-3, 80, 15, 8, WHITE);
tft.fillRect(13, 89, 15, 8, WHITE);
tft.fillRect(29, 80, 15, 8, WHITE);
tft.fillRect(45, 89, 15, 8, WHITE);
tft.fillRect(61, 80, 15, 8, WHITE);
tft.fillRect(77, 89, 15, 8, WHITE);
tft.fillRect(93, 80, 15, 8, WHITE);
tft.fillRect(109, 89, 15, 8, WHITE);
tft.fillRect(125, 80, 15, 8, WHITE);

//Drawing of fish
tft.drawCircle(64, 64, 11, MAGENTA);
tft.fillTriangle(50, 40, 59, 54, 69, 54, YELLOW);
tft.drawLine(39, 53, 39, 75, MAGENTA);
tft.drawLine(39, 53, 60, 64, MAGENTA);
tft.drawLine(39, 75, 60, 64, MAGENTA);
tft.fillTriangle(40, 54, 40, 74, 60, 64, YELLOW);
tft.fillCircle(64, 64, 10, YELLOW);
tft.fillTriangle(50, 88, 59, 74, 69, 74, YELLOW);
tft.drawFastHLine(60, 50, 4, CYAN);
tft.drawFastHLine(60, 78, 4, CYAN);
tft.drawFastHLine(40, 59, 4, CYAN);
tft.drawFastHLine(40, 64, 5, CYAN);
tft.drawFastHLine(40, 69, 4, CYAN);

//Fins outline
tft.drawLine(49, 39, 70, 54, MAGENTA);
tft.drawLine(49, 39, 58, 54, MAGENTA);
tft.drawLine(49, 89, 70, 74, MAGENTA);
tft.drawLine(49, 89, 58, 74, MAGENTA);

//Fish eyes & mouth
tft.fillCircle(70, 60, 1, BLACK);
tft.drawLine(72, 67, 70, 67, BLACK);
tft.drawLine(70, 67, 69, 66, BLACK);

//Show logo & wait
delay(2000);

//Reset to white screen
tft.fillScreen(WHITE);

//Draw static details
tft.setTextSize(1);
tft.setCursor( 30, 10);
tft.print(“REEF CONTROL”);

tft.drawLine(0, 20, 128, 20, BLUE);

tft.setCursor(10, 85);
tft.print(“TEMP”);

}

void loop(void){

sensors.requestTemperatures();

Serial.print("Celsius temperature: “);
Serial.print(sensors.getTempCByIndex(0));
Serial.print(” - Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));

tft.setTextSize(2);
tft.setCursor(10,110);
// tft.print(sensors.getTempFByIndex(0));
tft.print(“ERROR”);

}

Reef_Controller_W__Temp_Only.ino (3.24 KB)

Pin 12 is MISO - part of the SPI which your TFT is using so it is messing the pin. I’m guessing you are also using pin 12 to power your sensor.

Time for a new pin assignment.

blh64:
Pin 12 is MISO - part of the SPI which your TFT is using so it is messing the pin. I'm guessing you are also using pin 12 to power your sensor.

Time for a new pin assignment.

Would I just have to reassign the power pin for the sensor in the main code or do I have to go into the library to change the pin assignment?

Thanks

blh64:
Pin 12 is MISO - part of the SPI which your TFT is using so it is messing the pin. I'm guessing you are also using pin 12 to power your sensor.

Time for a new pin assignment.

Just changed the pins and now it works! Thank you so much!