I want to make a growbox for my red peppers.
The goal is to use my UNO as a Raspberry interface for the sensors and the relays. Pi will collect UNO sensors logs and stock it in an SQL database for a WAN access.
Every 30 minutes, Pi is doing a ser.write (python) to ask UNO to set the analogic led output to HIGH or LOW (actually the output is controlling the relay module).
Issue is that when the UNO is running the "if Serial.available loop", my analogic output is falling down to LOW during the time that the UNO is reading the serial port.
I believe my LED system will not appreciate to be turn OFF/ON every 30 minutes. I want the UNO to keep the last analogic state (HIGH) during the serial.read.
Is this a normal behavior or I'm missing something ?
I'm using a Pi zero W with an UNO R3 (link with USB).
UNO script is compiled with platformIO.
Thank you !
Pi Script :
import pendulum
import serial
import time
dt = pendulum.now('Pacific/Tahiti' )
hour = dt.to_datetime_string()[11:13]
hour_int = int(hour)
ser = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(5)
led = int
if hour_int > 6 and hour_int < 18 : led = 1
else : led = 0
ser.write(led)
Uno script :
#include "Arduino.h"
const int ledPin = 12;
void setup() {
   Serial.begin(9600);
   pinMode(ledPin, OUTPUT);
}
void light(int n){
   digitalWrite(ledPin, HIGH);
}
void loop() {
   if (Serial.available()>0){
       light(Serial.read() - '0');
   }
}
Hi and welcome to the forum. First, please read the forum guide, which will tell you how to get the most out of the forum, including how to post code correctly. Then modify your post above and correct.
You seem, to me, to be confusing analog and digital. What do you mean by "analogic"? Normally a digital output is used to control a relay.
What purpose is the Arduino here? Why can't the pi do all that for itself (with a suitable "hat")?
R-Uno:
Issue is that when the UNO is running the "if Serial.available loop", my analogic output is falling down to LOW during the time that the UNO is reading the serial port.
So... when you send the command to switch on the LED to the Arduino, it resets? Does it also happen when you send the command to switch off the LEDs?
It's very likely a power issue indeed. The switching of the relay, and even the switching of the LEDs, may cause some interference.
By the way, you can probably run the whole project on a NodeMCU or WeMOS D1 Mini. Those have WiFi built in, so can upload the sensor data to your database.
R-Uno:
I heard UNO to be more friendly with sensors
It depends on the sensor. Some sensors work only at 5V, so an Uno would be more friendly. Many sensors will work at either 3.3V or 5V so can be connected to Pi or Uno.
But there is also a problem. Uno is not friendly with Pi. Uno is 5V, Pi is 3.3V, so the Pi could be damaged if connected directly to the Uno. Is the Uno connected to the Pi using 2 cables for serial (+ ground) to the Pi pin header, or is is connected with USB?