This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding New I2C -Adafruit VCNL4020
#1
Wink 
How do I add a new sensor to the approved sensors list in I2C.  I have purchase an Adafruit VCNL4020 to meassure distance- use it for water levels(bilge, tanks, etc).  Here is the link to the sensor:

https://www.adafruit.com/product/5810

Here is the link to create the driver:

https://github.com/adafruit/Adafruit_Cir...020#readme

Maybe not possible, though I would ask...
Reply
#2
install package:
#sudo pip3 install adafruit-circuitpython-vcnl4020

Lines to be added in  openplotterI2cRead.py (in python editor to respect tabs):

                  elif i2c_sensors[i]['type'] == 'VCNL4020':
                                        from adafruit_vcnl4020 import VCNL4020
                                        if i2c_sensors[i]['channel'] == 0:
                                                if i2c_sensors[i]['address']:
                                                        instances.append({'name':i,'type':'VCNL4020','tick':[now,now],'sensor':i2c_sensors[i],'object':VCNL4020(i2c, address=int(i2c_sensors[i]['address'], 16))})
                                        else:
                                                if i2c_sensors[i]['address']:
                                                        instances.append({'name':i,'type':'VCNL4020','tick':[now,now],'sensor':i2c_sensors[i],'object':VCNL4020(muxInstances[i2c_sensors[i]['address']][i2c_sensors[i]['channel']-1])})

and later

                          elif i['type'] == 'VCNL4020':
                                proximityKey = i['sensor']['data'][0]['SKkey']
                                luxKey = i['sensor']['data'][1]['SKkey']
                                if proximityKey:
                                    proximityRaw = i['sensor']['data'][0]['raw']
                                    proximityRate = i['sensor']['data'][0]['rate']
                                    proximityOffset = i['sensor']['data'][0]['offset']
                                    proximityFactor = i['sensor']['data'][0]['factor']
                                    tick0 = time.time()
                                    if tick0 - i['tick'][0] > proximityRate:
                                        try: proximityValue = round(i['object'].proximity,2)
                                        except: proximityValue = i['object'].proximity
                                        proximityValue2 = proximityValue
                                        Erg = getPaths(Erg,proximityValue,proximityValue2,proximityKey,proximityOffset,proximityFactor,proximityRaw)
                                        instances[index]['tick'][0] = time.time()
                                if luxKey:
                                    luxRaw = i['sensor']['data'][1]['raw']
                                    luxRate = i['sensor']['data'][1]['rate']
                                    luxffset = i['sensor']['data'][1]['offset']
                                    luxFactor = i['sensor']['data'][1]['factor']
                                    tick0 = time.time()
                                    if tick0 - i['tick'][1] > luxRate:
                                        try: luxValue = round(i['object'].lux,2)
                                        except: luxValue = i['object'].lux
                                        luxValue2 = luxValue
                                        Erg = getPaths(Erg,luxValue,luxValue2,luxKey,luxOffset,luxFactor,luxRaw)
                                        instances[index]['tick'][1] = time.time()
Reply
#3
Thank you DroZDi!!!
Just curious, what do you mean "and later"- add that to openplotterI2cRead.py after the first section?
Reply
#4
just go to the mentioned file openplotterI2cRead.py   and you will see Smile
Reply
#5
(2023-11-26, 07:50 PM)DroZDi Wrote: just go to the mentioned file openplotterI2cRead.py   and you will see Smile

Must have screwed something up, installed the driver, added the two sections in openplotterI2cRead.py(per your thread) and needed to add lines to openplotterI2C.py for the selection to appear in I2C supported devices.  I got it to come up in the I2C supported devices, selected the device and moved forward.  However, when looking at any dashboard no data came in at all through I2C(all devices were not working from I2C).  I assume something wrong in the code that caused a conflict.  Removed it all and now other I2C devices work.  Any thoughts...look at the attached file.


Attached Files Image(s)
   
Reply
#6
you are good Smile I forgot about /usr/lib/python3/dist-packages/openplotterI2c/openplotterI2c.py to add to the list...

anyway please run as root if you see other errrors then below you need to fix it (send output here)

Errors below are only ones expected:

root@orangepi5-plus:~# sudo python3 /usr/lib/python3/dist-packages/openplotterI2c/openplotterI2cRead.py
creating configuration directory /home/root/.openplotter
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/openplotterI2c/openplotterI2cRead.py", line 731, in <module>
main()
File "/usr/lib/python3/dist-packages/openplotterI2c/openplotterI2cRead.py", line 76, in main
conf2 = conf.Conf()
^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/openplotterSettings/conf.py", line 38, in __init__
os.mkdir(self.conf_folder)
FileNotFoundError: [Errno 2] No such file or directory: '/home/root/.openplotter'

root@orangepi5-plus:~# sudo python3 /usr/lib/python3/dist-packages/openplotterI2c/openplotterI2c.py
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/openplotterI2c/openplotterI2c.py", line 28, in <module>
from .version import version
ImportError: attempted relative import with no known parent package
Reply
#7
just made quickly...
I have no sensor so no way to test it...

just unzip and execute
sudo cp -pf openplotterI2cRead.py /usr/lib/python3/dist-packages/openplotterI2c
sudo cp -pf openplotterI2c.py /usr/lib/python3/dist-packages/openplotterI2c
sudo pip3 install adafruit-circuitpython-vcnl4020
sudo reboot

then open i2c module and try to configure.
next week Im hopping to get sensors so I will adjust code if not working...
==========================
valid for openplotterI2C ver 3.3.12


Attached Files Image(s)
   

.zip   VCNL.zip (Size: 11.28 KB / Downloads: 310)
Reply
#8
Hey that is so awesome, and I will try this weekend or hopefully sooner!
You have been very helpful!!! You have provided fantastic support and your knowledge is unquestionable!
Thanx again!!!!! Smile
Reply
#9
it will not work for you at all Sad
Sorry I completely forgot you work probably with Raspberry Pi - I use Orange pi 5 Big Grin
This is fix only for Orange pi 5/Orange pi 5 plus as I change in those files some code too.
Please send me on priv your files: openplotterI2cRead.py and openplotterI2c.py and I will amend it.
Or you can do it by yourself based on attached files and instructions above Wink
Reply
#10
Getting close- thankyou again for your patience.  
-->I included my two file( OpenplotterI2c.py and OpenplotterI2cRead.py ), and had updated per your instructions.
-->I installed VCNL4020 driver
--> No errors on other I2C devices on Signal K this time, they work great(BME280 for example)- before this was not the case.

However, I do not see any data coming through for Adafruit VCNL4020, just other devices.  Not sure why Signal K is not reading the values.  I have included the following-

- Pics of I2C and Signal K Data
-OpenplotterI2c.py and OpenplotterI2cRead.py

Let me know if you have thoughts???


Attached Files Image(s)
   

.zip   openplotterI2c-compressed.zip (Size: 11.51 KB / Downloads: 52)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)