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:
Flashes White (just restarted)
flashes green (trying to connect to WiFi)
Rapidly flashes cyan for less than 1 second
Starts to breathe cyan for less than 1 second
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??
@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.
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.
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
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.
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
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.
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.
@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
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!