I built a Custom Input for the SI1145 IR / UV / Visible Light Sensor using the tsl2561 sensor as a template. I also riddled the SI1145 code with NOTES, for myself so I have an idea of what I did.
I’m trying to learn python the hard way, by reading and trying to program different modules. The tsl2561 had a lot of code in def get_measurement(self) that didn’t seem relevant for the SI1145 so I just commented the lines.
Mycodo excepted the code and when I go to the SETUP > INPUT I was able to add the SI1145 sensor and was even able to open the drop down. That is as far as I’ve gone. The last attempt with creating a Custom Input I corrupted the system so bad I had to re-load Mycodo.
Could someone take a look at the following code and tell me if it looks ok as is or did I miss a few things?
si1145.py (15.7 KB)
Edit: Removed code and replaced with file attachment
Thanks for sharing your Input module. Here are some things I noticed:
I see your module has a 5th measurement (prox, not sure what it is), but it’s not used (i.e. no value is saved to the database for that measurement). added “length” measurement and unit “cm” and added function to read proximity.
Also, I notice get_measurement() doesn’t actually do anything, so the module will not acquire or storing any measurements. The contents of get_lux() should be renamed get_measurement() or get_lux() should be called in get_measurement() (though redundant) if you want this to occur. get_measurement() should also return self.return_dict.
You’re calling _get_luminosity(), but this appears to be a protected member of the sensor class (indicated by the leading “_”). changed to use the functions specified in the library example script.
There doesn’t appear to be lux() in the module you are using. Removed.
You aren’t checking if all channels are enabled. Added.
Here’s an updated version with the changes for you to review/test: si1145.py (2.4 KB)
Kyle thanks for all your help. Hopefully by the time I get the whole system put together I’ll Have a better understanding of python.
the fifth measurement is for proximity. I found an option on the net where they added a diode to the sensor board. Supposedly it can measure out to 50 cm. I was hoping to use it for measuring how close the tegu’s get to the uv light and see if they have a preference to where they like to bask.
I do have some Ultrasonic Distance Sensors, but I planned to use them on the fogging units to measure the water in the holding tanks. but that’s a few weeks away.
Let me know if that module I attached works and I’ll include it in the next release. Thanks.
No, it has an issue I’m looking at:
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/controllers/base_controller.py”, line 74, in run
File “/var/mycodo-root/mycodo/controllers/controller_input.py”, line 317, in initialize_variables
self.measure_input = input_loaded.InputModule(self.input_dev)
File “/home/pi/Mycodo/mycodo/inputs/custom_inputs/si1145.py”, line 64, in init
File “/home/pi/Mycodo/mycodo/inputs/custom_inputs/si1145.py”, line 71, in initialize_input
TypeError: ‘module’ object is not callable
I ran i2cdetect -y 1 and the SI1145 is their.
I was importing the library incorrectly. The developer of the library chose to be confusing with their use of the same name:
import SI1145.SI1145 as SI1145
self.sensor = SI1145.SI1145()
I updated the previously attached code. Let me know if it resolves the issue.
thanks for the help!!!
I was going to load Mycodo into pycharm and see it that would help me figure out what / why I as getting the error
so far looks good… and no errors reported in the in the mycodo.log
DATA > Live
SI1145 (Input 64a571c1)
Input (SI1145), 15.0 second interval
Measurement | Timestamp
2 uv (Light) (SI1145 UV) CH0 | 2021/7/7 11:15:33
261 visible (Light) (SI1145 Visible) CH1 | 2021/7/7 11:15:33
260 IR (Light) (SI1145 IR) CH2 | 2021/7/7 11:15:33
I didn’t activate / use the Proximity because it uses an IR LED, which I don’t have on hand. I’ll order a half dozen after lunch. But, I don’t expect them until the middle of the month… I’ll advise…
the other part I haven’t activated / use is the Lux. I’ll have to go back to my notes an see what they are doing and why…