I make a robot project where the robot can move with stepper motors. I made all the math operations and calculations in Python and the results are in integer varuables, which means the steps of the motors. You can see the result "int" variables in Python:
I want to send these so that they equal the variables written in the Arduino. The variables in Arduino:
int stepsq1[4];
int stepsq2[4];
int stepsq3[4];
int stepsq4[4];
int stepsq5[4];
int stepszar[1];
And I want for example:
stepsq1[1] = stepsq1_1; //the first item of the arduino variable block equal with his Python variable
stepsq1[2]=stepsq1_2; //the second item of the arduino variable block equal with his Python variable
stepsq1[3]=stepsq1_3; the third item of the arduino variable block equal with his Python variable
stepsq1[4]=stepsq1_4; the fourth item of the arduino variable block equal with his Python variable
stepsq2[1]=stepsq2_1; the first item of the arduino variable block equal with his Python variable
.
.
.
e.t.c.
e.t.c.
e.t.c.
And I want to put a little part in the Arduino code, which say, if the datas is not coming, the void loop() operations won't begin or the datas is coming in, the void loop() operations begin.
Can somebody help me how can I send the Python datas and variables to Arduino, and how can I equal the Python variable datas with Arduino variables?
sounds like you want to pass "named" data across to the arduino. these could be passed as a series of string: "stepsq2_1=29". the two parts of the string need to be separated and the variable name looked up in a table with the address of the variable and the variable set to the integer value of the value string
of course, command strings could also be passed, the command string similarly looked up in a table containing the string and address of the function and executed
i'm curious.
what issues?
can you describe the advantages of using JSON over the ~100 program i posted? i'd like to understand the types of applications where json makes a difference
my experience is using a command line interface to exercise, test and debug code that parts of a larger application.
building a JSON is easy in Python (import json) and data is sent as text and ArduinoJson makes it super easy to decode what you got from the Serial Stream on the arduino side.
of course it's chatty and more memory intensive than the approach you proposed, but it also lets you deal with key value pairs that are dynamically transferred
so selecting one over the other is a question of convenience and ease of development/maintenance, hardware needs, portability requirements, etc...
is this how the data is described, or sent across the serial interface?
i'm curious how the addresses are associated with the names of the variables
it wouldn't take much to enhance what i posted to accept multiple variable/cmds on a single line, separated with a comma. this is an approach i read in a Bell Labs memo from the 80s
the following cmd line would produce
vars,tom=5,dick=12,vars,sum,vars
vars
varList:
0 tom
0 dick
0 harry
tom=5
dick=12
vars
varList:
5 tom
12 dick
0 harry
sum
vars
varList:
5 tom
12 dick
17 harry
technically it could be both as it can act as a poor performance storage container
Usually you use that as the payload in a communication and then you deserialize using the API. the key is the way you access the data using the API
something like this
const char* json = "{\"tom\":10}";
StaticJsonDocument<200> doc;
deserializeJson(doc, json);
int age = doc["tom"];
looks like there is no direct link between the serialized information and any storage of a variable. you show an explicit setting of the variable.
so JSON is a communication format. i believe i understand where JSON has value. (it can handle structured/"nested" data and strings with spaces)
i posted an approach that i believe was more direct for the request made by the OP. there's no extra coding required if additional variables are added -- just new table entries
you could always refer to doc["tom"] and not put that in an int. The textual container can be your memory but as I said it's heavier than lower level approaches
Your code is fine and answers the needs for sure.
JSON is simpler to extend, say if you have different types of variables, (int, bool, array, float) that you want to pass over. the library does the parsing for you but of course this comes as a cost
First of all, massive thanks for all the reacts and tips that you wrote only in 24 hours, I learned a lot about these, and I can try to figure out.
To avoid misunterstanding for example: in the python, the results of the calculations stepsq1_1 equal with 88, when I give a print command, I see that number and I want that value send to arduino which will equal with the int stepsq1[1], and etc. and etc.