No provision for a I2C bad communication or the IC not present
stdevPavelmc opened this issue · 4 comments
The library has no provision for a bad communication or even the IC not present, the sketch will simply hang and will not work.
It must has a way to alert the user that the IC in not there or even that there is no IC. In it most basic form it must not hang the full sketch for this.
While playing with the console example, I added these lines near the end of setup()
Serial.println <the banner>
if ( Si.i2cRead(0) > 0 ) devicePresent = 1; // should return the RevID=B, -1 is missing.dead si,
//Serial.print("Si.i2cRead(0) = "); Serial.println(Si.i2cRead(0),BIN);
//Serial.print("devicePresent = ");Serial.println(devicePresent);
if ( devicePresent == 1) { cmdHelp(); }
else { // err msg & loop forever
Serial.println(F("DEVICE MISSING. STOPPING."));
while(1);
}
While this just warns the user and hangs, it is just the console and if the chip is not there then there is no point in continuing.
Most projects will have a display, so the user can be warned. Behavior (hang or not) should be the programmer's choice. For those without a display, a buzzer error code pattern or an LED blink pattern could be used to alert the user,
Agree, I'm thinking on a function that allows the user to test the presence of the IC.
Like Si.ok()
, true if present & working, and false otherwise. In this way the user can implement his own checks & warn via LED/Dispaly/Serial/whatsoever...
Hi, thanks for your good work!
For this issue, may I suggest you to return a boolean for the 2 init methods?
If init fails, no need to go further
Hi, thanks for your good work! For this issue, may I suggest you to return a boolean for the 2 init methods? If init fails, no need to go further
Yup, I think this is the way, and setup a warn code section on the example, to teach the users how to use that feature