I2C on Spark core (noob question)

Hello!

I’m new to Spark Core, just started it using last week. Ok to the question, I’m trying to use the i2c pins of the Spark core. I did the set up with Arduino and it was perfect. I’ve been trying to replicate it in the Spark core but I failed, here’s the link to the exact set up I did in Arduino.

Link:
http://www.dfrobot.com/wiki/index.php/SI7021_Temperature_and_humidity_sensor_SKU:TOY0054

Any help will be great !

Hi @azmansalleh

There are just a few difference between Arduino and Spark for i2c:

  • Spark always requires pull-up resistors on the clock and data lines. Lots of values will work but 4.7k ohm is ideal if you have it.

  • Spark has built-in hardware-based i2c on pins D0 and D1 for data and clock so you should always use those pins.

  • The wire library for i2c is built-in on Spark, so you don’t need a #include for it.

1 Like

Hey @bko for the quick reply

So basically all I need to do is
-do a pull up on DO and D1 pins for the data and clock?

  • reuse my Arduino codes on the Spark IDE as you said it supports the wire library

and that should be all?

Thanks! :smiley:

Yes! Try that and if you are still having troubles, come back here and we will try to help more.

Hey @bko

How do I do a pull-up on the D0 and D1

I’m aware you have to change the pinmode of D1 and D0 to INPUT_PULLUP for the code
Circuit wise do I have to do anything else?

You don’t need to bother with the pinMode - the Wire class will do that for you.
For pull-up you’d have to add your own descrete resistors between 3.3V and your pins.
e.g. have a look here

2 Likes

Hey @bko and @ScruffR, thanks for the help. I managed to get readings from my temperature/humidity sensor, now I’m on to build my WIFI garden. Thanks! :smile:

2 Likes

I have several HIH6130 breakout boards from Sparkfun that work fine with an Arduino Uno and 3.3v RFduino. I’ve blown a few days trying to get them to work with Spark Core and I’m not having any luck.

I see that there’s a HIH61xx library already contributed to the Web IDE and if I try the demo project there I just get Wire.endTransmission returning 4, the same as my own library.

As suggested above I’ve put 4.7k pull-ups from the 3.3v pin to D0 and D1. I’ve tried all sorts of variations and I just cannot get it to work. What else could I be missing? My understanding is that updating via Web IDE ensures the latest firmware, no need to do any other restore or updates?

Your return value 4 seems to indicate a timeout.

Could you please check your wiring against the docs

I2C communication pins are multiplexed with the standard GPIO pins D0 and D1.
D0: SDA (Serial Data Line)
D1: SCL (Serial Clock)

And you are using the example code as is?

When I look at the board I’d suspect that it already provides 2k2 pullup resistors for the I2C lines, so you could leave them out.

I appreciate the assistance!

Unfortunately I’ve already tried swapping the SDA,SCL pins and adding and removing pull-ups.

Yes, I’ve tried the unedited demo code for the HIH61XX Spark Core library as well, no luck.

Sorry if I’m asking stupid questions, but how do you power the Core and the module?
The example does power the module via the D3 pin.

If you’re powering the module via 5V Vin pin, it might be that the Core’s I2C HIGH signal of 3.3V is not interpreted correctly by the sensor.
This might be completely wrong, but at the moment I’ve no better idea.

But I know a guy who seems to have waaaay more insight into I2C than me - @pra, what are we missing?

@ScruffR and @chasc, the Sparkfun boards DO have 2.2K pull-ups so no others are necessary. However, using several sensors will create an issue since they all have the same address and, as the author of the IDE library points out in his readme file:

If you have multiple devices connected to the I2C bus, remember that this device screws up the bus when it is not powered. One solution is to keep the device powered all the time. Another possible solution is to add an analog switch to physically disconnect the GND line or the SDA line to the device.

So I would suggest you use a single sensor to start with. Also, you may also want to test with Sparkfun’s Arduino code which will need very minor modifications to run on the Spark (let me know if you need help with that). If a single sensor and the code work for you, you can go from there. :smile:

@peekay123, I never understood that @chasc is actually using more than one sensor. I just understood he’s got several in his pocket and only uses one a time.
Sure, that would have been a clever question to ask first too :blush:

1 Like

All helpful suggestions but again unfortunately it doesn’t help. I do have multiple devices but I’m not currently trying to use more than one. I have tried powering it via the D3 pin (as per the demo sketch) and continuously from the 3.3v pin. I’ve customized the I2C addresses but have verified with an RFduino that I’m using the correct address. That Sparkfun codebase is what my own library is based off of and it doesn’t work either.

Is there any utility in refreshing the device via DFU or is that futile for this type of issue?

I don’t have a logic analyzer but I do have a multimeter. Is there anything else I can do to troubleshoot?

Let me add one last little bit of info: I had trouble with the HIH3160 in the past on RFduino’s I2C library too. The reason was that HIH3160 is triggered to initiate measurement by an empty transmission, but the I2C library was simply skipping further logic if the output buffer was empty at the time endTransmission() is called. I fixed it there by sending one random byte, which got around the issue.

I didn’t originally suspect I2C library issues because someone else had posted an HIH61xx library, making me suspect it was working fine. However, I’m out of other explanations so I thought I’d put it out there. Perhaps the slightly unusual I2C protocol of the HIH6130 is conflicting with the I2C library here?

And have you tried the same workaroung already, too?

You could also try to get in contact with GeertWille via his github, who has published this lib for the Web IDE.

According to the data sheet, the device has a VCC from 2.3V - 5.5V so I recommend power from the Spark’s 3.3V pin, or any Spark pin set to OUTPUT, HIGH , but not VIN. I2C pins are supposed to be connected Open Drain (i,e, pulled to VCC via resistors and the master and/or device pulls them to GND as required. No master or device pin should drive any voltage onto these lines).

as @ScruffR has pointed out, a 4 returned by Wire.endTransmission() is a Timeout, meaning either the SDA and SCL lines are not connected to the device properly, no VCC (trying connecting to Spark 3.3V pin rather than GPIO pin for now) or the address being send is incorrect (make sure you are using address 0x27). These are pretty much the only reason you will get this timeout, so it has to be one of these.

1 Like

Hi @chasc

While you are debugging this sensor you should remove everything else on the i2c bus and just deal with this sensor–it will simplify things a lot.

Yes, I tried my own library with and without that fix. I looked at GeertWille’s one for Spark Core and it doesn’t have it. I just opened an issue on his repo yesterday so perhaps he will have some additional info.

I’m testing with just a breadboard, the Spark Core, one sensor and some wires.

1 Like