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

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

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

Post 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
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

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

Post 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)
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

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

Post 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!
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

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

Post 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!
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

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

Post by PoltoS »

Please test it on 2.1.1 (test one). We will appreciate your feedback.

viewtopic.php?f=3427&t=25525
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

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

Post 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?
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

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

Post 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.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

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

Post 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 ;-)
Post Reply