Dreaded reset again


Due to a library change, I had to install a new sketch.

On the first Bluz, the board got stuck so I went to the dreaded reset. Now the board just blinks yellow and would never connect to the phone. When I press connect, the button changes to Disconnect and then back to Connect. So I gave up on this board and ordered a replacement (#103020297).

On the second Bluz, I did manage to upload the new firmware. However, now, I can never connect to the board. It just keeps flashing green (never breathing cyan). The iOS app shows that it is connected. The Web IDE also shows it as connected. When I power the board off, the iOS app shows disconnected. However, I can never really get it to connect to the cloud. I do not want to reset this board too lest it ends up like the first one.

The new code is below:

#include <stdint.h>

#include “application.h” //#include <Wire.h>
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#undef ARDUINO
#define ARDUINO 158

#include “LIDARLite_v3HP.h”

LIDARLite_v3HP myLidarLite;

#define FAST_I2C

enum rangeType_T

long count = 0;

void setup()
uint8_t dataByte;

// Initialize Arduino serial port (for display of ASCII output to PC)

// Initialize Arduino I2C 
#ifdef FAST_I2C
    #if ARDUINO >= 157
        //Wire.setClock(400000UL); // Set I2C frequency to 400kHz (for Arduino Due)
        Wire.setSpeed(400000UL); // Set I2C frequency to 400kHz, for Arduino Due            BLUZ
        TWBR = ((F_CPU / 400000UL) - 16) / 2; // Set I2C frequency to 400kHz



What may be causing this?


What is in the loop function?

Also, where did the LIDARLite library come from?


Thanks @eric. The library is from (LIDARLite_v3HP.cpp, .h):

I just found an error in the loop function so I will fix it and try again.


I reset the board and updated the firmware. Still, board is flashing green and not connecting.

Here is the loop function:

void loop()
uint16_t distance;
uint8_t c;
rangeType_T range = RANGE_NONE;

// Continuous loop
while (1)
      distance = distanceFast();
     count ++;
     if (count > 100)
        count = 0;
        Particle.publish ("Distance", String(distance) + " cm") ;


uint16_t distanceSingle()
uint16_t distance;
distance = myLidarLite.readDistance();
return distance;

uint16_t distanceFast(void)
uint16_t distance;



distance = myLidarLite.readDistance();

return distance;


void dumpCorrelationRecord()


Hello @eric.

I replaced the loop code above with code that turns on/off an LED (with the same setup() function) and everything worked.

I found out that the problem was with the While loop. It is not needed and when taken out everything worked well.

I still do not understand why the while statement caused the problem though.

Is there anything I can try to revive the other board. Firmware reset does not seem to help …


Bluz is single threaded, that is, the execution of all code happens in serial. That includes your user code and the system firmware. So adding a while loop that never exits into your user code blocks everything else, including the system code. That is why bluz couldn’t connect to the cloud, the system firmware was blocked from operating properly.


Thanks @eric. The While loop was not needed in my case but how does one handle a situation where a continuous loop is needed inside the loop() function?


The loop function is continuously called, so it should not need an inner loop. The user loop function should perform whatever checks it needs and then allow the function to exit, the system will then perform any necessary tasks, and call the user loop function again. So that continuous calling is already built in.