Arduino serial.print to Python

Hello, my first post. I have a fully working Arduino sketch that controls my house heating system, getting temperature readings from solar panels, parts of the house, water tank etc, and using an 8 channel relay module for moving valves and starting/stopping pumps as required. The program works exactly as I want it to [underlined!]. It sends the status of the valves/pumps/temperatures to the serial monitor, which displays them perfectly, in a 49 digit serial.print, first 13 digits are 0 or 1, showing on/off, open/closed status of the pumps and valves, the remaining 36 digits represent 12 temperatures, each temperature consisting of 3 digits. The temperature ranges are from as low as -20C to +120C, so I take the temperature, add 127, then I can be sure that all and any temps will be represented by a 3 digit number, in a known position of the 49 digit upload. I can then go into the 49 digit upload at a specific point, and be sure of getting, for example, the outside air temperature that is shown by digits14-16, take away 127 from that number, and I've got the OAT. I have "Serial.begin(9600)" in my setup{} and the serial.print(t_OAT) in mainloop{}. As I said earlier, it works fine.

An example would be "0010010001000154165173175182192160181171183193165"

My problem comes when I try to get the data read by a Python program running on a Windows laptop or Raspberry Pi running Linux. I want to take that 49 digit block, interpret it and display it in a "pretty" GUI interface. Again, the Python code works fine, and displays all the information, exactly as I want, in a GUI window.

However, even though I am only receiving data on the laptop or Pi, the relays of the 8 channel module connected to my Arduino all go HIGH for the brief period of the upload. This results in the relays and pumps turning on and off in cadence with the upload (no matter what the sketch commands them to do) . What's going on?? If I just pull the USB cable out of my laptop or Pi, the "chattering" stops, and the relays behave perfectly! If I stop the Python programme, plug in the USB cable again and look at the Arduino serial monitor, all is well again! It is as though the Python programme is somehow acknowledging the upload back to Arduino, and whilst the serial port is receiving that acknowledgement, there's an interrupt that causes the relay module to become unpowered, so all 8 relays go HIGH?? Does that happen? How can I stop this behaviour? The Arduino is powered from an ATX PSU that pushes out plenty of power, +12v to Arduino, +5v to relay module VIN, common ground.

I havent included any code as the two programs work fine-I don't think it's a coding problem, but I wondered if there is a coding solution? Thanks for any suggestions!

whoosh: the relays of the 8 channel module connected to my Arduino all go HIGH for the brief period of the upload.

That sounds like the Python program is opening the Serial port and causing the Arduino to reset.

If you plan to have the Python program running continuously then get it to open the Serial port once and keep it open.

If you only want the Python program connect to the Arduino occasionally without disturbing the Arduino then the simplest way is probably to use a USB-TTL cable with Rx Tx and GND connected to the Arduino. That won't cause the Arduino to reset and you can still easily upload a new program with the regular USB connection.

...R

Very many thanks, will try that and report back!

Robin, just wanted to say "thanks"; I'd been closing the serial comms after the data had been uploaded, and then re-opening it when the Pi was ready for more. Just leaving it open solved the problem - genius!

Thanks for the feedback.

...R