Communicating raspberry pi with motor2040

Hi guys,
I am new here , i just bought a new motor 2040 board and i am kinda new to this stuff and stuck with this. I need help , the issue i am facing is that i am unable to send signals to the motor 2040 via the raspberry pi , so what i want to do is send a signal from the raspberry pi to the board to controll the mmme motors but i am unable to form a communication between the two devices. It would be really helpful if someone can tell me what to do step by step, as i don’t know what to do exactly.
PLS HELP!!!

I think more info on what your trying to do is needed?

Raspberry Pi Pico Python SDK

pimoroni-pico/micropython/modules/motor at main · pimoroni/pimoroni-pico (github.com)

Hi,

It is unclear from your message whether you are having issues communicating with the device or are looking for assistance with setting up a bi-direction communication protocol so that a program running on your Pi can interact with motor2040.

I’ll assume the first case for now, since my knowledge of dealing with the second is limited.

Motor2040 comes without any software onboard, so you will either need to write your own C program or flash the board with a recent Micropython build. As a new user I would recommend the latter. Here are details for how to install: pimoroni-pico/setting-up-micropython.md at main · pimoroni/pimoroni-pico · GitHub
From there you can write a Micropython program for the board using Thonny. Here are some examples to get you started: pimoroni-pico/micropython/examples/motor2040 at main · pimoroni/pimoroni-pico · GitHub

Hi , Thank you so much for replying.

I will tell you what exactly i want to do , i want to make an app for my phone which will act like a controller and will communicate with the raspberry pi and i want the raspberry pi to send signals like “left” to the motor 2040 which will have a python program for recieving this command and some functions which will then operate the motors to move accordingly (chassis to be controlled).

Now the issue i am facing is that i don’t know to how to make these two devices communicate(bi-directional) using a serial communication(usb c), Or some other method(Maybe use the tx/rx on the board) that can also work as long as i can send different sets of commands from the raspi to moto2040 and operate the motors accordingly.

It would really be helpful if someone can help me figure out how i can achieve this output.

i know that i can directly connect my phone to the motor 2040 via a bluetooth module but i really need the setup to be like this only,(phone → raspi-> motor2040). Also i am facing some data decoding issues with the bluetooth connection( i tried to decode it using different functions and data formats but that did not seem to work out).

Thank again!!!

G’day,

I just received a Motor 2040 and have this exact same question and would love an answer here, pretty please @staff @kevinmcaleer

Ideally instructions targeted at a programming newbie.

Are serial port type comms possible, it would be nice to send commands to the 2040 (driving mecanum wheels) like:

Forward 100cm (Back, Left/Right, Rotate Left/Right, Forward Left/Right, Back Left/Right, Curved & Lateral…)

Like if the Pi had a Lidar connected and it was mapping or doing obstacle avoidance that sort of control scheme seems to make sense.

Thanks.

hi i got the uart communication working
i have used some leds to turn on when recieving data from a raspberry pi
`from machine import UART
import time
from plasma import WS2812
from motor import motor2040

uart_port = UART(0, baudrate=9600, tx=16, rx=17) # Example pins for ESP32, adjust based on your board

led = WS2812(motor2040.NUM_LEDS, 1, 0, motor2040.LED_DATA)

led.start()

while True:
if uart_port.any():
received_data = uart_port.read().decode(‘utf-8’).strip()
print(received_data) # Print received data (assuming it’s ASCII)
if received_data == ‘ON’:
led.set_hsv(0, 0, 0, 0.4)
elif received_data == ‘OFF’:
led.set_hsv(0, 0, 0, 0)
time.sleep(0.1) # Sleep for a short while to prevent high CPU usage

`

Just a FYI post. Clicking the Preformatted Text </> option will let you clip and past code, and keep the formatting (indents etc) intact. ;)

@gigachad Glad to hear you got that working. I just ordered my Motor 2040 for an autonomous tank project I am starting. If I understand correctly, you are communicating to the Motor 2040 board from your RPi4? Did you still need to install the firmware onto the 2040 board?

You could actually skip the Pi and add a HC-05 Bluetooth-dongle to the Motor2040. From the Motor2040 side, this is just UART, so you don’t have to change the program. And sending commands from your phone via Bluetooth is also very simple. You will find many examples for this kind of setup, including ready to run smartphone apps