hi guys, im new to arduino forum, recently ive been working on a project and im stuck at a point where i cant use both the modules together -.-"
if i want to use the TFT it works fine with my code, but when i add the code for BMP180 pressure sensor the TFT gives a blank white screen, im fairly certain that the problem is with my coding, since its my first attempt at using these 2 modules, and my first attempt at using something with SCL and SDA, i dont know what i should do now, i spent hrs searching net but im still not able to fine a solution.
im attaching my code with this post , can someone verify it and tell me what is wrong in it?
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <Banggood9341_Hack.h>
#include <SFE_BMP180.h>
#include <Wire.h>
SFE_BMP180 pressure;
#define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
// D0 connects to digital pin 8 (Notice these are
// D1 connects to digital pin 9 NOT in order!)
// D2 connects to digital pin 2
// D3 connects to digital pin 3
// D4 connects to digital pin 4
// D5 connects to digital pin 5
// D6 connects to digital pin 6
// D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).
// D0 connects to digital pin 22
// D1 connects to digital pin 23
// D2 connects to digital pin 24
// D3 connects to digital pin 25
// D4 connects to digital pin 26
// D5 connects to digital pin 27
// D6 connects to digital pin 28
// D7 connects to digital pin 29
#define YP A1 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 6 // can be a digital pin
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET 12
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int currentcolor = WHITE;
int pressure_value,i=0;
void setup(void) {
Serial.begin(9600);
Serial.println(F("Touch screen!"));
tft.reset();
uint16_t identifier = 0x9341;
if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
}
tft.begin(identifier);
Lcd_Init();
tft.fillScreen(BLACK);
tft.setTextSize (3); // We define text size.
tft.setTextColor (BLACK); // define the text color
tft.setRotation (90); // We set the screen Vertical or Horizontal
tft.fillRect(10, 10, 100, 100, WHITE);
tft.fillRect(130, 10, 100, 100, WHITE);
tft.fillRect(10, 120, 220, 90, WHITE);
tft.fillRect(10, 220, 220, 90, WHITE);
pinMode(13, OUTPUT);
}
#define MINPRESSURE 5// minimum should be > 0
#define MAXPRESSURE 1000
int getpressure()
{ if (pressure.begin())
Serial.println("BMP180 init success");
else
{
Serial.println("BMP180 init fail\n\n");
}
char status;
double T,P,p0,a;
pressure.startTemperature();
status = pressure.getTemperature(T);
if (status != 0)
{ status = pressure.getPressure(P,T);
if (status != 0)
{
// Print out the measurement:
Serial.print("absolute pressure: ");
Serial.print(P,2);
pressure_value=P;
}
}
return pressure_value;
}
void loop()
{ digitalWrite(13, HIGH);
tft.setCursor (15, 50); // Place the cursor
tft.println ( "START" ); // write our text on the LCD
tft.setCursor (140, 50); // Place the cursor
tft.println ( "PAUSE" ); // write our text on the LCD
tft.setCursor (90, 155); // Place the cursor
tft.println ( "STOP" ); // write our text on the LCD
tft.setCursor (50, 250); // Place the cursor
tft.println ( "SETTINGS" ); // write our text on the LCD
TSPoint p = ts.getPoint();
int16_t tempX = p.x;
p.x = 1023-p.y;
p.y = 1023-tempX;
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
// scale from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
if (p.y < 110 && p.x < 110) {
tft.fillRect(10, 10, 100, 100, GREEN);
tft.fillRect(130, 10, 100, 100, WHITE);
tft.fillRect(10, 120, 220, 90, WHITE);
tft.fillRect(10, 220, 220, 90, WHITE);
}
if (p.y < 110 && p.x > 120 && p.x <200) {
tft.fillRect(10, 10, 100, 100, WHITE);
tft.fillRect(130, 10, 100, 100, YELLOW);
tft.fillRect(10, 120, 220, 90, WHITE);
tft.fillRect(10, 220, 220, 90, WHITE);
}
if (p.y > 120 && p.y <220) {
tft.fillRect(10, 10, 100, 100, WHITE);
tft.fillRect(130, 10, 100, 100, WHITE);
tft.fillRect(10, 120, 220, 90, RED);
tft.fillRect(10, 220, 220, 90, WHITE);
}
if (p.y > 220 && p.y <310) {
tft.fillRect(10, 10, 100, 100, WHITE);
tft.fillRect(130, 10, 100, 100, WHITE);
tft.fillRect(10, 120, 220, 90, WHITE);
tft.fillRect(10, 220, 220, 90, BLUE);
}
Serial.print(" "); Serial.print(pressure_value);
Serial.println("\n");
}