A friend asked me to help him connect the HT21D temperature and humidity sensor to a TI board.
He's using the TM4C123 board while I'm using the older LM4F Launchpad.
The first thing to know is that neither of the boards have pullups adequate for I2C. You need to add a 4.7k resistor from SDA to VCC and another one from SCK to VCC. I've tested it with 1k resistors and it works with those as well.
The second thing is that the Stellaris boards have several I2C modules, so you need to select one. Even worse is the fact that the Energia library by default chooses the Boosterpack:
So you first need to go into this folder "\hardware\lm4f\libraries\Adafruit_HTU21DF_Library-master\" and edit two files as explained below.
Adafruit_HTU21DF.cpp
From:
Adafruit_HTU21DF.h
From:
In the example file
From:
The Wire::begin() function does not need to be called since the setModule() function will call it. But if you want to use the device as a slave, you need to call begin(slaveAddress).
He's using the TM4C123 board while I'm using the older LM4F Launchpad.
The first thing to know is that neither of the boards have pullups adequate for I2C. You need to add a 4.7k resistor from SDA to VCC and another one from SCK to VCC. I've tested it with 1k resistors and it works with those as well.
The second thing is that the Stellaris boards have several I2C modules, so you need to select one. Even worse is the fact that the Energia library by default chooses the Boosterpack:
if(i2cModule == NOT_ACTIVE) {
i2cModule = BOOST_PACK_WIRE;
}
So you first need to go into this folder "\hardware\lm4f\libraries\Adafruit_HTU21DF_Library-master\" and edit two files as explained below.
Adafruit_HTU21DF.cpp
From:
boolean Adafruit_HTU21DF::begin(void) {To:
Wire.begin();
reset();
boolean Adafruit_HTU21DF::begin(int moduleNo) {
Wire.setModule(moduleNo);
reset();
From:
boolean begin(void);To:
boolean begin(int moduleNo);
In the example file
From:
void setup() {To:
Serial.begin(9600);
Serial.println("HTU21D-F test");
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
}
}
void setup() {Instead of begin(0) you can choose whichever I2C module you'd like, the LM4F has 4 of them.
Serial.begin(9600);
Serial.println("HTU21D-F test");
if (!htu.begin(0)) {
Serial.println("Couldn't find sensor!");
while (1);
}
}
The Wire::begin() function does not need to be called since the setModule() function will call it. But if you want to use the device as a slave, you need to call begin(slaveAddress).
Comments
Post a Comment
Due to spammers, comments sometimes will go into a moderation queue. Apologies to real users.