hi guys, im new arduino forum, ive been working on project , im stuck @ point cant use both modules -.-"
if want use tft works fine code, when add code bmp180 pressure sensor tft gives blank white screen, im problem coding, since first attempt @ using these 2 modules, , first attempt @ using scl , sda, dont know should now, spent hrs searching net im still not able fine solution.
im attaching code post , can verify , tell me wrong in it?
if want use tft works fine code, when add code bmp180 pressure sensor tft gives blank white screen, im problem coding, since first attempt @ using these 2 modules, , first attempt @ using scl , sda, dont know should now, spent hrs searching net im still not able fine solution.
im attaching code post , can verify , tell me wrong in it?
code: [select]
#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 breakout board only, use these 8 data lines lcd:
// arduino uno, duemilanove, diecimila, etc.:
// d0 connects digital pin 8 (notice these are
// d1 connects digital pin 9 not in order!)
// d2 connects digital pin 2
// d3 connects digital pin 3
// d4 connects digital pin 4
// d5 connects digital pin 5
// d6 connects digital pin 6
// d7 connects digital pin 7
// arduino mega, use digital pins 22 through 29
// (on 2-row header @ end of board).
// d0 connects digital pin 22
// d1 connects digital pin 23
// d2 connects digital pin 24
// d3 connects digital pin 25
// d4 connects digital pin 26
// d5 connects digital pin 27
// d6 connects digital pin 28
// d7 connects digital pin 29
#define yp a1 // must analog pin, use "an" notation!
#define xm a2 // must analog pin, use "an" notation!
#define ym 7 // can digital pin
#define xp 6 // can digital pin
#define ts_minx 150
#define ts_miny 120
#define ts_maxx 920
#define ts_maxy 940
// better pressure precision, need know resistance
// between x+ , x- use multimeter read it
// 1 we're using, 300 ohms across 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 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); // define text size.
tft.settextcolor (black); // define text color
tft.setrotation (90); // set 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 > 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 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 cursor
tft.println ( "start" ); // write our text on lcd
tft.setcursor (140, 50); // place cursor
tft.println ( "pause" ); // write our text on lcd
tft.setcursor (90, 155); // place cursor
tft.println ( "stop" ); // write our text on lcd
tft.setcursor (50, 250); // place cursor
tft.println ( "settings" ); // write our text on 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 0->1023 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");
}
hi nightmare,
in 'loop' call "getpressure" - needs in loop !
good luck
in 'loop' call "getpressure" - needs in loop !
good luck
Arduino Forum > Using Arduino > Programming Questions > How to use 2.4inch TFT LCD ILI9341 along with BMP180 pressure sensor
arduino
Comments
Post a Comment