P1 keeps crashing with certain code

I just made some boards with the P1 modules and everything works fine. The device is claimed on my account, I can upload code to it over WiFi, it runs blinky code just fine, and I even got UDP and a few other things running. So I think the hardware is working properly. However, I’ve noticed that some code I’ve been trying to port from Arduino completely sends my P1 board into a tailspin. For example, this code:

void setup()
{

  Serial.begin(9600);  

  Wire.begin();
  Wire.beginTransmission(MCP3421_ADDRESS);
  Wire.write(0x1F);  // Set register for 18-bit continuous mode
  Wire.endTransmission();

}

void loop()
{

  delay(250);
  
  Wire.requestFrom(MCP3421_ADDRESS, 5);
  if (Wire.available() != 5) 
  {
    Serial.println("Wire.available failed");
    
  }
  else
  {
    
    byte a = Wire.read();  
    Serial.print(a,HEX);
    
    byte b = Wire.read();
    Serial.print(b,HEX);
    
    byte c = Wire.read();
    Serial.print(c,HEX);
    
    byte d = Wire.read();
    Serial.print(d,HEX);
    
    byte e = Wire.read();
    Serial.print(e,HEX);
    
    Serial.println(" \n");
    
    int32_t v = (a << 16);
    v |= (b << 8);
    v |= c;
    
    
    // read but ignore status
    uint8_t s = d;
    //print voltage from channel one in millivolts
    Serial.println(v,HEX);
    Serial.println(v,BIN);
    Serial.println(v);
    //Serial.println(" mv");
  
  }
  
  
  delay(2000);
  
}

The code compiles/verifies without any problems, and I can flash it to the device over WiFi without any problem also. But as soon as it restarts, it goes into the following loop:

  1. Flashes White (just restarted)
  2. flashes green (trying to connect to WiFi)
  3. Rapidly flashes cyan for less than 1 second
  4. Starts to breathe cyan for less than 1 second
  5. Restarts and repeats

The code isn’t being executed and from what I can tell, the device just keeps restarting. I then have to do a factory reset and run setup on it every single time.

With certain code, it also just just starts flashing red, and I have no idea what that means.

Also, I’m just trying to get a MCP3421 ADC chip working… anyone have a library or code for this that works??

Any help would be appreciated.

Thanks.

I think I2C is still unstable on the photon/P1 .
Try running some code without any I2C calls to verify it’s not your P1.

@jakeypoo is correct. There are presently I2C issues with the Photon/P1 that will be resolved i the next release. I don’t recall the latest develop branch of the firmware has the fix implemented or not. :smiley:

Sorry to hear about these problems. There are some I2C fixes in the upcoming release, but these were related to not having a I2C device connected. Is the device connected to your P1?

Rather than doing a factory reset, you can use safe mode to skip over running your code.

I’d like to echo the other comments and suggest you remove the calls to Wire to determine the problem by elimination.

Are you building locally or using the WebIDE?

1 Like

@mdma,

Thanks for the info. The device should be connected to the i2c bus directly on my board. And I am using the WebIDE. The hardware works fine when I load some other code on it. I can blink LEDs, send UDP data, etc. It just goes into a tailspin when I load the above code.

So I tried going line by line and commenting until the code crashes. It seems to crash when I call wire.begin():

#define MCP3421_ADDRESS 0x68
void setup()
{
    Serial.begin(9600);  

    Wire.begin();
    Wire.beginTransmission(MCP3421_ADDRESS);    //////// THIS LINE causes it to crash.
    Wire.write(0x1F);
    Wire.endTransmission();

}

So what can I try from here? I just want to get this MCP3421 working. If @jakeypoo is correct and i2c is unstable, thats a pretty big limitation on the P1s and I have 40 useless boards :confused:

If it is the case that I2C is unstable with the 0.4.0 release, please allow me to assure you it’s temporary. We are busy preparing the 0.4.3 release, just clearing the last few hurdles.

If you like, I can get you a pre-release version that you can flash to your device which should help fix the issue.

Do you have an ETA for the new firmware? If its soon I can wait. Otherwise, yes, it would be great to get on the pre-release version.

Thanks

Wait no longer! https://github.com/spark/firmware/releases/tag/0.4.3-rc2

1 Like

OK, I think I have my P1 updated to 0.4.3rc2, but now I have 2 more questions:

  1. How do I verify that 0.4.3 is what is running on my P1?

  2. How do I get my webIDE to compile code for the 0.4.3 firmware? Currently it won’t let me change it away from V0.3.4.

Thanks again for all your help.

1.) Place the Photon in Listening mode and hit s using a serial terminal connected at 9600 Baud

2.) The 0.3.4 firmware version only concerns the core and is not true for the Photon. Current version on the Web IDE is V0.4.1 and will (hopefully) be updated soon.

You can still use the Web IDE to build firmware and OTA it to the Photon since user firmware is designed to be backward compatible. As long as system firmware version is >= user firmware version

When I put my P1 into listening mode and type β€˜s’, this is what I get:

β€œp”:8,β€œm”:[{β€œs”:16384,β€œl”:β€œm”,β€œvc”:30,β€œvv”:30,β€œf”:β€œb”,β€œn”:β€œ0”,β€œv”:3,β€œd”:[]},
{β€œs”:262144,β€œl”:β€œm”,β€œvc”:30,β€œvv”:30,β€œf”:β€œs”,β€œn”:β€œ1”,β€œv”:3,β€œd”:[]},
{β€œs”:262144,β€œl”:β€œm”,β€œvc”:30,β€œvv”:30,β€œf”:β€œs”,β€œn”:β€œ2”,β€œv”:3,β€œd”:[{β€œf”:β€œs”,β€œn”:β€œ1”,β€œv”:3,"":""}]},
{β€œs”:131072,β€œl”:β€œm”,β€œvc”:30,β€œvv”:30,β€œu”:β€œxxxxxxxxx”,β€œf”:β€œu”,β€œn”:β€œ1”,β€œv”:2,β€œd”:[{β€œf”:β€œs”,β€œn”:β€œ2”,β€œv”:1,"
":""}]},
{β€œs”:131072,β€œl”:β€œf”,β€œvc”:30,β€œvv”:30,β€œu”:β€œxxxxxxxxx”,β€œf”:β€œu”,β€œn”:β€œ1”,β€œv”:2,β€œd”:[{β€œf”:β€œs”,β€œn”:β€œ2”,β€œv”:1,"_":""}]}]

Does this indicate 0.4.3 was loaded successfully?

EDIT: Sorry, my bad… looks like I had slightly different code. The P1 is indeed making it past the line where it crashed previously. I’ll try to force through and see if I can get it working.

Thanks for the help!

Yup it does look like V0.4.3 is loaded on your photon.

Not too familiar about this issue so someone else will have to chime in.

Ok off topic but I’m curious at to how you built you P1 board?
Did you hand solder or pick’n place?
What did you use to stencil? Did you get a commercial stencil made or do something DIY?
Would love to see the design if it was something you can share.

Thanks

1 Like

@mrOmatic Personally, I used the footprint in the eagle library, built on a one sided board and used a electric hotplate to reflow the board similar to this video : https://youtu.be/3drirgNktQg

1 Like

I also used the footprint in the eagle library, and my design is almost identical to what @BDub put up in the documentation. Just need a regulator and a few capacitors. Thats what I love about the P1 module.

As for making the board, I’m not mass producing any boards at the moment, so I just apply solder paste using a toothpick (no stencil). I then reflow the board in a toaster oven and done!