Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: I2C Sensor + Teensy 2.0. Bad Data

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Location
    Johnson City, TN
    Posts
    11

    I2C Sensor + Teensy 2.0. Bad Data

    Hi,
    Just tried using my new AM2315 Humidity/Temperature sensor with a Teensy 2.0, and I am getting bad data.
    This is an I2C device available from Adafruit Industries:
    http://www.adafruit.com/products/1293

    Link to the library:
    https://github.com/adafruit/Adafruit_AM2315

    The code is an example included with the AM2315 Library:
    Code:
        #include <Wire.h>
        #include <Adafruit_AM2315.h>
    
        /***************************************************
          This is an example for the AM2315 Humidity + Temp sensor
    
          Designed specifically to work with the Adafruit BMP085 Breakout
          ----> https://www.adafruit.com/products/1293
    
          These displays use I2C to communicate, 2 pins are required to 
          interface
          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
        ****************************************************/
    
        // Connect RED of the AM2315 sensor to 5.0V
        // Connect BLACK to Ground
        // Connect WHITE to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
        // Connect YELLOW to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
    
        Adafruit_AM2315 am2315;
    
        void setup() {
          Serial.begin(9600);
          Serial.println("AM2315 Test!");
    
          if (! am2315.begin()) {
             Serial.println("Sensor not found, check wiring & pullups!");
             while (1);
          }
        }
    
        void loop() {
          Serial.print("Hum: "); Serial.println(am2315.readHumidity());
          Serial.print("Temp: "); Serial.println(am2315.readTemperature());
    
          delay(1000);
        }
    Everything is wired the normal way, using a pair of 10K pullups to Vcc. I have made many successful gadgets using I2C in the past.

    When I first start the system, the first 11 readings were normal at 24degC and 55.4%rh (close to a DHT-22 I also have running on a different system), but then the numbers went all weird- the Temperature value stuck at 3331.80 and the Humidity at 22.00 with minor variation (+/- 0.02% or so).

    I tried disconnecting the USB, waiting 15 seconds, then plugged it in. Same thing.

    The software is an un-modified (except for deleting an extraneous "}" at the end) example sketch that came with the Adafruit AM2315 library.

    I ran exactly the same code for days with an Arduino Uno, with no difficulty.

    I am currently using the Teensyduino 1.02 IDE.

    Any clues will be most appreciated!

    I posted this topic on the Adafruit board as well:
    http://forums.adafruit.com/viewtopic.php?f=19&t=40118
    but have not received much helpful information yet.

    Thank you!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,759
    That library code is so very simple, it really ought to work.

    Inside the library, there is a commented line which would print the raw data from the sensor. It's in this part:

    Code:
      Wire.requestFrom(AM2315_I2CADDR, 8);
      for (uint8_t i=0; i<8; i++) {
        reply[i] = Wire.read();
        //Serial.println(reply[i], HEX);
      }
    Could you uncomment that line and give it another try? Perhaps seeing if (and how) the raw data changes might help in understanding the problem?

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Location
    Johnson City, TN
    Posts
    11
    Quote Originally Posted by PaulStoffregen View Post
    That library code is so very simple, it really ought to work.

    Inside the library, there is a commented line which would print the raw data from the sensor. It's in this part:

    Code:
      Wire.requestFrom(AM2315_I2CADDR, 8);
      for (uint8_t i=0; i<8; i++) {
        reply[i] = Wire.read();
        //Serial.println(reply[i], HEX);
      }
    Could you uncomment that line and give it another try? Perhaps seeing if (and how) the raw data changes might help in understanding the problem?
    Sure, I'd be happy to, but won't have an opportunity for at least two weeks. I guess the thing that is bothering me so much is that the Arduino UNO seemed to work so well. What do you suppose the variables could be when comparing the two platforms?

    Thanks for your quick reply, BTW.

  4. #4
    Junior Member
    Join Date
    Jan 2013
    Location
    Johnson City, TN
    Posts
    11
    Of course, can always be a wonky sensor, as well- It's worth noting that I never had a lick of trouble with Teensy 2.0 I2C communications until now...

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,759
    This really should work. The I2C hardware on Teensy 2.0 is pretty much identical to Arduino Uno.

    Without more info or the actual hardware to test, I really can't offer any useful opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •