Photon Unable to Connect to Wifi

First photon post. Not sure if yay or nay.

I just started working with a photon board late last night. Everything worked perfectly fine on the 3 boards I have.
2 are running 0.4.3 and one is running 0.6.0. I just updated EVERYTHING. I’ve gone through every single post I can find about lack of connectivity and nothing has solved my issues.

One thing I have not seen mentioned that seems to be causing my problems is SPI. I was running all kinds of little tinker stuff, basic LED on/off, 2 LEDs on/off, all the good hello world serial jazz.
As soon as I put SPI code on, it seems to have permanently broken all 3 of my photons. Not a single one can remain on a network for more than 5 seconds not exaggerating, it connects, I pick up my phone and open tinker, and it’s offline).

I am getting a solid green state. Only way for me to get to setup is to cut power all together and I have to reset while it’s starting. If I let it go for a bit then it enters the solid green state and it’s locked in there.

Are there any suggestions?
I have done the serial wifi, I’ve tried the 0.6.0 and 0.4.3 firmware versions, I’ve tried other networks, I have released and reclaimed. I saw that multiple networks saved can cause issues but at least 1 of the boards has only ever been on one network.
I read it might be an ISP issue but I have used my phone as a hotspot and the issue persists.

I’ve essentially got 3 very tiny, lightweight bricks and I need them for a school project.

Edit
Might have just solved my problem.
Through a 1 second delay in my code and it seems to be okay now. Might have been working too fast to handle the WiFi chip.

Edit
Wishful thinking, it’s basically bricked again.

The most recent firmware version is 0.6.2 and the most recent version CLI is 1.22.0 - I’d suggest you go for both of these versions :wink:

Showing your code and your hardware setup might help locating your issue.

SPI does definetly work (when used correctly :sunglasses:)

BTW, Safe Mode usually is the way to get out of any lockup conditions - to make bricking your device more difficult than that.

1 Like

As of last night the DFU driver told me 0.6.0 was the latest updated. I’ll try doing that again now.

Code:

        
int ndx = 0;

#define BYTE 8
#define CFG_REG_A_M 

//Register Addresses
//Accelerometer
#define CTRL_REG1_A 0x20
#define CTRL_REG2_A 0x21
#define CTRL_REG3_A 0x22
#define CTRL_REG4_A 0x23

#define STATUS_REG_A 0x27
#define OUTX_L_A 0x28
#define OUTX_H_A 0x29
#define OUTY_L_A 0x2A
#define OUTY_H_A 0x2B
#define OUTZ_L_A 0x2C
#define OUTZ_H_A 0x2D
//End Accelerometer Addresses

//Magnetometer
#define CFG_REG_A_M 0x60
#define CFG_REG_C_M 0x62

#define STATUS_REG_M 0x67
#define OUT_X_L_REG_M 0x68
#define OUT_X_H_REG_M 0x69
#define OUT_Y_L_REG_M 0x6A
#define OUT_Y_H_REG_M 0x6B
#define OUT_Z_L_REG_M 0x6C
#define OUT_Z_H_REG_M 0x6D
//End Magnetometer Addresses
//End Register Addresses

void Res(){
    Serial.println("Response");
}

void setup() {
   Serial.begin(9600);
   SPI1.begin();
}

void loop() {
   int accStatus = 0;

   int A_X_L;
   int A_X_H;
   int A_Y_L;
   int A_Y_H;
   int A_Z_L;
   int A_Z_H;
   
   int A_X_mg;
   int A_Y_mg;
   int A_Z_mg;
   
   int A_X_deg;
   int A_Y_deg;
   int A_Z_deg;
   
   
   int INT1 = 0;
   int INT2 = 0;
   
   
   int M_X_L;
   int M_X_H;
   int M_Y_L;
   int M_Y_H;
   int M_Z_L;
   int M_Z_H;
   
   int M_X_mg;
   int M_Y_mg;
   int M_Z_mg;
   
   int address;
   
   int heading;
   
   int INT_MAG = 0;

   if(ndx == 0){
      Serial.println("Photon Development Board (LSM303AGR)");
      Serial.println("");
   
      Serial.println("A_X [LSB] A_Y [LSB] A_Z [LSB] A_X [mg] A_Y [mg] A_Z [mg] A_X [deg] A_Y [deg] A_Z [deg] INT1 INT2 M_X [LSB] M_Y [LSB] M_Z [LSB] M_X [mG] M_Y [mG] M_Z [mG] Heading [deg] INT_MAG");
      ndx++;
   }
   
   //Accelerometer jazz
   //Write 00 to reg2 and reg3
   //Write 81 (BDU set and SPI enable) to reg 4
   //Write 57 to Reg1 (enable XYZ and set HR, LP, 100hz)
   digitalWrite(D5, LOW);
   digitalWrite(D6, HIGH);
   SPI1.transfer(CTRL_REG2_A);
   SPI1.transfer(0x00);
   
   SPI1.transfer(CTRL_REG3_A);
   SPI1.transfer(0x00);
   
   SPI1.transfer(CTRL_REG4_A);
   SPI1.transfer(0x81);
   
   SPI1.transfer(CTRL_REG1_A);
   SPI1.transfer(0x57);
   
   //wait 90ms per documentation suggestion
   delay(90);
   
   //Begin Reading data
   //do{
   //    address = STATUS_REG_A;
   //    SPI1.transfer(address);
   //    accStatus = SPI1.transfer(0x00);
   //    Serial.print("Accelerometer Status: ");
   //    Serial.println(accStatus);
   //    delay(1000);
   //} while(!(accStatus & 0x08));
   //Serial.println("This occured after the dowhile loop");
   
   SPI1.transfer(OUTX_L_A);
   A_X_L = SPI1.transfer(0x00);
   
   SPI1.transfer(OUTX_H_A);
   A_X_H = SPI1.transfer(0x00);
   
   SPI1.transfer(OUTY_L_A);
   A_Y_L = SPI1.transfer(0x00);
   
   SPI1.transfer(OUTY_H_A);
   A_Y_H = SPI1.transfer(0x00);
   
   SPI1.transfer(OUTZ_L_A);
   A_Z_L = SPI1.transfer(0x00);
   
   SPI1.transfer(OUTZ_H_A);
   A_Z_H = SPI1.transfer(0x00);
   
   
   //Serial.print((A_X_H << BYTE) | A_X_L);  Serial.print("   ");   Serial.print((A_Y_H << BYTE) | A_Y_L);  Serial.print("   ");   Serial.print((A_Z_H << BYTE) | A_Z_L);  Serial.println("   ");
   
   Serial.printf("%X", (A_X_H << BYTE) | A_X_L);  Serial.print("   ");   Serial.printf("%X", (A_Y_H << BYTE) | A_Y_L);  Serial.print("   ");   Serial.printf("%X", (A_Z_H << BYTE) | A_Z_L);  Serial.println("   ");
   /*
   Serial.print(A_X_mg);  Serial.print("   ");   Serial.print(A_Y_mg);  Serial.print("   ");   Serial.print(A_Z_mg);   Serial.print("   ");
   
   Serial.print(A_X_deg);  Serial.print("   ");   Serial.print(A_Y_deg);  Serial.print("   ");   Serial.print(A_Z_deg);   Serial.print("   ");
   
   Serial.print(INT1);  Serial.print("   ");  Serial.print(INT2);  Serial.print("   ");   
   
   Serial.print((M_X_H << 2 * BYTE) | M_X_L);  Serial.print("   ");   Serial.print((M_Y_H << 2 * BYTE) | M_Y_L);  Serial.print("   ");   Serial.print((M_Z_H << 2 * BYTE) | M_Z_L);  Serial.print("   ");
   
   Serial.print(M_X_mg);  Serial.print("   ");   Serial.print(M_Y_mg);  Serial.print("   ");   Serial.print(M_Z_mg);   Serial.print("   ");
   
   Serial.print(heading);   Serial.print("   ");
   
   Serial.println(INT_MAG);
   
   */
   delay(5000);
   
}

I’m troubleshooting so rather than a diagram I’ll summarize:

D5 ->CS
D6->separate CS
D4->SCK

The sensor has SDI/SDO on a single pin, so I have D3 going to the pin and D2 going to the pin across a 10k resistor (trying 4.7k once I get it up again).

depending on how it is setup your phone uses your router & isp net IP and tinker app uses that. while when you create a hotspot you might be creating a subnet which is like your phone becomes a new routing address. so if you photon is connected to the phone hotspot and then you start tinker the photon may be attempting to connect to competing addresses. this may be why the photon drops the hotspot as soon as you open tinker.

As stated the phone hotspot was one of several networks.

I used the phone hotspot, then independently on a different board I used my WiFi directly.

Both had the same issues.

well, you seemed to be talking about the same device when you said it was connected to a network[you did not mention which network] and then when you started tinker, it disconnected. the best way to deal with problems is to isolate variables and in this case multiple networks are multiple variables. so to have only 1 network anything involved is connected to or could possibly connect to helps eliminate variables thus helping to isolate while trying to find the problem.

How would the DFU driver know?

If you use the most recent CLI to perform

particle update

you'll see that 0.6.2 in fact is the most recent version :wink:

 Serial.printf("%X", (A_X_H << BYTE) | A_X_L);  Serial.print("   ");   Serial.printf("%X", (A_Y_H << BYTE) | A_Y_L);  Serial.print("   ");   Serial.printf("%X", (A_Z_H << BYTE) | A_Z_L);  Serial.println("   ");

This spaghetti line could be written a bit more concise, tool

 Serial.printlnf("%02X %02X %02X", (A_X_H << BYTE) | A_X_L), (A_Y_H << BYTE) | A_Y_L), (A_Z_H << BYTE) | A_Z_L);

And instead of the final delay(5000); I'd put this at the top of your loop()

void loop() {
  static _ms = millis();
  if (millis() - _ms < 5000) return;
  _ms = millis();
  ...
}

Sorry, not the DFU driver, the particler firmware manager claimed 0.6.0 is the latest version.

All of the code can be written “better.” Right now I just have it all segmented to more easily troubleshoot. As it’s my first time with photon I like to easily through a // and play around with stuff.

Are you aware of whether or not my SPI reading is the proper method?

SPI1.transfer(OUTY_H_A);
A_Y_H = SPI1.transfer(0x00);

Write to register being read, then set variable equal to the next transfer?

Have you got the latest firmware manager? Older FWMs will not know about any more recent versions.

Are you using the bare sensor chip or are you using a breakout board?
If the latter which?

I haven't checked the datasheets of the sensor, but is it actually set for SPI (not I2C) and do the default SPI settings fit the sensors needs?
For SPI (default 4-wire mode - which I'd go for to start with) the sensor uses two seperate pins for SDI and SDO, only with I2C the I/O happens on the same pin.

You are correct. I am using the 0.6.0 firmware manager. It’s the one given on the firmware-manager page.
Do you have a link to the most recent one by any chance?
I used your update method but the CLI cannot determine my devices ID or firmware version.

The settings are yet to be determined. I was given a few hundred pages of documentation, claims seem to indicate it will function for I2C or SPI depending on bits set on the registers (which seems to be a chicken and the egg situation).
My question is regarding the photon IDE syntax mainly. Is setting a variable equal to the SPI.transaction(XXX) the proper way to read?

Also, going back to the original topic, even after the particle update command I still need to reflash as tinker and then reflash my code to get functionality. Without a serial tinker flash the device is bricked.

The sensor has it’s SDI, SDO, and SDA on one pin. If I am not mistaken that would mean SDA (I2C data), SDI (SPI input) and SDO (SPI output) are on a single pin.

I just confirmed the documentation lists it as 3 wire SPI

particle update

does not require the device ID, but a device connected via USB and in DFU Mode.

This is where Safe Mode will spare you the trouble to reflash Tinker.

Yes, this would be the syntax to read from SPI (uint8_t x = SPI1.transfer(0x00)).

Hence the question about your actual hardware (breakout vs. naked sensor).
Here is one of the available breakouts that indicates that setting CS pin HIGH activates I2C while pulling LOW makes it SPI.

If you've multiple possible causes for your issue, going back to the most basic version will help pinpointing the actual cause.
Hence

The Pololu page states this for SPI

Which I don't see in your code.

BTW, do you think these libraries might help you any further?
Particle Web IDE
GitHub - pololu/lsm303-arduino: Arduino library for Pololu LSM303 boards

I did run the particle update. I was stating that I cannot view the firmware so I cannot confirm I am now on 0.6.2.

I’ll look into safemode. Thanks for the tip.

Thank you for syntax confirmation.

It is a breakout board, the documentation of the breakout board is claiming wither works but I am seeing discrepancies between the documentation and the board itself (for instance one lists the 2nd CS pin as accelerometer and the other lists it as the magnetometer). Going to be fun going through that.

The libraries may be handy, thanks for the links. I’ll review them in the morning, currently struggling as it’s 4 am. Was hoping to get the photon functional before the day really got going, hopefully the safemode tip will get me there soon.

1 Like

You could use one of these commands