LowPowerLab Forum

Hardware support => Moteino => Topic started by: raenrfm on September 16, 2017, 09:34:11 PM

Title: Does AM2315 Temperature & Humidity sensor work with Moteino? [solved]
Post by: raenrfm on September 16, 2017, 09:34:11 PM
I've been trying to get the moteino to recognize this AM2315 for hours with no luck.  Can anyone help me figure this out?  I'm using the version 2 of the AM2315 library someone posted on the Adafruit forum.  Will not recognize the sensor with either 3.3v or 5v and pullups/no pullups. 
Title: Re: Does the AM2315 Temperature and Humidity sensor work with Moteino?
Post by: raenrfm on September 17, 2017, 12:27:35 AM
I tried my adafruit bme280 and that also doesn't work.  i2cscanner sketch doesn't find any of my i2c sensors.  Do I have a bad board?  It is equipped with the RFM69HCW transciever.
Title: Re: Does the AM2315 Temperature and Humidity sensor work with Moteino?
Post by: TomWS on September 17, 2017, 08:02:27 AM
Quote from: raenrfm on September 17, 2017, 12:27:35 AM
I tried my adafruit bme280 and that also doesn't work.  i2cscanner sketch doesn't find any of my i2c sensors.  Do I have a bad board?  It is equipped with the RFM69HCW transciever.
We need more details.  Which 'Moteino' board are you using?  What pins are you connected to?  What libraries are you using?  A sketch might help, depending on the cause.

Net:  The Moteino boards work fine with I2C devices. 

Tom
Title: Re: Does the AM2315 Temperature and Humidity sensor work with Moteino?
Post by: raenrfm on September 17, 2017, 11:39:44 AM
I'm using the R6 Moteino connected to a FTDI adapter with an RFM69HCW tranciever and the flash chip installed.  I'm powering the Adafruit BME280 from the 3.3 pin on the Moteino and the Moteino is getting power from the FTDI adapter which is set to 5 volt supply and 3.3V logic (default setting, but not sure if this is my issue).  I didn't have 4.7k resistors but made them with a 3.3 and a 1.2 in series for both the SDL and SCK (A4 and A5) pins.  Here is the simple i2cScanner program I'm running because it's simple and I wanted to troubleshoot what's going on:

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  //digitalWrite(A4, INPUT_PULLUP);
  //digitalWrite(A5, INPUT_PULLUP);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }   
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}
Title: Re: Does the AM2315 Temperature and Humidity sensor work with Moteino?
Post by: TomWS on September 17, 2017, 02:38:37 PM
I can't say I've ever done back to back begin/end transmissons:
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

without an intervening write.  Do you know that this sequence works?  The Arduino reference says nothing is transmitted until the endtransmission call and then it sends what is written.

Assuming you know this sequence works then the only thing I can think of (short of a broken part) is that the wrong board is selected in the Boards setting in the IDE.  UNO setting should work for this test if the Moteino board package installation is broken.

Tom
Title: Re: Does the AM2315 Temperature and Humidity sensor work with Moteino?
Post by: TomWS on September 17, 2017, 02:51:04 PM
Another thing to look at is what is the state of the SDO and CSB pins on the BME280?  According to the datasheet these need to be set to specific values for the I2C interface to operate.  See snapshot below...

Tom

Title: Re: Does the AM2315 Temperature and Humidity sensor work with Moteino?
Post by: raenrfm on September 17, 2017, 02:56:29 PM
Ok, so I'm an idiot....I had the SDA pin of the Moteino going to the SDO pin and not the SDI pin!  Doh!  This code is now finding the BME280 and printing out it's address 0x77.  I'm thinking my AM2315 will need a bidrectional shifter because in that case I did have the correct wires from it going to the SDA and SCL pins on the Moteino, so that must be the explanation.  I have some 5LN01SP mostfets, can I build a level shifter for the the I2C pins with those?
Title: Re: Does the AM2315 Temperature and Humidity sensor work with Moteino?
Post by: TomWS on September 17, 2017, 05:48:52 PM
Quote from: raenrfm on September 17, 2017, 02:56:29 PM
I have some 5LN01SP mostfets, can I build a level shifter for the the I2C pins with those?
You should be able to, the Vgsth is low enough and being N channel, the diode will block the 5V side and pulldown the 3.3V side.

Glad you got it figured out...  Those 'vowels' (SD'O' vs SD'I' are a major nuisance!   ;)

Tom