Interfacing Raspberry Pi Zero with 3pi+

Hello

I am trying to establish serial communication between a raspberry pi and 3pi+ through UART. To do this, I removed the display to free up a pair of RX TX pins. I am able to send data from the 3pi+ to the Pi but I am unable to do the reverse (receive data from the Pi).

Hardware Setup
Raspberry Pi Zero
Pololu 3pi+
5V to 3.3V logic level shifter
5V to 3.3V step down voltage regulator

RASPBERRY PI PART OF CODE
Case 1- sending data from Pi to 3pi+
I have written the following code in python

import serial
import time

data = "Hello\n"

ser = serial.Serial(
    port='/dev/ttyAMA0',
    baudrate=115200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)

while 1:
    ser.write(data.encode('utf-8'))
    time.sleep(1)

Case 2- sending data from 3pi+ to Pi
Similarly for reading from the 3pi+ (this works as intended)

import serial
import time

ser = serial.Serial(
        port='/dev/ttyAMA0',
        baudrate=115200,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
)

while True:
        data = ser.readline().decode('utf-8')
        print(f"data received: {data}")

3PI+ PART OF CODE

Case 1- sending data from Pi to 3pi+
The code on 3pi+ is

#include <Pololu3piPlus32U4.h>

using namespace Pololu3piPlus32U4;

char bytes[100];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial1.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("bytes for reading: ");
  Serial.println(Serial.available());

  Serial1.readBytes(bytes,100);
  Serial1.flush();
  Serial.print("data received: "); Serial.println(bytes);
  // if (Serial1.available() > 0)
  // {
  //   // String data = Serial1.readStringUntil("\n");
  //   Serial.print("data: "); Serial.println(data); 
  //   Serial1.flush();
  // }
  // delay(100);
}

Case 2- sending data from 3pi+ to Pi
The code is as follows on the 3pi+ (works as intended)

#include <Pololu3piPlus32U4.h>

using namespace Pololu3piPlus32U4;

char data[] = "from arduino\n";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial1.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial1.write(data);
  Serial.println("sent");
  delay(50);
}

I am not sure if I missed something trivial here or my fundamentals are shaky. Any comment is highly appreciated!

PS-
Attaching an image for Case 1

Attaching an image for Case 2

Thanks

Hello.

Could you clarify which 3pi+ robot you are using (i.e. the LCD version or the OLED display version)? Additionally, could you post some pictures of your setup that show how everything is connected?

Brandon

Hi

I am using the LCD version. I will send the picture of the setup soon. Is it alright if I send a graphical representation of the setup as I’m using a lot of jumper wires? I think it would be harder to understand over pictures.

Hello

Here are the images, hopefully you can make sense of it.

Thanks



I see what you mean about the jumper wires being hard to follow. A description and graphical representation of the connections would be helpful as well. I did not expect to see two 3pi+ robots in your setup (I did not get that from your first description). Could you clarify if the one that the Raspberry Pi Zero is mounted on top of is connected at all (and what the board and 4 wires under the Raspberry Pi are doing)? Also, it looks like you are connecting the 5V pin on the 3pi+ LCD header to the 5V pin on the Raspberry Pi Zero through the power bus on the breadboard; is that connection being used to power the Raspberry Pi?

Brandon

Hi

Sorry I forgot to mention.

Note: The 3pi+ that is placed under the Raspberry Pi has no electric connections with it. It is just used to mechanically mount the Raspberry Pi on it.

UPDATE: I was able to achieve my basic serial communication using UART but there is no change in the codes or the electrical connections. My intended application started working when I switched the Pi with a newer one. Seems like there is an issue with the previous Pi.

Here’s a graphical representation of the circuitry.

Yes, I am currently powering the Raspberry Pi from the 5V display headers on the 3pi+. This is actually another concern, should I be using the 5V display header for powering the Pi or should I have a separate power supply for? I did not want to add another power supply as it would increase the overall weight.

Thanks

I do not see any obvious problems with that wiring scheme. I am glad to hear you were able to get some basic UART communication working.

As far as powering the Raspberry Pi Zero, the 5V output on the 3pi+ can handle around 0.7A under typical conditions (the exact amount depends on the current battery voltage and ambient conditions). This is quite a bit lower than the 1.2A that the Raspberry Pi documentation recommends for powering the Raspberry Pi Zero. However, I suspect there is a fair amount of safety margin added in their recommendation, and the actual current draw of the Raspberry Pi in your application will depend on how you are using it and what else is connected to it, so it might be possible that 0.7A is enough for you. If you notice any problems with it (or just want to be cautious), you might consider adding a separate step-up/step-down voltage regulator to power the Raspberry Pi Zero from the 3pi+ battery voltage (available on the VSW pin if you want it to turn off with the 3pi+ robot). In particular, something like our new 5V, 1.5A S13V15F5 regulator might be good fit.

Brandon