-
Notifications
You must be signed in to change notification settings - Fork 42
Added MCP3008 Node Support #1
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
Conversation
Created a new ADCMCP3008Worker (workers/adc_worker.py) simila to SensorWorker to control sensors connected to GPIO via the MCP3008 analog-digital converter (e.g. analog Soil Moisture Sensor). Split "sensors/" into "sensors/arduino" and "sensors/MCP3xxx" for the new different Node Types. Created a new Node setting "type" to select original node ("arduino") or the new "ADC-MCP3008" Node and updated the mudpi.config.example with an example accordingly.
This is excellent. I will review and work on getting this merged in. More updates in the works as well. Thank you for your support! |
I had time to review this request and test it on my demo units. This is a great addition to the library @P33ry. I also have some other updates in the works I may push this weekend. Your PR format is good and I was able to install the needed libraries to support the update. I agree there should be an updated package/dependancies list, I will work on that. The MCP3xxx is interesting and I like expanding node support. I would like to look into more of these options. The folder restructure is also an acceptable change. There is some refactor and cleanup on the list that will help with removing some old testing code and legacy files. In terms of testing the relays there are scripts in the tools folder that I don't think have been fully documented on the site yet. There are three scripts named However you would want to boot up the TestingI tested the changes on a demo unit and the SensorWorker class is working fine. Action ItemsAll changes approved and will be merged. |
That's great to hear and thanks for the feedback @olixr ! The current state of MudPi seems not operational except for debugging & development purposes. Is that correct? I've since added code in my fork to get my setup to switch the relay live on sensor readings. I assume such functionality is part of the update you mentioned? Best of luck to you and MudPi! |
Its operational but not to the full extent I have in plans. My own MudPi systems have been running on various versions for the past 2 years now. The triggering of relays and solenoids has been through manual controls (i.e. a dashboard). I have a scheduler that runs in the background and would also toggle the relays on a time basis. (supervisor running script that fires redis events) The plan of what I am working on is better link-able actions. This could be manual or automated based on a number of conditions like sensor readings or schedules. Part of my system also involves this web app that I have not released much publicly yet. This web app enhances the open source core with additional features like my manual controls and scheduling. Currently in the works I am working to bring some more linked actions to the core and ways to configure them. This also includes adding button support to have actions fired off bases on the button presses. Additionally I want to update the scheduling I have for relays to involve conditional triggers like sensor readings and other factors. Part of the challenge here was first designing a format that makes sense to allow this feature while also being configurable enough for folks to implement a wide array of uses. As I get further here I would like to have a better shared roadmap with planned features and keep more frequent developer updates. I am sending out a newsletter once a month to include some of these developments and I have a twitter page for the project to share progress of work. Thank you again for your help on the core and I plan to get more released soon here. Also I made a discord server to folks to keep in touch as well. Please feel free to join the tech talks with me. https://discord.gg/daWg2YH |
A bit of refactoring and linting
Greetings,
I've added support for reading sensors using the MCP3008 (an Analog-to-Digital Converter) to MudPi as a different Node Type. This way one can connect analogue sensors directly to the RaspberryPi's GPIO after they went through the MCP3008 without involving an Arduino.
An example to the MCP3008 usage.
New SensorWorker class
I created an ADCMCP3008Worker (workers/adc_worker.py) similar to the SensorWorker class it dynamically imports the sensor classes, initializes them and reads them when running. Basically the same as the original SensorWorker but also taking care of initializing the mcp chip.
To do this cleanly I've used several new imports. They should all be covered by the packages:
They are available over pip for me.
Are the dependencies listed somewhere? A requirements.txt for pip might be useful.
Node Types
I understood MudPi expected the Soil Sensor to come from a node and Pi_Sensors to be only for optional (digital) sensors and not core ones like the Soil Sensor. Therefore I've introduced Node Types where I moved the original nodes to the type "arduino" and added "ADC-MCP3008"
For that purpose I've also rearranged the _sensors_ folder so that the original sensor classes (now under sensor/arduino) and the sensor classes for reading from the mcp3008 over SPI (sensor/MCP3xxx) aren't mixed up.
Created a new Node setting "type" to select original node ("arduino") or the new "ADC-MCP3008" Node and updated the mudpi.config.example with examples accordingly.
Testing
Tested changes with:
Also wanted to test the reaction with a Relay but haven't seen the right place to trigger switch events for it yet (or how to actually trigger a pump?) Is there code to trigger these events?
I'm also unable to fully test the SensorWorker class. I had to edit the method dynamic_sensor_import to fit the changed folder structure but don't have an Arduino.
Note
Critique, correction, etc. is welcome for both code and PR format (first time to make one).