Hello!
can me anyone help with program code, I can`t find how to control motor with message over serial port ? I need to control dc motor with Motor Shield L298N,
So I have incoming message over serial port in tape "$motor, a, t", where "a" is motor speed from 1-255. 1-126 is reverse direction, and 1 is max speed reverse, 127 is stop, and 128-225 is forward direction, and 255 is max forward speed. "t" is number for motor run time.
Look at the third example in this Thread serial input basics and the part about parsing data.
...R
So I have incoming message over serial port in tape "$motor, a, t", where "a" is motor speed from 1-255. 1-126 is reverse direction, and 1 is max speed reverse, 127 is stop, and 128-225 is forward direction, and 255 is max forward speed. "t" is number for motor run time.
Do you have control of format of how the data is being sent? It is often easier to decide on an easy decoding format first, then send the data in that format. What is the function of the "a" in the data sent?
I'm getting data from software and I can`t change it
From software is coming data in this format.
$MOTOR,174,1000
$MOTOR,56,700
$MOTOR,120,400
$MOTOR,150,100
$MOTOR,70,200
...
pithonp:
I'm getting data from software and I can`t change it
The link I gave you in Reply #1 has code that will do what you want. Did you not read it?
...R
Is the data packet terminated with a carriage return and line feed?