Page 1 of 1

I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 01 Oct 2017 14:55
by petergebruers
Motivation

After I've toyed with the Z-Uno demo sketches (see http://z-uno.z-wave.me) for some time, I thought I would show a little ambition and at the same time seek feedback from experienced users. I took the BH1750 sketch and improved the reporting range (from about 13000 to about 79000 Lux), add detection of I2C bus errors and add an algorithm to calculate reporting interval, getting good responsiveness without spamming the Z-Wave network. I would really appreate if you could review it, or even try it. Then give me some comment, criticism or advice! I will use it to refine this sketch and develop other solutions!

Features

- Measures 1 x per second, so you can poll at any time and get a value that is no older than about 1 second.
- Reports 0 - 78642 Lux. Resolution: 1.2 Lux (Original Demo Sketch: max about 13000 Lux).
- Plenty of debugging output via USB (serial emulation). Can be disabled by changing two lines in the sketch.
- Honours minimum 30 second reporting interval for unsollicited reports.
- Automatic reporting interval, ranging from 30 seconds up to 32 minutes. If light level doubles or halves, the sensor reports as soon as possible (honouring the minimum of 30 seconds between unsollicited reports). If changes are smaller, reporting time increases. Tested by me, indoors and outdoors. (Original Demo Sketch: fixed reporting).
- Detects I2C bus errors. LED blinks+ automatic bus reset. Sensor can be hot plugged. (Original Demo Sketch: no detection of bus errors, sketch does not recover from bus errors).
- Plenty of comments in source code.
- Uses timer(s) and avoids delay() to get maximum responsiveness.
- White LED blips when data gets transferred to the controller.

Download and readme:

https://github.com/petergebruers/Z-Uno-BH1750

Re: I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 01 Oct 2017 23:47
by PoltoS
Great job!

If you don't mind, we can reference it on the site: http://z-uno.z-wave.me/examples/bh1750-petergebruers/ (no links on it until you approve it)

Re: I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 02 Oct 2017 10:04
by petergebruers
Thank you! If you think the sketch is good enough to be mentioned on the Z-Uno site, that is OK. I am flattered!

Re: I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 02 Oct 2017 23:21
by PoltoS
Z-Uno is a community driven product. We appreciate a lot people sharing their experience and code. Make and Share is our motto!

Re: I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 03 Oct 2017 00:34
by PoltoS
Please test it on 2.1.1 (test one). We will appreciate your feedback.

viewtopic.php?f=3427&t=25525

Re: I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 03 Oct 2017 10:14
by petergebruers
Under 2.1.1 I can compile one time. The next time I compile, I get:

"?ASlink-Warning-Undefined Global '_Timer' referenced by module 'LLCore_arduino"

I can make it work by applying this dirty hack: I add "extern void Timer();" to the source code, like this:

Code: Select all

extern void Timer(); // Makes linker happy

void Timer() {
  if (msCounter1 == 0)
  
  ****** code removed for brevity
  }
Any idea on a better fix?

Re: I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 03 Oct 2017 12:59
by p0lyg0n1
It's really wonderful to have great beta-testers! I have an idea... I try to reproduce it and fix this in compiler. Thank you!
Another idea is to split your sketch to library and the main part. It will be cool to fix the code and make it reusable.

Re: I have made an attempt at improving the BH1750 demo sketch and it is available for comment

Posted: 04 Oct 2017 10:03
by petergebruers
Thank you for the compliment. The BH1750 sketch has been running flawlessly since my last post. So now I will move on to other sketches. I think I am going to try the improved FLiRS functionality first. It is difficult choice, there are some many exiting things in 2.1.1 like the error reporting on Serial0 and custom parameters, I do not know where to start ;-)