what i am doing in a python script is taking input from my game controller and rearranging it to 0 being neutral and 1 being full left or right as a rounded float to 4 decimal places.
on arduino i want to take that data and move stepper motors with the accelstepper library.
i have tried sending an f string however i get an error substring not defined and am unable to get string.h or wstring.h library to work in any way whatsoever for using substrings to get my data that way.
then i tried to pack a list in python and send it over i have no idea where to start there on arduino i cant find any documentation or sources that actually work.
ps i dont just want an answer i want to understand why this is so hard for me to grasp. there is one single forum post i found on arrays form serial read but it does not work for me at all. i am not good at arduino so please be generous.
python list method
m = pack('ff',m1,m2)
serial.write(m)
and python string method
newline = '\n'
fstring = (f'{m1},{m2} {newline}')
fstring = bytes(fstring, 'utf-8')
serial.write(fstring)
my arduino code is here. im not even going to show you what i did based on other few posts to try to communicate on arduino i know it has to be so wrong. setspeed value will replace 100000 with value from python im sending
#include <AccelStepper.h>
#include <MultiStepper.h>
#define ENABLE1 9
#define ENABLE2 12
#define MODE0 8
#define MODE1 7
#define MODE2 6
#define RESET 5
#define SLEEP 4
AccelStepper motor1(1, 3, 2);
AccelStepper motor2(1, 11, 10);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(ENABLE1, OUTPUT);
pinMode(ENABLE2, OUTPUT);
pinMode(MODE0, OUTPUT);
pinMode(MODE1, OUTPUT);
pinMode(MODE2, OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(SLEEP, OUTPUT);
digitalWrite(ENABLE1, LOW);
digitalWrite(ENABLE2, LOW);
digitalWrite(RESET, HIGH);
digitalWrite(SLEEP, HIGH);
digitalWrite(MODE0, HIGH);
digitalWrite(MODE1, HIGH);
digitalWrite(MODE2, LOW);
motor1.setMaxSpeed(100000);
motor2.setMaxSpeed(100000);
}
void loop() {
motor1.setSpeed(100000);
motor2.setSpeed(100000);
motor1.runSpeed();
motor2.runSpeed();
}
here is how i want to run the script
if (myArray[0] > 1.01){
motor1.setSpeed((myArray[0] -1) * 103500);
}
else if (myArray[0] < 0.99){
motor1.setSpeed((((myArray[0] / 1) * (-1)) + 1) * 103500);
}
if (myArray[1] > 1.01){
motor2.setSpeed((myArray[1] -1) * 103500);
}
else if (myArray[1] < 0.99){
motor2.setSpeed((((myArray[1] / 1) * (-1)) + 1) * 103500);
}
motor1.runSpeed();
motor2.runSpeed();