You cannot just tie Chip Select (CS) to ground. In SPI the CS pin not only tells the receiving device to listen but also synchronizes the communication.
SCK sends pulses to separate each bit. But after powering on the slave IC might be in an undefined state regarding the communication to know it is not in the middle of a message. Thus requires a transition ...
Presumably the chip needs to see its slave select line being asserted to respond.
The solution is to use a GPIO and set it low when you want to address the chip and set it high afterwards.
Just use your own GPIO for slave selects and leave the "official" SPI slave selects for use as general GPIO.
Does the following turn on and off your relay accordingly?
import RPi.GPIO as GPIO
RELAIS_1_GPIO = 18
Setting a GPIO pin has a latching behavior. That is when you set it, it stays that same value until you tell it otherwise. So in your if statement, just add an else clause to reset it low if the value read is <=600:
if touch > 600:
print("moisture: " + str(touch))
OBSERVATION: I do not see a line of code / instruction to pull the GPIO back to low. If the observation is correct and this instruction is executed:
How would the line GPIO return to a low state?
Under what condition do you expect the GPIO to return to the low state?
What happens if the instructions is changed to:
It's possible that this might mirror something I was doing a couple of years ago and I preface this with the observation that I don't believe that it was good practice, but I didn't find a way around it, so I welcome any correction.
The issue (in my case) was that running a python program that accessed the GPIO pins required root access. If you are going to ...
A little poking with Google suggests this is a permissions problem. I don't have an instance of Apache running on a Pi, but it runs as user www-data on Debian. If that's the case, try sudo adduser www-data gpio, reboot or restart Apache, and test.
Yes. There are several ways this can be done. The method used will depend upon the characteristics of the load connected to the relay's contacts.
As @OyaMist has stated, "the actual relay state may differ from its nominal state". From a distance, when the relay state must be known, we are reduced to making a simple assumption; i.e. "...