Core flashes once, then won't flash. Eventually breathes blue

Admittedly, I am both a hardware and embedded systems software novice.

I have set up the core with a Pulse Sensor Amped using the library already ported. I have then, using I2C, connected a LSDM9DS0 gyroscope and I made a (very) rough attempt at porting the library from arduino for it.

The code validates in the IDE, and will flash the first time. If you monitor via serial though, nothing is output and if I then try to reflash the core it does not respond. Eventually it breathes blue (the same blue as waiting for wifi credentials but instead of flashing it breathes).

If I reboot the core, it will connect to Wifi but again after a few minutes it will breathe blue instead of cyan.

Any help would be appreciated. Can post the code below if that would help.

To add to it: If I do a factory reset, I then can’t connect the core to wifi via the iOS app, I have to do it through serial.

@christophmccann, are you using the Adafruit 9DOF IMU breakout? I had ported the 9DOF library some time ago but things have changed a lot since. I would have to revisit the code to do the updates.

One important thing is that the SparkIntervalTimer library may affect I2C operation on D0/D1 if the timer used is TMR4. If I recall, the PulseSensor library uses a single timer and by default, the first timer to be used is TMR2 so that should not be the cause of the problem. I suggest you test your IMU code independently of the PulseSensor code to make sure your port works and THEN add the remaining code to test. :smile:

1 Like

@peekay123. Thanks very much. Its not an Adafrut, it is https://www.sparkfun.com/products/12636, but it looks to be broadly the same chip as the Adafruit?

I followed your advice and bingo the IMU works. I don’t suppose you could give me a steer on integrating the two codebases? I plan on adding in an I2C infra-red thermometer as well just to complicate matters.

Really appreciate your help.

@christophmccann, I would have to see your entire code to look for possible conflicts. Any chance I can get access to it?

@peekay123 Course, is easiest way just to share on here?

@christophmccann, the easiest way is to post it on Github or create a gist on github. Otherwise, you can share on dropbox.

@peekay123 Gist is here: https://gist.github.com/christophmccann/15bb1c2b34022b4ff2c5

Thanks very much for your help.

Hey @peekay123, I just wondered if you had had any time to review my code ? :slight_smile: Any advice/help is much appreciated!

See https://gist.github.com/christophmccann/15bb1c2b34022b4ff2c5#file-main-ino-L66.

It was called before Serial.begin() and might have caused an issue.

I see this breathing blue symptom when using something that is not initialized.

Eg. SPI before SPI.begin is called.

@mdma, seems like something we need to work on no?

1 Like

@kennethlimcp beat me to it! He is so sharp, I can’t keep up with him :stuck_out_tongue:

I wonder if the “empty” app template should have a commented out Serial.begin(9600) in setup() as a reminder. Or, have a pre-processor rule that catches the lack of initialization on the affected devices as mentioned. :smile:

2 Likes

Hey @kennethlimcp @peekay123,

Thanks very much for getting back to me and sorry for the beginners error!! I have taken out what you suggested but it still doesn’t work. I have taken it out all code except for the gyroscope code but it isn’t working either. Updated gist is here: https://gist.github.com/christophmccann/34dfb58005e1e8d4290e

I’m getting quite strange behaviour. If i completely factory reset the core, I can flash it from the IDE but if I then change the code and try to flash again, the core won’t flash. After about 5 minutes, it will start breathing blue. I can then do a soft reset and it will re-connect to Wifi but after 5 minutes same thing happens. I have no choice but to do another factory reset.

I’ve went through the code and I can see that Wire.begin is being called before anything else starts.

I’ll keep looking for the problem but if you happened to have a chance to check it out, it would be greatly appreciated.

I wonder if we’re seeing the Serial buffer filling too far?

As a sanity check I might just add a check during setup to see if you’ve shorted some random pin to Ground, and then you can use jumpers to force your code into a while(pin is low) { Spark.process(); } scenario, so no matter what you can get back into a good state for an OTA flash?

Thanks,
David

Hey all, thanks for all the help.

I have traced the issue back to the function dof.readGyro(). The code for it is:

void LSM9DS0::readGyro()
{
	uint8_t temp[6]; // We'll read six bytes from the gyro into temp
	gReadBytes(OUT_X_L_G, temp, 6); // Read 6 bytes, beginning at OUT_X_L_G
	gx = (temp[1] << 8) | temp[0]; // Store x-axis values into gx
	gy = (temp[3] << 8) | temp[2]; // Store y-axis values into gy
	gz = (temp[5] << 8) | temp[4]; // Store z-axis values into gz
}

If I comment out the call to this function, then the core doesn’t “freeze” but if it is in then it appears to block and nothing gets printed to the serial. Eventually the core starts breathing blue.

Any help at all appreciated.

1 Like

@christophmccann, I wonder if it is the call to gReadBytes(OUT_X_L_G, temp, 6) that stalls?

I am looking at the gx, gy and gz lines and I also wonder if some casting is necessary:

gx = (uint16_t)(temp[1] << 8) | (uint16_t)temp[0]; // Store x-axis values into gx
gy = (uint16_t)(temp[3] << 8) | (uint16_t)temp[2]; // Store y-axis values into gy
gz = (uint16_t)(temp[5] << 8) | (uint16_t)temp[4]; // Store z-axis values into gz

:slight_smile:

2 Likes

Ok, I am really hoping I can stop bothering you guys soon lol. I added in the casting but it still doesn’t work so I assume it is that line that is blocking. I have noticed this odd behaviour whereby the serial will sometimes spit out 2 or 3 results from the gyro and then just stop.

I see this same behaviour in some other code I have whereby I have a pulse sensor, IR thermometer and I have added in two ring terminals that measure electrical conduction of the skin i.e. sweat.

    void setup() {
    pinMode(blinkPin,OUTPUT);         
    pinMode(fadePin,OUTPUT);
    pinMode(A6, INPUT);
    Serial.begin(115200);            
    interruptSetup();                
    mlx.begin();
}

void loop() {
    int a = 0;
    a = analogRead(A6);
    Serial.println("LOOPED");
    ledFadeToBeat();
    delay(20);
}

In the above example looped will be output a couple of times by the serial and then completely stall, but if I comment out analogRead it works. mlx.begin() is for the IR thermometer whilst interruptSetup() is for the pulse sensor. This will also cause the core to eventually breathe blue.

I am hoping that whatever I have wrong in this is the same issue as with the gyro? I see the suggestion above about the serial buffer filling up to fast and I wonder am I doing the same thing here? And if so, how do I correct it?

I really do appreciate these are novice questions, but trying my best to pick this up! Next time I am in the states, I owe you guys many many beers.

1 Like