Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4775

Automation, sensing and robotics • Sequent microsystems 8 relay hat weirdness

$
0
0
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:

Code:

8relind 0 test
Everything works, here's the result

Code:

Are all relays and LEDs turning on and off in sequence?Press y for Yes or any key for No....yRelay Test ............................ PASS
Using the command line, I test the individual relays using: (x is the relay number between 1 and 8)

Code:

8relind 0 write x  on
I check the relay, each one is working fine.
Then I turn it off that relay.

Code:

8relind 0 write x  off
Here's a simple python script that only looks at one relay at a time.

Code:

#!/usr/bin/env python3# Make sure you "chmod +x main.py" or else it won't start by itself from the command line.import osimport lib8relindfrom getkey import getkeyrelay = 0def 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 programprint("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)    breakif 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.

Code:

b2400@b2400:~/Desktop/b2400 $ python test6.pyTEST 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.

Relay entered Relay activated
1..............................1
2..............................7
3..............................2
4.............................. 7
5..............................4
6..............................5
7..............................3
8..............................Error (below)

Code:

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

Code:

lib8relind.set(0, relay, 1)
to

Code:

os.system("8relind 0 write 1  on")
(changing the "1" to the relay #) it works fine.

I haven't had any success from contacting Sequent Microsystems. Anyone have any ideas?

Statistics: Posted by gwfami — Thu Oct 10, 2024 1:25 am



Viewing all articles
Browse latest Browse all 4775

Trending Articles