Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Embedded programming

This thread is locked; no one can reply to it. rss feed Print
Embedded programming
Ariesnl
Member #2,902
November 2002
avatar

Does any of you smart guys have any experience with the AM2315 Temperature & humidity sensor from Asair ? I'm trying to get the thing to work, but the manual is in a variation of the english language even a frenchman living in japan couldn't come up with :-/

Any advise is welcome ;)

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Elias
Member #358
May 2000

Does it use I2C? I've been playing with various sensors the past year or so and if they have I2C it always makes me happy because it's easy - just connect the four wires and read from its address. All Arduinos and Raspberries should be able to. If it doesn't have builtin pullup resistors you may need to connect your data lines to the voltage line with some 10k or so resistors, my understanding is those resistors are to set the data signal to high whenever there is no other signal.

--
"Either help out or stop whining" - Evert

Peter Hull
Member #1,136
March 2001

I haven't used it myself but Adafruit have an Arduino library for it (on Github) - you could probably use that in conjunction with the datasheet to figure out how it works

Ariesnl
Member #2,902
November 2002
avatar

It is I2c but the protocol is unclear to me, and the manual/datasheet is crap.

this is an example in I think Arduino But I'm using STM32 cube

[code]
bool AM2315::read( )
{

char data_write[5];
char data_read[10];
int i =0;
for(i=0; i<8; i++)
data_read[i]=0;

// Wake up the sensor
// write single byte twice to wake up
// single write is not enough
data_write[0] = 0x00;
i2c.write(AM2315_ADDR,data_write,1,0);
i2c.write(AM2315_ADDR,data_write,1,0);

// Read temperature and humidity register
// send request to AM2315
data_write[0] = AM2315_REG_READ;
data_write[1] = 0x00; // read from adr 0x00
data_write[2] = 0x04; // read 4 bytes
i2c.write(AM2315_ADDR, data_write, 3, 0); // with stop

// wait 2ms before we start to read reg
wait_ms(2);

i2c.read(AM2315_ADDR, data_read, 8, 1);

if (data_read[0] != AM2315_REG_READ)
return false;
// check numbers of bytes read
if (data_read[1] != 4)
return false;

humidity = data_read[2];
humidity *= 256;
humidity += data_read[3];
humidity /= 10;

celsius = data_read[4] & 0x7F;
celsius *= 256;
celsius += data_read[5];
celsius /= 10;

if (data_read[4] >> 7)
celsius = -(celsius);

return true;
}

[/code]

I tried to convert it to STM32 code.. but no succes.. I only get a bunch of zero's together with an ending byte sequence ::)

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Go to: