-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request to add Adafruit NeoKey 1x4 input board #1353
Comments
How were you envisioning it integrating? |
im wanting to use the switches to start functions, and change what is displayed on a different i2c screen. neopixels are just a added bonus, they could be used as status led's or to show that the button was pressed and recognized you can also have 8 of these together, so 32 total keys from one i2c bus like be able to have a button to trigger some of the input actions on this page https://kizniche.github.io/Mycodo/Inputs/#input-actions the more useful ones would be to trigger the supported actions which is where i would use it the most https://kizniche.github.io/Mycodo/Supported-Actions/ button to capture a pic from all the cameras / execute command: shell / display backlight / pause would be the big ones i can think of right away. im not currently able to access my mycodo system so not able to really go through all the different sections to see where it is useful, but i envision using it so i dont have to go into the webui when i do maintenance, i can do it by buttons. -pause/enable everything |
I could throw together a simple function that you could execute one or more actions when a button is pressed. |
that would work for almost all of my use cases, and i think i can add a lot with that. the only other thing is if there would be a way to address the neoled's too. also need to be able to change the i2c address, will probably end up using more then 1 example for 1 button - when button is pressed, runs action, then flashes the neoled while that is active. and push the button again to undo if its not one based on a timer. |
All three sound doable. I'll let you know when I have a module for you to test. |
cool, thanks |
Attached below is a module to test. Rename from txt to py and import as a Function. You will also need to upgrade to master to be able to use Actions for Custom Functions and see the Action ID needed to use the new Function. The instructions after creating the Function should be sufficient to use it. I won't detail how to use it to see if the instructions can stand on their own. Let me know if you run into any issues or can't get it working. Remember to enable the Function debug logging when testing to see all debug messages in the log. |
Thank you for that, got it installed. when i push a button it just lights up the LED underneath but nothing else. below is the error log. just have all buttons mapped to deactivate a function for testing. your assistance here is greatly appreciated ``` AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:46,916 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID dd3d8ad0
Traceback (most recent call last):
File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:46,928 - INFO - mycodo.function.function_adafruit_neokey_01_8df033ec - Button 4
2023-12-10 15:31:47,461 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID 8ceb33e8
Traceback (most recent call last):
File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:47,473 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID d05c3d60
Traceback (most recent call last):
File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:47,486 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID dd3d8ad0
Traceback (most recent call last):
File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id' |
Here is an updated module. Delete all of this Function type, then delete the Function module, then import this new Function module. |
Wait, you didn't add the correct Function. That's one of the built-in functions. Your screenshot is of the Execute Actions Function, not the Device: Adafruit Neokey (Button Executes Actions) Function. |
the screenshot was just the execute actions, to show the id's in changing the settings in it, now the method page wont load giving 500 error. i must have done something stupid. reinstalling mycodo and will test out the new file Error (Full Traceback): Traceback (most recent call last): |
The IDs should show on all Functions. You should be only using the Function I created. |
What did you do in the time between it working and not working? |
all i did was change the ID's in the new module to random numbers, thinking that using the id's from the execute actions function was causing the issue |
i was just showing with that screenshot that i didnt make a error copying the action id's into the boxes in the new module |
It would be most beneficial if you can give steps to reproduce any errors you get. If you found an error that crashes the frontend, that is a major issue. |
i am working on trying to reproduce it now, as i could not load the method page, not much i could do other then reinstall. which i am doing now. if i can reproduce it, i will provide steps all i did, was change the ids in the new module, not sure how that changed other things. |
pretty sure i see what causes it, fresh install, installed the new module, and clicked on add action in the module itself, after adding a module to deactivate a controller in the action itself it gave the 500 error when i went to load the main functions page /Error (Full Traceback): Traceback (most recent call last): |
Got it somewhat working. all the activate and deactivate does is turn on or off the ph and ec regulation. the buttons work to turn it on and off. the only issue is, when using the deactivate action, the led never turns off. when using activate the led turns on for 1 second. if there is no action tied to a button it also turns on the LED and it does not turn off on any future button presses. looks like the behaviour when deactivating a controller is leaving the led on, maybe because it just sees the controller deactivated so its duration never ends? if i go and turn on the controller the led does not turn off I think the best use for the LED's on this board, is to only have them light up when the corresponding buttons actions are being ran, or for a set time after the last action happens. logs look good now 023-12-10 16:19:07,905 - INFO - mycodo.function.function_adafruit_neokey_01_38392045 - Button 2 Found bug reproduction steps: add neokey function add controller:deactivate under measurement settings do not need to add anything specific under, just save as blank and then try to load the functions page and you get 500 error. i think the fix for this is just removing the measurement settings area as it is not needed for the neokey function, i was only playing with it at first as part of my troubleshooting |
I was able to replicate the error. Looking into a fix. |
Fixed the error. You'll need to upgrade to master to get that fix. And to fix the LED on all but the first button not working, change the last line of the module from:
to
The current behavior is to only have the LED on when the actions are executing. You are likely choosing short-lived actions, why the LED goes off quickly. |
all working now, and the code change worked. there are cases where having it be enabled for total duration would be helpful, would it be difficult to be able to select per key if it is pixels[0] to pixels[key] |
What do you mean by enabled for total duration? The LED stays on for as long as it takes the Actions to complete. I also just majorly refactored the Function Module to utilize another method for organizing configuration data so it's easier to work with in the code. And added a delay to keep the LED on after all actions have completed. I also made the key press spawn a thread to complete the actions, so you can now have multiple key action sets running at the same time and you don't have to wait for the first to finish before starting the next. |
i did upgrade to master. the screentshot was just of the execute actions of the functions i was going to use, to show the id's
i just misunderstood the code change. what you did is perfect, the new changes make it very clear what is happening. I would say it is complete for at least my needs now. Thank you very much for doing this |
I'm working on allowing the color of each key to be set |
if your working on that side, is it possible to have a start colour, then it change colour on its last action? like a colour change to signify when it is on its last action. just a thought |
Here is an update that adds LED colors for resting, running, and last action running. Let me know if it works. |
very nice just tested and it all works. only thing i would add, is since there is a resting led state now, maybe add a brightness option to resting so you can have the light off on rest |
I don't think brightness can be set. Here is a version that turns the LED off when set to 0. |
This version may or may not work to set the brightness. |
yes i am following that process, delete the function, then the function module, then importing and adding new function |
here is the error log from the most
here is the error log from this one, buttons still do not seem to do anything, have to go to the old file again 2023-12-10 19:47:07,584 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Parsed Action IDs: OrderedDict([(0, ['8e4a9986']), (1, ['34505ec9']), (2, []), (3, [])])
2023-12-10 19:47:07,584 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Brightness: 0.2
2023-12-10 19:47:07,585 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 19:47:08,122 - DEBUG - mycodo.controllers.controller_function_eed44e0c - loop() not found
2023-12-10 19:47:08,124 - DEBUG - mycodo.controllers.controller_function_eed44e0c - listener() found
2023-12-10 19:47:08,125 - DEBUG - mycodo.controllers.controller_function_eed44e0c - Starting listener() thread
2023-12-10 19:47:08,126 - INFO - mycodo.controllers.controller_function_eed44e0c - Activated in 910.0 ms
2023-12-10 19:47:13,142 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 2
2023-12-10 19:47:13,663 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 1
2023-12-10 19:47:18,630 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 1
2023-12-10 19:47:19,152 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 0
2023-12-10 19:47:25,412 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 2
2023-12-10 19:47:26,451 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 1
2023-12-10 19:47:27,404 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 1 |
Now we're getting somewhere. Try this version. I suspect we'll see something strange in this one. |
Here are the logs from that one 2023-12-10 19:54:10,793 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Parsed Action IDs: OrderedDict([(0, ['34505ec9']), (1, ['8e4a9986']), (2, []), (3, [])])
2023-12-10 19:54:10,794 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Brightness: 0.2
2023-12-10 19:54:10,794 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 19:54:11,332 - DEBUG - mycodo.controllers.controller_function_b6dc24df - loop() not found
2023-12-10 19:54:11,332 - DEBUG - mycodo.controllers.controller_function_b6dc24df - listener() found
2023-12-10 19:54:11,333 - DEBUG - mycodo.controllers.controller_function_b6dc24df - Starting listener() thread
2023-12-10 19:54:11,334 - INFO - mycodo.controllers.controller_function_b6dc24df - Activated in 712.1 ms
2023-12-10 19:54:12,799 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Key 2
2023-12-10 19:54:13,327 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Executing Actions for Key 2
2023-12-10 19:54:18,227 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Key 1
2023-12-10 19:54:18,749 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Executing Actions for Key 1 here are the logs from the last version that was working 2023-12-10 19:51:34,573 - INFO - mycodo.controllers.controller_function_11107a50 - Deactivated in 230.7 ms
2023-12-10 19:51:41,250 - DEBUG - mycodo.controllers.controller_function_11107a50 - loop() not found
2023-12-10 19:51:41,251 - DEBUG - mycodo.controllers.controller_function_11107a50 - listener() found
2023-12-10 19:51:41,252 - DEBUG - mycodo.controllers.controller_function_11107a50 - Starting listener() thread
2023-12-10 19:51:41,262 - INFO - mycodo.controllers.controller_function_11107a50 - Activated in 731.0 ms
2023-12-10 19:51:51,647 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 1
2023-12-10 19:51:52,401 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message: Deactivate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:51:52,699 - INFO - mycodo.controllers.controller_function_4671a538 - Deactivated in 210.6 ms
2023-12-10 19:52:00,551 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 2
2023-12-10 19:52:01,247 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message: Activate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:52:01,691 - INFO - mycodo.controllers.controller_function_4671a538 - Activated in 356.7 ms
2023-12-10 19:52:07,173 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 1
2023-12-10 19:52:07,866 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message: Deactivate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:52:08,205 - INFO - mycodo.controllers.controller_function_4671a538 - Deactivated in 245.7 ms |
I understand. There's nothing I can tell between the versions that would affect anything. THe only thing I cna do is give you versions to try, since i don't have the device. |
This version I threw in a slew of debug lines. |
apologies, didnt know if you saw my message on the old version working. here are the new logs. 2023-12-10 20:01:40,956 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Parsed Action IDs: OrderedDict([(0, ['34505ec9']), (1, ['8e4a9986']), (2, []), (3, [])])
2023-12-10 20:01:40,956 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Brightness: 0.2
2023-12-10 20:01:40,957 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 20:01:41,494 - DEBUG - mycodo.controllers.controller_function_d40c3f98 - loop() not found
2023-12-10 20:01:41,495 - DEBUG - mycodo.controllers.controller_function_d40c3f98 - listener() found
2023-12-10 20:01:41,495 - DEBUG - mycodo.controllers.controller_function_d40c3f98 - Starting listener() thread
2023-12-10 20:01:41,496 - INFO - mycodo.controllers.controller_function_d40c3f98 - Activated in 715.6 ms
2023-12-10 20:01:53,894 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Key 2 Pressed
2023-12-10 20:01:54,423 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Executing Actions for Key 2
2023-12-10 20:01:54,423 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - TEST00
2023-12-10 20:02:03,045 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Key 1 Pressed
2023-12-10 20:02:03,566 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Executing Actions for Key 1
2023-12-10 20:02:03,567 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - TEST00 |
oh wow, it was the easiest fix. Simple error. Should work now. |
it is working now. everything seems to be working properly. what was the issue? |
"len(list)" instead of the actual list. "list" is a type, not a variable. |
The last thing I can think of to add is to write a value of 1 to the measurement database for the channel of the key pressed, so it's recorded. We've been at it for a while, so I don't expect you to test this right away if you're done for now. Just let me know if it works if you get a chance to test it. |
I can't seem to get a key name to appear on the chart without some more in-depth refactoring, so I'm going to call it a wrap for now. Thanks for all the testing, I'll add this in my next commit to github. |
…hange deprecated threading.currentThread to threading.current_thread
The last thing I changed (and will commit soon) was figuring out how to have the key number show on measurements (such as on charts, live page, etc). I'm also going to implement an action to set the color of a neopixel at position x of a function and set this new function as the recipient module for that action (as well as the other neopixel functions). That way you can have the lights change in response to things elsewhere in the system, such as turning a key red to notify of a system issue. If anyone else has ideas for improving the functionality, let me know and we can discuss the feasibility. One thing that may be interesting (maybe a separate function) would be two sets of actions and colors per key, that when pressed will toggle between executing each set of actions. For example, press Key 1 and it deactivates Function x and turns red (or flash a color, like the flash functionality of LCD screens to indicate an issue), press Key 1 again and it activates Function x and turns green. Side note: I kind of want one of these now. It seems really useful as a device that can serve as both a status indicator and input device. |
the addon part is what i was initially envisioning, same button to turn on grow lights, then if on, the same button turns them off. thought it would be to complicated, but it does cut the need for a some of the keys down. im thinking on how to expand this to use like 4-5 of the keypads. it is a handy little thing. i love that your thinking of expanding it to be able to address the neopixels too, can replace the neopixel led strip with this and free up that wiring |
Thankfully, I refactored the system a while ago to make development much quicker by allowing all code for a function to be contained in a single file, so developing these functions is much more enjoyable than previously (editing multiple files). This makes it rather easy to implement these features, as long as you understand how the system works and options available to build a module. My only limitation is not owning the hardware, which significantly slows testing. I just bought the board, so we soon won't have to share a dozen module files to make development progress. |
with it showing the key number, how do you account for multiple devices? just have it display device name-1? |
You can already name the Function, which appears next to each measurement. I'll also work on allowing renaming the measurement so you can change the measurement name from "Key 1". |
…work with Neopixel Function, Add Actions: Neopixel Flashing On and Neopixel Flashing Off (#1353)
I just committed changes to the Neopixel Function to include the ability to flash and have the color set via the Neopixel Set Color Action (and updated the action to work with this Function). I also created Flash On and Flash Off Actions for the Neopixel Function. All code is on the master branch now, so delete any Neopixel Functions, delete the Function Module from the import page, upgrade to master, then you should have the built-in Function available. |
tested the neopixel set colour and all works as described. like the flashing option |
Great. I'm actually a little surprised it all worked on the first try, considering I couldn't test anything since I don't yet have the hardware. I also have a small update that can fix some edge cases with button presses and flashing, but I'll be committing that soon. |
I think I may change from using the single value color to the format I used previously for neopixels, the RGB string, e.g. "10, 255, 0". |
would make sense for consistency, and i believe with that 0 is still off |
I received my NeoKey 4x1 and had a chance tonight to test it with the Function. I found a bunch of bugs that I fixed and performance improvements. Just a few of the changes: it's now faster, key presses do nothing if it's already executing, there's a new shutdown color, fixed an issue with the function thread stopping, you can press another key while you have one already pressed. You can upgrade to master to get the new code. |
i like the shutdown colour option. the pressing more then one at once was something i noticed before, so glad to see you already resolved it i also found this https://www.adafruit.com/product/5157 its not i2c, so im not sure if its something that you can implement, but its basically this neokey, but any amount of keys you want. and this https://www.adafruit.com/product/5100 almost a holy grail input device in my eyes. but its USBC or UART so prob not really a feasible option |
Hi Kyle,
Found a device from adafruit that would be able to add a lot of possible functionality for people not super skilled in programming if you can add this input device. It is basically a i2c controlled mini keyboard that has 4 keyboard keys and 4 neopixels. basically a easy way to add 4 i2c controlled momentary switches to a system. It also has 8 possible i2c addresses so there is a lot of possibility here
https://www.adafruit.com/product/4980
adafruit neokey library: https://docs.circuitpython.org/projects/neokey/en/latest/
i have ordered one and been playing with it, have gotten their test code working, but getting it to work with mycodo is not working for me, with you already having neopixels added not sure if this would be complicated to sort out
The text was updated successfully, but these errors were encountered: