I have written the following arduino code to try and read a serial value sent over from pyserial (python). I want the ascii character that I sent over by python to be read by the arduino as an integer value which will then be used as the speed value for the stepper motor.
#include <Stepper.h>
int s = 0;
const int stepsPerRevolution = 48;
Stepper myStepper = Stepper(stepsPerRevolution, 8,9,10,11);
void setup() {
Serial.begin(9600);
s = Serial.read()-'NUL'; //convert ascii to int. read from serial port and substract serial 0
myStepper.setSpeed(s);
}
Here is my python code which sends over the speed setting in ascii:
import sys
import serial
import time
ser = serial.Serial('/dev/ttyACM5', 9600)
ser.timeout = 2
ser.open()
s = input('Enter a speed from 0-70')
ser.write('s')
However nothing happens on the arduino front. I have compiled the arduino code which seems to work out fine.
Any suggestions would be greatly appreciated. Much thanks,
No. That 'NUL' is still wrong. 'NUL' is a multibyte character constant which will not have the value you think it does (whatever it is you think it does).