Software Serial and Camera Servo

I’m trying to use pins (11,12) from the RBG led port as a software serial output to transmit data to an onboard PiZero via rs232. I can get get the connection configured but when I try to send data continuously it interferes with the camera servo. Rapid twitching and such. I’m using the following code:

SoftwareSerial mySerial(11, 12, true); // RX, TX - 11=blue, 12= green
mySerial.begin(9600);
mySerial.println(“Software serial begin”);

Again, I can receive the data during startup but when sending during the loop: mySerial.print(distance) the camera servo goes all twitchy. Anyone have any ideas why this may be happening or maybe an alternative method to offload data?

We have not worked on a project similar to yours, so we cannot provide you with an accurate solution. The following methods are for reference only:

SoftwareSerial should be the last resort when the hardware serial port is occupied. The hardware serial pins for Arduino are 0 (RX) and 1 (TX).

Important: When using the hardware serial port, make sure to disconnect the Arduino from the computer’s USB connection, or ensure that the Pi Zero is not connected to the Arduino’s serial port during programming, as USB communication also uses the same hardware serial port, which can cause conflicts.

Wiring:

Arduino GND — Pi Zero GND
Arduino TX (Pin 1) — Pi Zero RX (GPIO Pin)
Code Modification:

cpp

// Remove SoftwareSerial
// SoftwareSerial mySerial(11, 12, true);

void setup() {
// Initialize hardware serial at a baud rate of 9600
Serial.begin(9600);
// Wait for serial connection; can be commented out in actual applications
// while (!Serial);
Serial.println(“Hardware serial initialized successfully”);
}

void loop() {
int distance = getDistance(); // Your function to get distance
Serial.println(distance); // Now using hardware serial to send, won’t interfere with servo

// Control the servo motor
myServo.write(angle);
delay(15); // Standard servo delay
}
On the Pi Zero, you need to enable an available UART (usually /dev/ttyS0 or /dev/ttyAMA0) and use Python’s pyserial library to read the data.

I abandoned the software serial approach and tapped the Tx and Rx pins on the Uno and connected these to a USB-to-TTL converter connected to my Pi Zero. I’m able to receive the data being sent out the serial port on the Uno. However, what I’m receiving is the camera dictionary data. I can’t seem to find where in the sketch this is being sent. I suspect it is somewhere in the camera module. Can i stop this data transmission which is normally sent to the IDE serial monitor? Also, I am still getting occasional twitching on the camera servo and the wheels activate at random for short bursts. If I had a better understanding on how the ESP board and the UNO communicate maybe I could come up with a better approach.

Sorry as we are not familiar with the specific details of your project and how you are using our learning kit, we are unable to provide detailed analysis or troubleshooting assistance at this time.