I am trying to create a new module.
I have already tested this sensor with custom py code.
But this is my first time with mycodo input module.
I am using an Adafruit driver to comunicate with the module.
I have already added custom measurements to the Mycodo. And I have added this module via browser using the page “Import Input Module”
But when I try to setup it, it ask for the dependency, that I have already tried to install already when trying to install this module:
Install Dependencies for APDS-9960
There were unmet dependencies encountered when adding the following device: APDS-9960 (APDS9960)
Dependencies not installed: adafruit-circuitpython-apds9960
To install these dependencies, click the Install button below and wait for the install to complete before attempting to add the device again. Note that the frontend and the backend will be restarted following the install to allow detection of the newly-installed modules.
Then I click Install:
[2022-05-10 02:34:11] Dependency installation beginning. Installing: adafruit-circuitpython-apds9960
[2022-05-10 02:34:12]
[2022-05-10 02:34:12] #### Installing/updating adafruit-circuitpython-apds9960 (pip-pypi)
[2022-05-10 02:34:17] Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
[2022-05-10 02:34:17] Requirement already satisfied: adafruit-circuitpython-apds9960 in ./env/lib/python3.9/site-packages (3.1.1.dev4+gc7dc592)
[2022-05-10 02:34:19] Requirement already satisfied: adafruit-circuitpython-busdevice in ./env/lib/python3.9/site-packages (from adafruit-circuitpython-apds9960) (5.1.8)
[2022-05-10 02:34:19] Requirement already satisfied: adafruit-circuitpython-register in ./env/lib/python3.9/site-packages (from adafruit-circuitpython-apds9960) (1.9.8)
[2022-05-10 02:34:19] Requirement already satisfied: Adafruit-Blinka in ./env/lib/python3.9/site-packages (from adafruit-circuitpython-apds9960) (7.3.0)
[2022-05-10 02:34:19] Requirement already satisfied: Adafruit-PureIO>=1.1.7 in ./env/lib/python3.9/site-packages (from Adafruit-Blinka->adafruit-circuitpython-apds9960) (1.1.9)
[2022-05-10 02:34:19] Requirement already satisfied: rpi-ws281x>=4.0.0 in ./env/lib/python3.9/site-packages (from Adafruit-Blinka->adafruit-circuitpython-apds9960) (4.3.4)
[2022-05-10 02:34:19] Requirement already satisfied: pyftdi>=0.40.0 in ./env/lib/python3.9/site-packages (from Adafruit-Blinka->adafruit-circuitpython-apds9960) (0.54.0)
[2022-05-10 02:34:19] Requirement already satisfied: adafruit-circuitpython-typing in ./env/lib/python3.9/site-packages (from Adafruit-Blinka->adafruit-circuitpython-apds9960) (1.6.0)
[2022-05-10 02:34:19] Requirement already satisfied: RPi.GPIO in ./env/lib/python3.9/site-packages (from Adafruit-Blinka->adafruit-circuitpython-apds9960) (0.7.1)
[2022-05-10 02:34:19] Requirement already satisfied: sysv-ipc>=1.1.0 in ./env/lib/python3.9/site-packages (from Adafruit-Blinka->adafruit-circuitpython-apds9960) (1.1.0)
[2022-05-10 02:34:19] Requirement already satisfied: Adafruit-PlatformDetect>=3.13.0 in ./env/lib/python3.9/site-packages (from Adafruit-Blinka->adafruit-circuitpython-apds9960) (3.22.1)
[2022-05-10 02:34:19] Requirement already satisfied: pyserial>=3.0 in ./env/lib/python3.9/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-apds9960) (3.5)
[2022-05-10 02:34:19] Requirement already satisfied: pyusb!=1.2.0,>=1.0.0 in ./env/lib/python3.9/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-apds9960) (1.1.1)
[2022-05-10 02:34:27] End install of adafruit-circuitpython-apds9960
[2022-05-10 02:34:27]
[2022-05-10 02:34:27] #### Setting permissions
[2022-05-10 02:34:31] #### Dependencies installed. Restarting frontend and backend...
[2022-05-10 02:34:52] #### Dependency install complete.
I am stuck in this loop with my custom Input module
My module is in here:
# coding=utf-8
import copy
from mycodo.inputs.base_input import AbstractInput
def constraints_pass_measurement_repetitions(mod_input, value):
"""
Check if the user input is acceptable
:param mod_input: SQL object with user-saved Input options
:param value: integer
:return: tuple: (bool, list of strings)
"""
errors = []
all_passed = True
# Ensure 1 <= value <= 1000
if value < 1 or value > 1000:
all_passed = False
errors.append("Must be a positive value between 1 and 1000")
return all_passed, errors, mod_input
# Measurements
measurements_dict = {
0: {
'measurement': 'color_red',
'unit': '16_bit_color'
},
1: {
'measurement': 'color_green',
'unit': '16_bit_color'
},
2: {
'measurement': 'color_blue',
'unit': '16_bit_color'
},
3: {
'measurement': 'color_clear',
'unit': '16_bit_color'
},
4: {
'measurement': 'proximity_IR',
'unit': 'eight_bit_color'
},
5: {
'measurement': 'movement',
'unit': 'unitless'
}
}
# Input information
INPUT_INFORMATION = {
'input_name_unique': 'APDS9960',
'input_manufacturer': 'Broadcom',
'input_name': 'APDS-9960',
'input_library': 'Adafruit_CircuitPython_APDS9960',
'measurements_name': 'RGB_Distance_Movement',
'measurements_dict': measurements_dict,
'url_manufacturer': 'https://www.broadcom.com/products/optical-sensors/integrated-ambient-light-and-proximity-sensors/apds-9960',
'url_datasheet': 'https://docs.broadcom.com/docs/AV02-4191EN',
'url_additional': 'https://learn.adafruit.com/adafruit-apds9960-breakout',
'url_product_purchase' : 'https://www.adafruit.com/product/3595',
'dependencies_module': [
# ('pip-pypi', 'Adafruit_GPIO', 'Adafruit-GPIO==1.0.3'),
('pip-pypi', 'adafruit-circuitpython-apds9960', 'adafruit-circuitpython-apds9960'),
],
'interfaces': ['I2C'],
'i2c_location': ['0x39'],
'i2c_address_editable': False,
'options_enabled': [
'i2c_location',
'period',
'pre_output'
],
'options_disabled': ['interface'],
'custom_commands': [
{
'type': 'message',
'default_value': 'The APDS-9960 is a specialized chip that detects hand gestures, proximity and ambient light color over I2C.'
'The APDS9960 from Avago Technologies has an integrated IR LED and driver, along with four directional photodiodes that sense reflected IR energy from the LED. Its proximity detection feature allows it to measure the distance an object is from the front of the sensor (up to a few centimeters) with 8 bit resolution.'
'Since there are four IR sensors, you can measure the changes in light reflectance at each of the cardinal locations over time and turn those changes into gestures. Our interface library can detect directional gestures (left to right, right to left, up to down, down to up).'
'The Color and Ambient Light Sense detection feature provides red, green, blue and clear light intensity data. Each of the R, G, B, C channels have a UV and IR blocking filter and a dedicated data converter producing16-bit data simultaneously. This architecture allows applications to accurately measure ambient light and sense color'
},
]
}
class InputModule(AbstractInput):
"""Read Colors as Red, Green, Blue and Clear(no filter) as 16 bits Values
Proximity are read as 8 bits values, by an IR sensor
It can also sense movements as up/down/left/wright directions using the same IR sensor.
The RGB sensor can operate independtly from the IR sensor, but you can not disable the IR sensor to read movement nor distance.
Also, unfornetly, it is not possible to read ambient IR emission using this sensor.
"""
def __init__(self, input_dev, testing=False,):
super().__init__(input_dev, testing=testing, name=__name__)
self.adc = None
self.adc_gain = None
self.measurements_for_average = None
if not testing:
self.setup_custom_options(
INPUT_INFORMATION['custom_options'], input_dev)
self.try_initialize()
def initialize(self):
from adafruit_apds9960.apds9960 import APDS9960
import board
try:
self.apds = APDS9960(self.input_dev.i2c_bus)
self.set_sensor_settings()
except Exception:
self.logger.exception("Exception while initializing sensor")
def set_sensor_settings(self):
if self.is_enabled(0) or self.is_enabled(1) or self.is_enabled(2) or self.is_enabled(3):
self.enabled_rgb = True
self.apds.enable_color = True
self.logger.debug("APDS RGBC sensor enabled")
else:
self.apds.enable_color = False
self.enabled_rgb = False
self.logger.debug("APDS RGBC sensor disabled")
if self.is_enabled(4) or self.is_enabled(5):
self.apds.enable_proximity = True
self.enabled_IR = True
self.logger.debug(f"APDS IR sensor Enabled")
if self.is_enabled(5) == True:
self.apds.enable_gesture = True
self.enabled_gestures = True
self.logger.debug(f"APDS gesture sensor Enabled")
else:
self.apds.enable_gesture = False
self.enabled_gestures = False
self.logger.debug(f"APDS gesture sensor Disabled")
else:
self.apds.enable_proximity = False
self.enabled_IR = False
self.logger.debug("APDS IR sensor disabled")
# Throw out first measurement of Atlas Scientific sensor, as it may be prone to error
self.get_measurement()
def get_measurement(self):
if not self.apds.color_data_ready:
self.logger.error("Error 101: Device not set up. See https://kizniche.github.io/Mycodo/Error-Codes#error-101 for more info.")
return
return_string = None
self.return_dict = copy.deepcopy(measurements_dict)
# Read device
if self.enabled_rgb:
red, green, blue, clear = self.apds.color_data
self.logger.debug("Device Returned: R:{} G:{} B:{} C:{}".format(red, green, blue, clear))
self.value_set(0, int(red))
self.value_set(1, int(green))
self.value_set(2, int(blue))
self.value_set(3, int(clear))
if self.enabled_IR:
distance = apds.gesture()
self.value_set(4, int(distance))
if self.enabled_gestures:
movement = apds.proximity
if movement == 1:
self.value_set(5, "up")
if movement == 2:
self.value_set(5, "down")
if movement == 3:
self.value_set(5, "left")
if movement == 4:
self.value_set(5, "right")
return self.return_dict
System info:
Mycodo Version: 8.13.9
Python Version: 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
Database Version: b354722c9b8b
Daemon Status: Running
Daemon Process ID: 3606
Daemon RAM Usage: 96.964 MB
Daemon Virtualenv: Yes
Frontend Process ID: 499
Frontend RAM Usage: 116.164 MB
Frontend Virtualenv: Yes
At page https://bioreactor3.local/admin/dependencies/ i get:
Error 500: Internal Server Error
Something bad happened but it's probably not your fault. Letting the developers know about these issues is crucial to supporting Mycodo. Please submit a new issue on GitHub with the following diagnostic information and error traceback (copy the entire traceback):
Version: 8.13.9
Database: b354722c9b8b
Model: Raspberry Pi 3 Model B Rev 1.2
Release:
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Firmware:
b''
Error (Full Traceback):
Traceback (most recent call last):
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_restx/api.py", line 672, in error_router
return original_handler(e)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_login/utils.py", line 277, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
File "/home/pi/Mycodo/mycodo/mycodo_flask/routes_admin.py", line 383, in admin_dependencies
if each_dep not in unmet_list:
TypeError: unhashable type: 'list'