Skip to content
Snippets Groups Projects
Commit 25bb2c53 authored by Kai Junge's avatar Kai Junge
Browse files

Updated readme and comments in .ino code.

parent c64f1015
Branches
Tags
No related merge requests found
......@@ -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
......
#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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment