Hi together
I want to use a raspberry Pi to communicate to my ESP8266 D1 mini over Serial. Currently i have a steppermotor attached to my ESP8266. For test purposes, I just write a PWM frequency from my Raspberry Pi to the ESP8266 which is then used as "steps" for my steppermotor.
Everything works, but unfortunately if I write a new value to the ESP8266, the frequency changes roughly 1 second after my input. I think it has something to do with the buffer, but I am not sure if the problem is on the raspberry-side or on the ESP8266-side.
As a feedback, I just print the received values back to my raspberry over serial as a confirmation that the values change. If I write a value value of roughly less than 99999999, the feedback value is identical. Unfortunately, if I send for example "9582665835" as a value, I receive "992731243" as a feedback. It just happens if the value is very big and I think I made some mistakes in converting the value properly. Maybe someone knows also a solution for that.
Code on Raspberry-Side:
import serial
import time
SerialPort = serial.Serial('/dev/ttyUSB0', 500000, timeout=1)
cmd = 5000
cmd = str(cmd).encode()
SerialPort.write(cmd)
time.sleep(0.01)
DataReceived = SerialPort.readline().decode().strip()
print(DataReceived)
Code on ESP8266-side
#include <SPI.h>
#include <HighPowerStepperDriver.h>
HighPowerStepperDriver Driver;
const uint8_t CSPin = 15;
const uint8_t PWMPIN = 0;
int receivedRawValue = 0;
void setup()
{
Serial.begin(500000);
SPI.begin();
Driver.setChipSelectPin(CSPin);
pinMode(PWMPIN, OUTPUT);
analogWrite(PWMPIN, 128);
delay(1);
Driver.resetSettings();
Driver.clearStatus();
Driver.setCurrentMilliamps36v4(250);
Driver.setStepMode(HPSDStepMode::MicroStep8);
Driver.enableDriver();
Driver.setDirection(0);
}
void loop()
{
if (Serial.available() > 0) {
receivedRawValue = Serial.parseInt(); // Lese die empfangene Zahl
analogWriteFreq(receivedRawValue);
Serial.println(receivedRawValue);
}
}
//https://arduino.esp8266.com/stable/package_esp8266com_index.json