I2C having issue with the new Photon-2

Hi Folks,

The I2C doesn't seem to function with the Photon-2. However, the same code runs smoothly on the older Photon. Does anyone have insights on this? For reference, I'm utilizing the BME680 temperature sensor.

Hi @italex -

Hhmm... I have done several tutorials recently using I2C sensors and the Photon 2, there should be no problem. Can you send more details? Wiring diagram or some code maybe?

Regards, Friedl.

What version of Device OS? You should use the latest (currently 5.5.0) because there are some issues with earlier versions:

Description Tags Pull Request Version
Avoid glitch on I2C pins when reconfiguring I2C peripheral rtl872x 2682 v5.5.0
Fix i2c hal deadlock gen3 p2 2572 v5.2.0
Fix incorrect I2C read timeout rtl872x 2671 v5.5.0
hal: implement i2c sleep and fix the reset APIs rtl872x 2497 v5.0.0
hal: Fixes I2C failing to read/write from/to slave device rtl872x 2634 v5.3.1
Fix logic level overshoot on SPI, I2C, PWM pins rtl872x 2680 v5.5.0

Do you change the speed of I2C? Only 100 kHz and 400 kHz are supported at this time, custom speeds do not currently work and will result in 400 kHz.

What pull-ups do you have on SDA and SDL? The P2/Photon 2 (RTL872x) have an internal pull-up of 22K which is not usually sufficient and requires an external pull-up as well. The Argon and Boron (nRF52) have an internal pull-up of 13K which is also too large, but close enough that it often works. You should try to get to 2.2K to 4.7K.

2 Likes

Hi rickkas7,

I'm using the Adafruit BME680 sensor which already has pull-up resistors. Despite adding two 4.7K resistors for extra assurance, it didn't help. I've updated the Photon-2 to version V5.5.0. Interestingly, the BME operates well with an older Photon and the Argon, same code. I did not change the I2C speed.

Here's the issue:

When I attach the SDA wire to the Photon-2 pin D0:

The RGB LED turns off.
The blue LED near the USB remains lit.
The Photon-2 stops functioning.
If I connect the BME before powering the Photon-2: The RGB LED doesn't light up at all.

I am trying to develop a home thermostat for a two stages heater and A/C compressor. Like I said, the code works fine with the older Photon and Argon.

Thank you.

Hi Friedl,

I'm working on developing a home thermostat as I'm dissatisfied with commercial options like the Nest thermostat. But the Photon-2 is not cooperating with me. Hopefully we will find a solution why the I2C is not working in my case. Thank you.

Hi @italex -

This behaviour seems very strange to me indeed. I cannot see why the I2C connection should cause the system LED to shut down. In my experience that will happen only due to a short circuit or if purposely done in firmware.

Are you using a module for the BME sensor or custom PCB? Are there any other sensors connected? Have you tried running an I2C scanner only to see whether the behaviour is the same and whether the device is actually been detected?

void setup() {
    
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             
  Serial.println("I2C Scanner");

//    pinMode (D4, OUTPUT);
//    digitalWrite(D4, LOW);
    
}
 
 
void loop() {
    
  byte error, address;
  int nDevices;
 
  Particle.publish("Scanning...");
  delay(1000);
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Particle.publish("I2C device found at address 0x" + String(address,HEX), PRIVATE);
      nDevices++;
    }
    
    else if (error==4)
    {
      Particle.publish("Unknown error at address 0x");
        if (address<16)
        Serial.print("0");
        Particle.publish(String(address,HEX), PRIVATE);
    }    
  }
  
  if (nDevices == 0)
    Particle.publish("No I2C devices found");
  else
    Particle.publish("done");
 
  delay(20000);           // wait 5 seconds for next scan
} 

Please send me the wiring diagram if you do not mind.

Regards,
Friedl.

2 Likes

Hi Friedl,

I found the solution. Initially, I mentioned using two 4.7K resistors. Upon rechecking them, I discovered that one was actually 47K. This mismatch was the issue. After correcting it, the Photon-2 now works perfectly. Thanks to your post, I was prompted to investigate further. Thank you.

2 Likes

Hi @italex

Glad you managed to resolve the issue. Some thoughts, my default pull-up values for I2C is 10k unless otherwise stipulated by the sensor manufacturer.

Regards Friedl.

Hi Friedl,

I'm considering trying 10K. I initially used 4.7K based on Rickkas7's recommendation. Below is a screenshot of the thermostat user interface. I'm currently using Blynk, and the screenshot displays heater stage 1.

The target temperature is set at 73 degrees. There's a "dead zone" of 2 degrees, meaning the thermostat won't react to temperature fluctuations within this range. I can adjust this range to any value, but I find 2 degrees to be optimal as I don't notice significant temperature changes. This concept also applies to the A/C.
The gauges indicate current temperature and humidity.

2 Likes

Hi @italex -

You can go with his recommendation, he is beyond smart and know just about everything :nerd_face: I started out using 10k and it has served me well over te years. Having said that, I have worked with sensors requiring as los as 1K2.

You project looks great, well done!! Love the implementation of the deadline. Also use it in level sensors to avoid hysteresis or values fluctuating too unnecessarily.

I am curious to know, are you using the Blynk library or sending data via webhooks?

Regards,
Friedl

Hi Friedl,

I'm using the Blynk library, and it's performing excellently. For two-stage thermostats, there are two methods to transition to the second stage: time-based or temperature-based. Personally, I choose between Stage 1 and Stage 2 manually.

Here's how commercial thermostats typically function with a time reference:

If the target temperature isn't achieved within 20 minutes, it switches to Stage 2. There's no dead zone in this approach. However, the Nest thermostat has a one-degree dead zone, which isn't adjustable.

Regards,
itAlex

1 Like

Hi Alex -

I used this on the Photons as well... for GSM however Blynk seems to recommend using the API. This also works really well but is a bit more cumbersome to get going. Especially for sending data from Blynk to Particle where you then need to expose variables first and then use Blynk webhooks. Once you have the hang of it though, it works very well.

Interesting. Seems like a nice project!!