Serial Connection Problem between Processing and CircuitPython Code on a Adafruit Grand Central M4 Metro.
I have a Adafruit Grand Central M4 Metro Micro-Computer with 3 Motors connected to it. On the Grand Central are to Files with CircuitPython Code on it. The first one is for the initialization of the 3 Motors and the Definition of the Movements of them. The Motors are connected to the Pins: D5, D6 ; D14, D15 ; D52, D53. The Code of the second File that imports the Code from the first File is for the Function of the Motors shown below:
import time
import board
from motor import *
import busio
uart = busio.UART(board.TX, board.RX, baudrate=9600)
def vorwärts():
while True:
motor1_R1(30)
motor2_R2(30)
def rückwärts():
while True:
motor1_R2(30)
motor2_R1(30)
def drehung_rechts():
while True:
motor1_R2(30)
motor2_R2(30)
motor3_R2(30)
def drehung_links():
while True:
motor1_R1(30)
motor2_R1(30)
motor3_R1(30)
while True:
data = uart.readline()
if data is not None:
received_data = data.decode().strip()
if received_data == 'L':
drehung_links()
elif received_data == 'R':
drehung_rechts()
Now I want to controll these Functions with Buttons that I visualized in Processing. I am sending the Signals via the serial connection:
import processing.serial.*;
Serial myPort;
void setup() {
size(400, 400); // Größe des Fensters festlegen
String portName = "COM3";
myPort = new Serial(this, portName, 9600);
}
if (mouseX > 50 && mouseX < 150 && mouseY > 50 && mouseY < 150) {
// Linker Button wurde geklickt
// Sende Signal über die serielle Schnittstelle
myPort.write('L');
println("Linker Button wurde geklickt");
}
if (mouseX > 250 && mouseX < 350 && mouseY > 50 && mouseY < 150) {
// Rechter Button wurde geklickt
// Sende Signal über die serielle Schnittstelle
myPort.write('R');
println("Rechter Button wurde geklickt");
}
My Problem is that the Motors does not move at all if I press or hold one of the Buttons, but if I start a Function manuel in the CircuitPython Code, the Motors move, so the Problem must be the serial connection. Does anyone have an Idea what the Problem could be?