I'm currently working on a (big) project that uses lots of elements. The machine I'm developping is meant to be a tool for biology labs that study insect's behavior.
Since there are lots of inputs and outputs (9 servo SG90, 1 servo SG5010, and 12 relays as output, 9 thermistors, 1 DHT22, and a RTC clock as inputs), I'm using an Arduino Mega 2560. The Arduino is USB-linked to a computer, on wich Putty is running, in order for the user to send commands and receive data.
I've attached my code to this post. It is quite long, but a lot of it is repetition. (I've created and used functions as well as I could).
My problem is that, when I upload that code to the Arduino, I read data correctly (I see 9 different temperatures, the humidity, "door state" wich indicates the SG90's position, etc), but if I send an instruction from Putty, I see the Rx led blink, but nothing ever happens. No matter how short the instruction is (even if it's just one character).
But, if I upload a smaller code to the Arduino, that commands one single motor, for instance, or one relay, etc, then it works without problem (for every elements).
As I don't truly understand the problem, I find it difficult to find a solution... I figured it could be a synch problem between the computer and the Arduino, and the commands sent are lost in the process. Either that, or it's an alimentation problem, but then again, the Arduino is powered by a computer's alim (5 V, and up to 20 A...), the servo's are detached after beeing used so they don't use power, and the 12 relays are on 2 plates so it shouldn't use too much power either.
I've tried several things (quite randomly) to make it work. I changed the communications' speed (I've set it to 9600 bauds, 115200 bauds, 57600 bauds), it didn't work. I tried to set a time out as well (I tried 500 ms, 1000 ms, 100 ms, 2000 ms, also quite randomly ), it didn't work either. I tried the set delays between each if-else conditions, no better results.
I'm lost here, I don't understand what happens after the Arduino receive the commands (it does, the Rx blink...), why the command is lost every time, and I don't know what to do to fix it
I would appreciate some help !
Projet_Integrateur.ino (13.2 KB)