Hi, first of all thanks for the time everybody takes to help me and sorry for my English is not my native language , I’m working with a jetson nano and Arduino to control 2 dc motor trough an H-Bridge so this is my code in the Arduino.
//Motor A
int RPWM = 11;
int LPWM = 10;
//Motor B
int RPWM_B = 6;
int LPWM_B = 5;
//LED
int LEDAZUL = 12;
int LEDROJO = 13;
void setup() {
pinMode(RPWM, OUTPUT);
pinMode(LPWM, OUTPUT);
pinMode(RPWM_B, OUTPUT);
pinMode(LPWM_B, OUTPUT);
pinMode(LEDAZUL, OUTPUT);
pinMode(LEDROJO, OUTPUT);
Serial.begin(115200);
Serial.setTimeout(3);
}
void LED(){
digitalWrite (LEDAZUL,HIGH);
}
void LEDR(){
digitalWrite (LEDROJO,HIGH);
}
void Parar(){
analogWrite(RPWM, 0);
analogWrite(LPWM, 0);
analogWrite(RPWM_B,0);
analogWrite(LPWM_B,0);
digitalWrite(LEDAZUL, LOW);
digitalWrite(LEDROJO, LOW);
}
void Adelante(){
analogWrite(RPWM, 255);
analogWrite(RPWM_B, 255);
}
void Izquierda(){
analogWrite(RPWM_B, 255);
analogWrite(LPWM, 255);
}
void Derecha(){
analogWrite(RPWM, 255);
analogWrite(LPWM_B, 255);
}
String a;
void loop() {
a= Serial.readStringUntil('\n');
if (a == ""){
Parar();
}
if (a == "on"){
digitalWrite(LEDROJO, LOW);
LED();
}else{
LEDR();
digitalWrite(LEDAZUL, LOW);
}
if (a == "fr"){
Adelante();
}
if (a == "de"){
Derecha();
}
if (a == "iz"){
Izquierda();
}
}
And python is:
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(1)
try:
while True:
ser.write(str.encode('fr'))
time.sleep(0.001)
except KeyboardInterrupt:
print("BYE")
So actually in the jetson nano I’m using pyserial module to send data to the arduino and works fine in my pc with the same code throught USB but in the jetson is slow. I try everything including I put a time.sleep(0.02) to get some time but is very slow and when I remove time.Sleep or any kind delay in my codes even in the arduino code , my dc motor not even move (it seen like is too fast). I will appreciate any kind of help is for my final degree thesis.