sparkfun / SparkFun_HTU21D_Breakout_Arduino_Library

HTU21D Breakout Arduino Library
Other
31 stars 23 forks source link

Using different pin? #7

Closed cuci90 closed 6 years ago

cuci90 commented 6 years ago

Hi,

is it possible to use other pins then 4 & 5 on the arduino. You are mentioning something on the "SparkFunHTU21D.cpp" --> //Grab which port the user wants us to use

But I cannot figure out how I can change this. Can you help? Thanks a lot!

tdkryger commented 6 years ago

In SparkFunHTU21D.cpp you need to remove this line: _i2cPort->begin(); You then need to add Wire.begin(sda, scl); to your setup() before calling begin on the sensor

nseidle commented 6 years ago

@tdkryger - I have not seen .begin(sda, scl). Do you have a link to docs? I have seen .begin(address) for making a device a slave on the bus: https://www.arduino.cc/en/Reference/WireBegin

@cuci90 90 - Yes you can. You can pass the HTU21D .begin() function a Wire stream. It would look something like this (but I haven't tested this code). I am assuming you will be using a device with multiple I2C ports like a Teensy or SAMD21.

#include <Wire.h>
#include "SparkFun_HTU21D_Breakout_Arduino_Library.h"

HTU21D myHumidity;

setup() {
    Wire1.begin();
    myHumidity.begin(Wire1); //Pass the Wire1 stream to the library

    ....

Now all myHumidity function calls will use the Wire1 bus.

Another option that I have not tried is to use software I2C such as softwire but there are about a dozen such software I2C libraries for Arduino. You would do the same thing. Create a softwire object and pass the stream to the HTU21D library. I haven't tested this yet but it should work if the library has define its stream elements correctly.