Raspberry Pi Coop Automation

This thread is to show how I did my coop automation. I'm going to start as basic as I can. I have tried Arduino's and ESP8266 and other control devices and finally settled in with the Raspberry Pi 3B as my control of choice. The programming is in Python which to me is a bit easier to read than C which you must use for the Arduino and other devices that support Arduino code.

Some things to know up front, I do all my programming on a Linux PC. If you connect a keyboard, mouse and monitor to the Raspberry Pi you can program directly on the Rpi (Raspberry Pi). The Rpi uses a Linux Operating System, nothing to be afraid of, it just works better. The Rpi needs a connection to the Internet at bootup to get the current date and time, the Rpi doesn't have an onboard real time clock or battery/capacitor backup for date and time. The Rpi is a SBC (Single Board Computer), yes it's a fully functioning PC with USB ports, HDMI monitor connection and 40 pins that are used for I/O (Input/Output), these are use to connect the Rpi to the real world. You use the I/O to run your motor, turn lights on and off, get input from limit switches etc. The Rpi has some special pins, I2C or One Wire which can connect to things like temperature sensors (you can connect more than one as they have a unique address). The Rpi I/O is 3.3vdc so you need to be careful and select 3vdc relays, while 5v relays may work it's better to use the 3v versions.
View attachment 2392585

Python is a programming language not the snake. The most simple program you could run is howdy.py
Python:
#!/usr/bin/python3
print("Howdy")

The first line is the shebang line that tells the system what to use to run the code.
The second line is a print statement that does what it looks like it should do.
To run the program the executable permission must be set. The easy way is to right click on the file in the file manager and select permissions then check off executable.
Then open a terminal in the same directory and type in ./howdy.py the ./ is needed otherwise the file will not be found.
View attachment 2392591

You can also test snippets of code in a terminal without creating a file and I do that all the time to just test syntax and see my results. To start a Python session just type in python3 and press enter. Then you can test your code snippet.
View attachment 2392596

Time to start my day, next up is the event loop and you will need one...

Got ahead of myself...

JT
This is fabulous!!! Thank you! My son is in second year of Computer engineering at university and we have Raspberry pi and Arduino stuff here at home. Methinks I will put the kid to work!!
 
I should have put a ReadMe.txt file in the zip but forgot.

Copy the 3 files to your bin directory and make sure coop3 is executable then run it from a terminal. If your missing a library look in the coop3 file for the sudo apt install line for that library and run that in a terminal.

BTW, you should run the following commands in a terminal from time to time to keep everything updated.

Code:
sudo apt update
sudo apt dist-upgrade

I've been running the door control and have added light control so I'll push that to the github repo in the morning.

JT

@jthornton well, I ended up opening this thread in cromium, on my Rpi via vnc, downloaded the files to my Rpi, (download folder, extracted them "here")
moved them to the bin folder, made coop3 executable
ran it in terminal,
had to install astral library,
then had to install PyQt5 library,
NOW stuck at
"rob@coop:~ $ coop3
libEGL warning: DRI2: failed to authenticate
qt5ct: using qt5ct plugin
qt5ct: D-Bus global menu: no
Traceback (most recent call last):
File "/home/rob/bin/coop3", line 204, in update
if not doorOpen and self.doorStatus not in closeList:
NameError: name 'closeList' is not defined
Aborted"
 
"rob@coop:~ $ coop3
libEGL warning: DRI2: failed to authenticate
qt5ct: using qt5ct plugin
qt5ct: D-Bus global menu: no



Traceback (most recent call last):
File "/home/rob/bin/coop3", line 204, in update
if not doorOpen and self.doorStatus not in closeList:
NameError: name 'closeList' is not defined
Aborted"

This is a typo, sorry line 204 should be self.closeList

JT
 
@jthornton
I couldn't seem to get the file... on Windows, I can be on github, download the files, cant get the files on Rpi without removing sd card putting it in windows PC.
On the Rpi, I went to github, see your files, cant download them... I did copy and paste the code to the RPI coop3 file... there has to be an easier way... help!

After the copy and paste, and trying to run coop3, I now get
"rob@coop:~ $ coop3
Traceback (most recent call last):
File "/home/rob/bin/coop3", line 33, in <module>
from rpi_utilities import ledfade
ImportError: cannot import name 'ledfade' from 'rpi_utilities' (/home/rob/bin/rpi_utilities.py)"
 
I use FileZilla to transfer files from PC to PC or to my website.

Why not just work in the Rpi? Hook a monitor, keyboard and mouse to the Rpi and download the files from my github repo.

I probably should just create a new repo for Coop 3 that way you can just get a zip file from github without all the other coops.

JT
 
I use FileZilla to transfer files from PC to PC or to my website.

Why not just work in the Rpi? Hook a monitor, keyboard and mouse to the Rpi and download the files from my github repo.

I probably should just create a new repo for Coop 3 that way you can just get a zip file from github without all the other coops.

JT
@jthornton doesn't VNC do the same thing... monitor, keyboard, mouse...( would have to buy moitor, keyboard, mouse...)

I did/do work in the Rpi, on github repo, I do not see the "copy" code icon. that is why I was asking easier way/what am I missing?

I do want to learn the right way...
 

New posts New threads Active threads

Back
Top Bottom