Go Down

Topic: I2C problem with Adafruit 7 segment backpack (Read 2551 times) previous topic - next topic

Mark_Hardin

Hi,
I am a complete beginner with programming.

I have a UNO 3 and I am trying to connect a DHT 11 and a 4 digit seven segment display.  The display is from Adafruit and uses the I2C protocal.  I can display the temperature and humidity on the serial monitor using Serial.print just fine.  The temperature reported is fairly consistant and changes when I hold the DHT 11.  I can run the Adafruit example in the library with out problems.

The problem occures when I try use the seven segment display to show the temperature.  With the 7-segment display backpack, the DHT 11 now changes temperature with each reading.  And the temperature changes widley.  It will read 85 degrees and the next reading two seconds later is 66 degrees.

Remove the 7-segment display or commenting out the matrix.print and matrix.writeDisplay and the DHT 11 will again give fairly consistent results.

I don't think I am running out of SRAM.  Using the function to look for free space in SRAM I get over 1000 bytes of free SRAM.

Any help trouble shooting this is greatly appreciated.


Code: [Select]


/*

From the DHT 11 example:

Board           int.0   int.1   int.2   int.3   int.4   int.5
Uno, Ethernet   2   3
Mega2560   2   3   21   20   19   18
Leonardo   3   2   0   1
Due           (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)

------------------------------------------------------------------------------------------------

From the Adafruit example:

This is a library for our I2C LED Backpacks

Designed specifically to work with the Adafruit LED 7-Segment backpacks
----> http://www.adafruit.com/products/881
----> http://www.adafruit.com/products/880
----> http://www.adafruit.com/products/879
----> http://www.adafruit.com/products/878

These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries. 
BSD license, all text above must be included in any redistribution

___________________________________________________________________________

Circuit:

DHT 11

DHT 11 Data pin to D2
DHT 11 Data pint a 10K pull up 10K resistor

The Adafruit back pack.

SDA to pin A4
SCL to pin A5

The backpack has 1K pull up resistors.

*/

#include <idDHT11.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

Adafruit_7segment matrix1 = Adafruit_7segment();
//Adafruit_7segment matrix2 = Adafruit_7segment();
//Adafruit_7segment matrix3 = Adafruit_7segment();


#if defined(ARDUINO) && ARDUINO >= 100
#define I2C_WRITE Wire.write
#define I2C_READ Wire.read
#else
#define I2C_WRITE Wire.send
#define I2C_READ Wire.receive
#endif


int idDHT11pin = 2; //Digital pin for comunications
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)

//declaration
void dht11_wrapper(); // must be declared before the lib initialization

// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);


void setup()
{
  Serial.begin(9600);
  Wire.begin();
  matrix1.begin(0x70);
  // matrix2.begin(0x72);
  // matrix3.begin(0x75);
  matrix1.clear();
  // matrix2.clear();
  // matrix3.clear();
  matrix1.writeDisplay();
  //  matrix2.writeDisplay();
  // matrix3.writeDisplay();
  Serial.println("idDHT11 Example program");
  Serial.print("LIB version: ");
  Serial.println(IDDHT11LIB_VERSION);
  Serial.println("---------------");
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapper() {
  DHT11.isrCallback();
}

void loop()
{
  Serial.print("\nRetrieving information from sensor: ");
  Serial.print("Read sensor: ");
  //delay(100);
  DHT11.acquire();
  while (DHT11.acquiring());

  int result = DHT11.getStatus();
  switch (result)
  {
  case IDDHTLIB_OK:
    Serial.println("OK");
    break;
  case IDDHTLIB_ERROR_CHECKSUM:
    Serial.println("Error\n\r\tChecksum error");
    break;
  case IDDHTLIB_ERROR_ISR_TIMEOUT:
    Serial.println("Error\n\r\tISR Time out error");
    break;
  case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
    Serial.println("Error\n\r\tResponse time out error");
    break;
  case IDDHTLIB_ERROR_DATA_TIMEOUT:
    Serial.println("Error\n\r\tData time out error");
    break;
  case IDDHTLIB_ERROR_ACQUIRING:
    Serial.println("Error\n\r\tAcquiring");
    break;
  case IDDHTLIB_ERROR_DELTA:
    Serial.println("Error\n\r\tDelta time to small");
    break;
  case IDDHTLIB_ERROR_NOTSTARTED:
    Serial.println("Error\n\r\tNot started");
    break;
  default:
    Serial.println("Unknown error");
    break;
  }

  /*
  Serial.print(F("Humidity (%): "));
   Serial.println(DHT11.getHumidity(), 2);
   
   Serial.print(F("Temperature (oC): "));
   Serial.println(DHT11.getCelsius(), 2);
   */

  Serial.print(F("Temperature (oF): "));
  Serial.println(DHT11.getFahrenheit(), 2);
  /*
  Serial.print(F("Temperature (K): "));
   Serial.println(DHT11.getKelvin(), 2);
   
   Serial.print(F("Dew Point (oC): "));
   Serial.println(DHT11.getDewPoint());
   
   Serial.print(F("Dew Point Slow (oC): "));
   Serial.println(DHT11.getDewPointSlow());
   */

  Serial.print(F("SRAM free space: "));
  Serial.println(freeRam());

  // matrix1.print(DHT11.getFahrenheit(), 2);
  // matrix1.writeDisplay();
  delay(2000);

  Serial.print(F("Second SRAM: "));
  Serial.println(freeRam());


end of main loop


// functions

// SRAM measurement
int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}



pylon

The 1k pull-ups are out-of-spec for a 5V I2C. Are you sure Adafruit placed 1k resistors on the board?

My guess is, your problems arise from an unstable power supply. How do you power your project? Just from the USB? Do you have an external power supply for the board? If the voltage drops because of that your sensor may return more or less random values.

Caltoa

I agree with pylon. My feeling tells me it is 80% chance a power problem, no wait.. make that 90%.

Go Up