Motor2040 UART connection does not work

Hi Everyone,

I just got my Motor2040 and I am trying to get it to communicate with other Pico via UART. My Motor2040 board cannot send or listen to the message. Could anyone help me to see if my setting is wrong or if something is wrong with my Motor2040 board?

What I have tried so far:

My code worked when I tested Pico vs Pico. So I guess the issue is not here.
I tested the Motor 2040 RX and TX pin by connecting them to a button, one by one. Both of them can get responses from the button.
I flashed Pimoroni firmware, but it did not work. Then I flashed the official Pico firmware, it did not work either.
It sounds dumb but I tried to swap RX and TX wire, and it did not work.

My wire:

Motor2040 RX → Pico GPIO0
Motor2040 TX → Pico GPIO1
Motor2040 GND → Pico GND

My code:

Motor 2040:

from machine import Pin,UART
from time import sleep
uart = UART(0,9600)
count = 0
while True:
    message = "hello " + str(count)
    print(message)
    count = count + 1
    uart.write(bytes(message + '\n','utf-8'))
    sleep(1)

Pico:

from machine import Pin,UART
uart = UART(0,9600)
while True:
    if uart.any():
        command = uart.read().decode('utf-8')
        print(command)

Thank you!

Edit: The answer is I need to specify the PIN used for TX and RX on Motor 2040

uart = UART(0,9600, tx=Pin(16), rx=Pin(17))

If I read the schematic correctly, the motor 2040 uses GPIO 16 and 17 for UART.
GPIO 16 TX and GPIO 17 RX. Not 0 and 1
motor2040.sch (shopify.com)

Raspberry Pi Pico GPIO Pinout

Hi @alphanumeric ,

You are correct that on Motor2040, the GPIOs are 16 and 17. However, the Pico uses GPIO 0 and 1 as TX and RX. So my wiring is still correct, isn’t it?

I just tried to use Pico GPIO 16 and 17, it did not work either

Motor2040 RX → Pico GPIO0
Motor2040 TX → Pico GPIO1
Motor2040 GND → Pico GND

Best

Your wiring is correct. But I think you need to set up the use of those pins in your motor 2040 code.

Hi @alphanumeric ,

Could you give me more information on how to do it correctly? What lines in my code above need to be corrected?

The thing is, I tested my code using Pico vs Pico and it worked. Also, I don’t think I need to specify any GPIO PIN when using UART. All I need to check is channel 0 or channel 1. In this case, Motor 2040 only has 1 channel UART0.

Best.

Hi @alphanumeric,

Thank you for your help. It works now. As you said, I need to specify the pins in

uart = UART(0,9600, tx=Pin(16), rx=Pin(17))

I think the problem is when I used Pico, I only used 3 PINs (TX, RX, GND), and the other UART PINs were free. So the Pico knew where to read/send data. But in Motor 2040, the other UART PINs are used for controlling motors or other things, so the board is confused. Hope someone from Pimoroni team could confirm this.

Again, thanks for your help.

Best

1 Like

I “think” the way it works is, if you don’t specify any pins, it defaults to using 0 and 1.
You were wired up to 16 and 17, but software wise, it was trying to use 0 and 1.

Manually pointing it to the correct pins fixed it. That was good sleuthing figuring out what line of code to edit. I was thinking it was that line, based on the following

i2c has a similar issue, depending on what Pack etc your using.

from pimoroni_i2c import PimoroniI2C

PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}

i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)

I use i2c = PimoroniI2C(sda=(4), scl=(5)) in my code as those are the pins I most often use.

So far I haven’t done anything UART wise on a PICO.

I see. It is interesting to know about specifying PINs for i2c. I have never tried to connect more than 1 i2c device at a time.

However, I dont think there are default UART PINs. I did try to connect Pico 0, 1 to another Pico 17, 16. And my code worked without specifying PINs. That is why I thought something wrong with my Motor 2040.

You can have multiple i2c devices on the same bus, as long as no two devices have the same address. I have done it many many times on a PICO and Pi. Light sensors, environmental sensors, Real Time Clock, etc. It’s why some Pimoroni breakouts have an address select jumper on the back. It lets you use two of that breakout at the same time.
On a Pi your limited to the default pins for i2c1. On a PICO, i2c0 can be set to several different sets of pins. same deal for SPI and UART.

SPI is the same deal, as long as each device uses a different chip select pin. I’ve run two Display packs on a PICO with special wiring and special code. And three displays on a Pi on SPI 1

Just haven’t dabbled in UART as of yet.

EDIT: I’ve been at it a while and still get very confused by how some of it works, Pi and PICO.

1 Like