My latest project involved communicating between the computer with python and the Arduino. I felt like this needs more explaining, especially as now in retrospect I understand the whole thing a lot more.
First of all, start every communication with < and end it with >. This way the Arduino always knows when important information is coming its way, and then can immediately save all of the incoming data between the <> signs. I also advise you to make a function that receives the data inbetween the <> signs automatically.
Although I haven’t utilised this yet because I have not had a project that receives data for more than one command, it is important to have the first characters of the data labelling what this data is (for). For example:
<L1,somedata>
This could be telling the Arduino to light LED 1 to the colour of the data. A comma can be used to separate command from the data.
Also, my last tip is that I would read all of the data at once because otherwise I found that it lost some of the data in the data buffer. I don’t know that this is a universal problem or just something wrong with the way I have coded it. But either way, I think it is safer to receive all the data and then mess with it afterwards.
I hope this helps! :)
Commenti