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!!

I am experiencing similar symptoms with the Photon 2 connected to a SparkFun_Qwiic_Scale_NAU7802. I am using the SparkFun_Qwiic_Scale_NAU7802_Arduino_Library-1.0.4. The Photon 2 will not go through the normal bootup status light sequence when it is connected to USB jack. The blue led is on solid. If I power the setup with the SDA line disconnected the bootup is normal but the I2C connection to the 7802 fails at the myScale.begin(). If however I power things up with SDA disconnected and wait until the Photon 2 has begun initializing and then connect the SDA line the myScale.begin() succeeds and the code reads the load cell attached to the 7802 perfectly. I have tried two NAU7802 and two Photon 2 with the same results. I have also tried adding 4.7k pullups and 10k pullups on the I2C lines(the spec sheet says 10k pullup internal to the NAU7802). Same results. Could there be something I am overlooking as far as arduino code?
Thanks,
Bob

#include "Particle.h"

#include "C:\Users\Robert\Documents\Particle\Particle_Processor_Projects\Load_Sensor_NAU7802\lib\SparkFun_Qwiic_Scale_NAU7802_Arduino_Library-1.0.4\src\SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h"

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Run the application and system concurrently in separate threads
SYSTEM_THREAD(ENABLED);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
//SerialLogHandler logHandler(LOG_LEVEL_ALL);
NAU7802 myScale;
// setup() runs once, when the device is first turned on
void setup() 
{
  // Put initialization like pinMode and begin functions here
  Serial.begin(115200);
  delay(2000);
  Serial.println("Plug in sensor now");
  Serial.println("Plug in sensor now");
  Wire.begin();
  while (myScale.begin() == false)
  {
    Serial.println("Scale not detected. Please check wiring. Freezing...");
    delay(2000);
  }
  Serial.println("Scale detected!");
}
void loop() {
  if(myScale.available() == true)
  {
    long currentReading = myScale.getReading();
    delay(2000);
    Serial.print("Reading: ");
    Serial.println(currentReading + 470000 + 4000 - 2700);
  }
  else
  {
    Serial.print("Reading Failed ");
  }
}

@Bellatrix, do you have anything else on the I2C bus? I would not try adding pull-ups since the 7802 already has them. How is the 7802 wired to the Photon 2?

Also, the 7802 should be plugged in BEFORE powering the Photon 2/7802.

Hello PK,
Thank you for your reply. Nothing else on the I2C bus. The only connections between the two are SDA and SCL. There is a ready pin on the NAU7802 so maybe that plays a role with the issue. If I power the Photon 2 on with the NAU7802 connected, it won't boot. No status light activity at all. I also created a blank project and oddly enough it won't boot with the NAU7802 connected either.

Hi @Bellatrix

I'm just trying to clear up the connections to the 7802. You should have SDA and SCL as you say, but you also need GND and generally +3V3 power connections. It's possible to have only ground and SDA and SCL between the boards if you power the 7802 separately but three wires is the minimum and four is the normal way to connect it.

So sorry to ask but you do have power connected, right?

Also could the scale itself be connected electrically to earth ground? The 7802 creates a supply for that side but weird grounding could do what you are seeing. Can you try just the P2 and the 7802 without the scale connected to the 7802 board.

2 Likes

Hello BKO,
I have the NAU7802 connected to ground and USB pins. The NAU7802 spec sheet says " VIN - This is the power pin. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 3V microcontroller like a Feather M4, use 3V, or for a 5V microcontroller like Arduino, use 5V."* so that is why I connected it to the 5vdc USB pin. I am connecting a strain gauge / load cell ( "Strain Gauge Load Cell - 4 Wires - 1Kg : ID 4540 : $3.95 : Adafruit Industries, Unique & fun DIY electronics and kits") to the four inputs of the 7802 in what would be a wheatstone bridge configuration. The load cell has no earth grounding as far as I know. I can disconnect the load cell inputs if you still think that is worth pursuing. Are there any pins on the Photon 2 that need to be resistor pull up/downs in a minimal configuration? I can't seem to find a minimal level sketch for the Photon 2. I have also tried 10uF cap and despiking cap on the breadboard power rails. Just a wild thought .. could the NAU7802 become a I2C master before the Photon 2 has a chance to initialize and therefore block the Photon 2 initialization. I don't even know if the 7802 has I2C mastering capability and cant find anything so far to say it definitely does not.
Thank You,
Bob

Hi BKO,
I decided to sit down and review the Photon 2 docs, something I should have done well before getting it out of the box. Had I done so I would have read this " * The I2C port is 3.3V and must not be connected directly a 5V I2C bus". I'd say that is a full dozen Grade A Extra Large on my face. I guess I'm lucky I didn't fry both of my Photon 2s and NAU7802s (hopefully). I switched the vin of the NAU7802 to the Photon 2 3v3 pin and everything is working as expected now. My apologies to you, Rick and the rest of the thread readers for wasting your time. Thank you for your help.
Thanks,
bob

4 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.