From 25bb2c5351be1344aeada80e8ab437b915091d3c Mon Sep 17 00:00:00 2001
From: kjunge <kai.junge@epfl.ch>
Date: Sat, 22 Jan 2022 14:48:33 +0100
Subject: [PATCH] Updated readme and comments in .ino code.

---
 README.md           |  5 +++++
 pyComms/pyComms.ino | 43 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 7ffada3..e4833c8 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,11 @@ This project is very much in its early stages, so some bugs are expected.
 - Send mulitple messages with specified messages names from the Arduino side to the Python side (e.g.: can be used to transfer multiple sensor values, status messages, timestamps, etc)
 - Simplified keyboard keypress reading functionality to test your mechatronic setup
 
+
+### Points to bare in mind
+- For now, you can only send a single string to the Arduino side.
+- The Arduino stores the **most recent message** received from the Python side. For now, there is no buffer or queue of messages (in order to simplify and increase the robustness the communication channel from edge cases). 
+
 ---
 
 ## How to use this tool
diff --git a/pyComms/pyComms.ino b/pyComms/pyComms.ino
index d6b3d94..8aea606 100644
--- a/pyComms/pyComms.ino
+++ b/pyComms/pyComms.ino
@@ -1,28 +1,61 @@
 #include "pyCommsLib.h"
 
-
+/*
+Define the message names you want send from the Arduino side 
+to the Python side. 
+The names must exactly match what is defined on the Python side. 
+*/
 String msgName[] = {"msgA", "msgB"};
+
+
+/*
+Define the C arry which will carry the data content. 
+The number (here it's 2) must match the number of messages you have defined.
+*/
 String dataCarrier[2];
 
 
 void setup() {
-  // Start the serial communication 
+  // Start the serial communication. The baudrate is arbiturary.
   Serial.begin(115200);
 
-  // Connect with the python script. This will perform a handshake
+  // Connect with the Python side
   init_python_communication();
 }
 
 void loop() {
-
+  
+  // This is how you access the latest received message from the Python side
   String received_message = latest_received_msg();
 
+  /*
+  Populate the dataCarrier array with your data
+  Here we have some temporary data/messages.
+  You must ALWAYS send strings and no other variable type. 
+  You can convert anything to a string by calling String(); 
+  */
   dataCarrier[0] = "Some message";
   dataCarrier[1] = String(3);
 
+
+  /*
+   * This command "loads" the message. It doesn't send the message yet.
+   */
   load_msg_to_python(msgName, dataCarrier, size_of_array(msgName));
-  
+
+
+  /*
+   * The sync() function must be declared at every loop of your arduino code 
+   * sync() will 
+   *    a) Receive messages from the Python side
+   *    b) Send loaded messages to the Python side
+   */
   sync();
 
+  /*
+   * This delay is not critial. 
+   * It is here to show that having a process that blocks the loop can be used.
+   * e.g.: a sensor with a very slow sampling speed. 
+   */
   delay(100);
 }
-- 
GitLab