I’m preparing to separated tasks in python to control inputs and outputs. When I start both lights starts to do strange things, they blink without explanation.
Is there a way to avoid that?
Thanks in advance
I’m preparing to separated tasks in python to control inputs and outputs. When I start both lights starts to do strange things, they blink without explanation.
Is there a way to avoid that?
Thanks in advance
Posting the code your using would help. ;)
#RELAY CONTROL
import time
import keyboard
import automationhat as ah
if ah.is_automation_hat():
ah.light.power.on()
#ah.relay.auto_light(False)
while True:
key= input("Press key: ")
if(key==‘q’):
print(‘Exit’)
break
if(key==‘1’):
ah.relay.one.toggle()
print(‘Relay 1 toggled’)
if(key=='2'):
ah.relay.two.toggle()
print('Relay 2 toggled')
if(key=='3'):
ah.relay.three.toggle()
print('Relay 3 toggled')
#INPUTS READ
import time
import automationhat as ah
if ah.is_automation_hat():
print(ah.light.power.on())
#ah.relay.auto_light(False)
s0=ah.input.one.read()
s1=ah.input.two.read()
s2=ah.input.three.read()
while True:
key= input("Press key: ")
if(key==‘q’):
print(‘Exit’)
break
temp=ah.input.one.read()
if(temp!=s0):
s0=temp
print('input one: '+str(temp))
temp=ah.input.two.read()
if(temp!=s1):
s1=temp
print('input two: '+str(temp))
temp=ah.input.three.read()
if(temp!=s2):
s2=temp
print('input one: '+str(temp))
Code tags are three ` at the beginning and three more at the end of your code.
First thing I’d do is merge the two files into one py file.
I think I’d also redo the temp= parts like so
temp1=ah.input.one.read()
if(temp1!=s0):
s0=temp1
print('input one: '+str(temp1))
temp2=ah.input.two.read()
if(temp2!=s1):
s1=temp2
print('input two: '+str(temp2))
etc
sorry, copying and pasting the code from a terminal made the format a bit strange.
I want two files to have well separated the different processes, because at the end they will have a lot more code to do different things
Have yoy checked this code with your automation hat? it does erratical ilumination too?
With my board, when I start both scripts at the same time, the acm leds and relays leds blinks erratical and when I stop one of them, all become normal.
I don’t own an automation hat. I’m thinking your issue might be because both scripts are trying to access i2c at the same time?
This was whats I was thinking, I guess the only solution will be to convert the two processes into two threads to share the same i2c importation and access in python
I think it will work from the one file.