interfacing AM2302 with tft display problem

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jsadler3
 
Posts: 4
Joined: Sun Jun 23, 2013 7:50 pm

interfacing AM2302 with tft display problem

Post by jsadler3 »

Main Issue: text in tft display disappearing when including another section of code...and pulling out hair.

Devices: Arduino Mega2560 rev3
Adafruit AM2302 --> http://www.adafruit.com/products/393
Adafruit 2.8" 18-bit color TFT LCD with touchscreen breakout board (ILI9325) --> http://www.adafruit.com
/products/335 (looks to be discontinued)

IDE: Tried on both 1.0.3 and 1.0.5 arduino

Libraries: Adafruit TFTLCD --> https://github.com/adafruit/TFTLCD-Library
Adafruit GFX --> https://github.com/adafruit/Adafruit-GFX-Library
created my own AM2302...attached for ref.

Background:

So attempted to create a AM2302 class off existing code available on web. Gave me opportunity to create first class and help keep main sketch file from being cluttered with code. Attached is AM2302 library code for ref.

I have verified that I can obtain AM2302 data in sketch. So that portion of code stands on its own.
I have verified that I can obtain displayed text "hello world" to ftf display. So that portion of code stands on its own.
However problem arises when both portions of code are in same main sketch.
When I suppress takeMeasurements() code my display works correctly and shows "hello world" on green background.
When I unsuppress takeMeasurements() code my display has green background but no text??

Troubling part to me is that the display portion of code does not interface with AM2302 sensor portion of code so if they work separately what gives? Some timing issue?

I know long wined but would be appreciative for any help or guidance,

Thanks,

Shown below is code from main sketch

Code: Select all

#include <AM2302.h>
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>

// 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

/**************/
/*****Pins*****/
/**************/

// AM2302 Sensor
const byte AM2302pin = 50;

// TFTLCD Display
#define LCD_CS A3 // Chip Select 
#define LCD_CD A2 // Command / Data 
#define LCD_WR A1 // LCD Write 
#define LCD_RD A0  // LCD Read
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

/**************************/
/*****Var Declarations*****/
/**************************/
static float HumdSensor1 = 0; 
static float TempSensor1 = 0;

/****************************/
/*****Funct Declarations*****/
/****************************/
void takeMeasurements();
void updateDisplay();

/*****************************/
/*****Instantiate Objects*****/
/*****************************/
AM2302 AM2302sensor1(AM2302pin);
Adafruit_TFTLCD display(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

/***********************/
/*****Setup Routine*****/
/***********************/
void setup(){
  Serial.begin(9600);
  display.reset();
  int identifier = display.readID();
  display.begin(identifier); 
  delay(3000);
}

void loop(){
  takeMeasurements();
  updateDisplay(); 
  delay(5000);
}

void takeMeasurements(){
    AM2302sensor1.takeHumdAndTempReading();    
    Serial.println(AM2302sensor1.getHumd());
    Serial.println(AM2302sensor1.getTemp());
}

void updateDisplay(){
  display.fillScreen(GREEN);
  display.setTextSize(3);
  display.setCursor(0,0);
  display.setTextColor(WHITE);
  display.print("Hello World!");
}
Attachments
AM2302.cpp
(3.92 KiB) Downloaded 108 times
AM2302.h
(312 Bytes) Downloaded 127 times
Last edited by Franklin97355 on Sat Jul 05, 2014 4:23 pm, edited 1 time in total.
Reason: Added code tags

User avatar
Franklin97355
 
Posts: 23939
Joined: Mon Apr 21, 2008 2:33 pm

Re: interfacing AM2302 with tft display problem

Post by Franklin97355 »

If you are using SPI for your display you should not use pin 50 (MISO) for the AM2302. Try a different pin.

jsadler3
 
Posts: 4
Joined: Sun Jun 23, 2013 7:50 pm

Re: interfacing AM2302 with tft display problem

Post by jsadler3 »

update:
Was directed to RobTillaart library on Github. Used the code and appears to work with display. Something must be a little off with my library code for AM2302.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”