I have a RPi 4b which has a sequent microsystems 8 relay hat and on top of that it has lcd touchscreen. I just connected it to an Adafruit Feather RP2040 using a USB bus. The feather is monitoring an encoder so the Pi doesn't miss counts. Got the encoder working just fine, but now I have a weird issue popping up.
The relay can be ran either from code or the command line. Using python, I have coded the relays numerically, doing things in the order needed.
I have ran various code using all of the relays before connecting the Feather, and everything worked perfectly.
Now anything coded for the relay acts very strange.
So I reinstalled the lib8relind library, and it still is goofy.
Here's what it does.
From the command line, I test all the relays:
Everything works
Using the command line, I test the individual relays using: (x is the relay number between 1 and 8)
Each one is working fine.
Here's a simple python script that only looks at one relay at a time.
Can't get much simpler then that.
When ran, the code returns this, pretty simple.
Here's where it gets really strange when using the python code shown above. These results were verified from both the "relay active" blue light and from the relays themselves.
Relay entered Relay activated
1..............................1
2..............................7
3..............................2
4.............................. 7
5..............................4
6..............................5
7..............................3
8..............................Error (below)
Now if I change the python code from
to
(changing the "1" to the relay #) the python works fine.
Anyone have any ideas?
The relay can be ran either from code or the command line. Using python, I have coded the relays numerically, doing things in the order needed.
I have ran various code using all of the relays before connecting the Feather, and everything worked perfectly.
Now anything coded for the relay acts very strange.
So I reinstalled the lib8relind library, and it still is goofy.
Here's what it does.
From the command line, I test all the relays:
8relind 0 test
Everything works
Using the command line, I test the individual relays using: (x is the relay number between 1 and 8)
8relind 0 write x on
and 8relind 0 write x off
Each one is working fine.
Here's a simple python script that only looks at one relay at a time.
#!/usr/bin/env python3
# Make sure you "chmod +x main.py" or else it won't start by itself from the command line.
import os
import lib8relind
from getkey import getkey
relay = 0
def test():
lib8relind.set(0, relay, 1)
def shutdown():
# make sure all the relay is off
lib8relind.set(0, relay, 0)
# now shut the program off
exit(0)
# Runs the program
print("TEST")
print(" ")
print("Enter a relay # (1-8)")
print(" ")
print("<any other key will end the program>")
a = ""
while True: # Breaks when key is pressed
key = getkey()
print(key)
break
if int(key) in range(1, 8):
try:
while True:
relay = int(key)
test()
except KeyboardInterrupt:
lib8relind.set(0, relay, 0)
shutdown()
else:
shutdown()
Can't get much simpler then that.
When ran, the code returns this, pretty simple.
b2400@b2400:~/Desktop/b2400 $ python test6.py
TEST
Enter a relay # (1-8)
<any other key will end the program>
1
Here's where it gets really strange when using the python code shown above. These results were verified from both the "relay active" blue light and from the relays themselves.
Relay entered Relay activated
1..............................1
2..............................7
3..............................2
4.............................. 7
5..............................4
6..............................5
7..............................3
8..............................Error (below)
Traceback (most recent call last):
File "/home/b2400/Desktop/b2400/test6.py", line 46, in <module>
shutdown()
File "/home/b2400/Desktop/b2400/test6.py", line 16, in shutdown
lib8relind.set(0, relay, 0)
File "/home/b2400/lib/python3.11/site-packages/lib8relind/__init__.py", line 47, in set
raise ValueError('Invalid relay number!')
ValueError: Invalid relay number!
Now if I change the python code from
lib8relind.set(0, relay, 1)
to
os.system("8relind 0 write 1 on")
(changing the "1" to the relay #) the python works fine.
Anyone have any ideas?