Hi experts! Hoping you can help me figure this out.
Using RPi.GPIO v0.7.0 (apparently the latest), python 3.7.3, pip 18.1, Django 3.1.5 - all installed on a Raspberry Pi 4.
As one of my initial tests, I created a python script to simply turn on/off a couple of pumps through the Raspberry Pi GPIO pins. That works just fine. My next step was to incorporate that logic in a view that I could invoke though an HTML page - my application… The logic is a forever loop with a keyboard interrupt to stop the program.
My application is a set of models that contain information that I use to control how much water flows through a pump. The goal is to use information in tables to drive the behavior of these pumps.
I created a virtualenv for my Django application, constructed a models.py, views.py, static HTML/CSS, urls.py, and updated settings.py.
Using django, I am able to successfully perform CRUD ops on my database tables, so from that perspective everything is working how I want it to.
I added an addition definition in my views.py file to use RPi.GPIO to control a couple of pumps. From my HTML page, I can select a link that causes that view to be invoked. The actual code to drive the GPIO pins is the same as the one I used in my earlier tests (that way I can ensure no odd logic errors creeped in); ultimately of course the goal is to use tables that contain information on how to drive these pumps.
In my view, I used a for loop to drive the pumps through several iterations. Note this is not what will happen in the finished app, but baby steps…
Now here’s the issue. I can hear/feel the first of two pumps click once like it’s trying to start, but that’s it. I added a few print() statements in the view and I can see the output in my runserver console output, so I am confident that the code is being properly exercised. But I am befuddled why the pump motors won’t work for the duration I programmed.
Now the really puzzling part…
The same logic outside the virtual env workss I expect, i.e., the pump motors start and stop at the prescribed intervals.
It seems to me that there is some weird discrepancy in how the RPi.GPIO module behaves in a virtual env versus outside, but I am not clear how I can figure out what is going on.
I did a “pip freeze” in the venv and outside it. I saw that there are a significant number of modules in the installation outside the venv compared to that inside the venv. I guess that’s something I need to explore further and see if there are additional modules that need to be installed inside the venv.
In the meantime, any diagnostic tips that you could share with me will be gratefully appreciated.
This is my first time using this forum, so my apologies if I did something against the rules.!!