Quantcast
Channel: Software and microcontrollers - Pololu Forum
Viewing all articles
Browse latest Browse all 81

Wixel communication between computer and Pololu 3P+ 2040OLED

$
0
0

I follow the manual of the Wixel and configure two of those by using the newest wireless serial app. One connects to the computer and here is the computer python code.

import serial
import time
port = 'COM5' 
baud_rate = 9600

ser = serial.Serial(port, baud_rate)
def send_command(command):
    ser.write(command.encode('utf-8'))
    print(f'Sent: {command}')
try:
    while True:
        command = input("Enter command (F: Forward, B: Backward, L: Left, R: Right, S: Stop): ")
        if command in ['F', 'B', 'L', 'R', 'S']:
            send_command(command)
        else:
            print("Invalid command. Please enter F, B, L, R, or S.")
except KeyboardInterrupt:
    print("Exiting...")
finally:
    ser.close()

And the other one is connect to 3P+ 2040 OLED by connect rx tx on pin 29,28 and 3.3V and GND.
The code running on the 3P+ is

import time
from machine import Pin, UART
from pololu_3pi_2040_robot import robot
from pololu_3pi_2040_robot.extras import editions

bump_sensors = robot.BumpSensors()
motors = robot.Motors()
display = robot.Display()
edition = editions.select()
yellow_led = robot.YellowLED()
if edition == "Standard":
    max_speed = 1500
    turn_time = 250
elif edition == "Turtle":
    max_speed = 3000
    turn_time = 500
elif edition == "Hyper":
    max_speed = 1125
    turn_time = 150
    motors.flip_left(True)
    motors.flip_right(True)
uart = UART(0, baudrate=9600, tx=Pin(28), rx=Pin(29))

display.fill(0)
display.text("Ready", 80, 0)
display.show()
try:
    while True:
        if uart.any():
            command = uart.read(1).decode('utf-8')
            yellow_led.on()
            time.sleeps(0.5)
            yellow_led.off()
except UnicodeError:
    display.fill(0)
    display.text("ERROR", 80, 0)
    display.show()
except KeyboardInterrupt:
    print("Exiting...")

However, it always shows an error when I use the keyboard input which means always getting unicodeError. is there any solution?

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 81

Trending Articles