# Wixel communication between computer and Pololu 3P+ 2040OLED

**URL:** https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709
**Category:** Software and microcontrollers
**Created:** [July 1, 2024, 10:38pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709 "2024-07-01T22:38:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![zheweiwang](https://forum.pololu.com/letter_avatar_proxy/v4/letter/z/b782af/32.png) [@zheweiwang](https://forum.pololu.com/u/zheweiwang)
#### Post date: [July 1, 2024, 10:38pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/1 "2024-07-01T22:38:06Z")

</div>

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.

```auto
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

```auto
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?

---

<div class="post-metadata">

### Author: ![BrandonM](https://forum.pololu.com/user_avatar/forum.pololu.com/brandonm/32/609_2.png) [@BrandonM](https://forum.pololu.com/u/BrandonM)
#### Post date: [July 2, 2024, 9:30pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/2 "2024-07-02T21:30:13Z")

</div>

Hello.

Nothing immediately stands out to me as problematic from glancing through your code, but you might try debugging it using something like `c = uart.read(1)` and then printing `repr(c)` and/or displaying it on the 3pi+ robot’s OLED so you can see what data it is receiving.

Brandon

---

<div class="post-metadata">

### Author: ![zheweiwang](https://forum.pololu.com/letter_avatar_proxy/v4/letter/z/b782af/32.png) [@zheweiwang](https://forum.pololu.com/u/zheweiwang)
#### Post date: [July 8, 2024, 6:44pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/3 "2024-07-08T18:44:40Z")

</div>

Hello BrandonM  
I tried to print on the screen about the msg received, but it directly showed UnicodeError and sound beeee. I tried ecnoder() and encoder(utf-8) both way.

Thank you  
Zheiwei

---

<div class="post-metadata">

### Author: ![BrandonM](https://forum.pololu.com/user_avatar/forum.pololu.com/brandonm/32/609_2.png) [@BrandonM](https://forum.pololu.com/u/BrandonM)
#### Post date: [July 8, 2024, 10:09pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/4 "2024-07-08T22:09:11Z")

</div>

It sounds like you are still trying to process the data before printing it to the display. For debugging purposes, you shouldn’t need to call `encode` or `decode`. You can just call `repr` to convert the bytes read from the UART into a string.

Brandon

---

<div class="post-metadata">

### Author: ![zheweiwang](https://forum.pololu.com/letter_avatar_proxy/v4/letter/z/b782af/32.png) [@zheweiwang](https://forum.pololu.com/u/zheweiwang)
#### Post date: [July 9, 2024, 12:56am UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/5 "2024-07-09T00:56:55Z")

</div>

Thank you. I will try it.

---

<div class="post-metadata">

### Author: ![zheweiwang](https://forum.pololu.com/letter_avatar_proxy/v4/letter/z/b782af/32.png) [@zheweiwang](https://forum.pololu.com/u/zheweiwang)
#### Post date: [July 9, 2024, 7:31pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/6 "2024-07-09T19:31:41Z")

</div>

Hi, thank you for your help. When I send b’\x05\x06\x07\x08’ from computer. The 3pi+ would receive b’\xfc’ printed. Is that what you mean for debugging?

Zhewei

---

<div class="post-metadata">

### Author: ![BrandonM](https://forum.pololu.com/user_avatar/forum.pololu.com/brandonm/32/609_2.png) [@BrandonM](https://forum.pololu.com/u/BrandonM)
#### Post date: [July 9, 2024, 10:37pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/7 "2024-07-09T22:37:55Z")

</div>

It sounds like it could be a baud rate mismatch issue (since \xFC would be 0001111111 on the UART line). Are you sure both Wixels and the 3pi+ are set to the same baud rate?

You might try sending just \x00 in one experiment, then \x01 in another one and comparing the results.

Additionally, it sounds like your program might only be printing the first byte it receives; you should probably make it print all the bytes received, just in case the there are a few bytes of noise or something that are causing problems.

Brandon

---

<div class="post-metadata">

### Author: ![zheweiwang](https://forum.pololu.com/letter_avatar_proxy/v4/letter/z/b782af/32.png) [@zheweiwang](https://forum.pololu.com/u/zheweiwang)
#### Post date: [July 10, 2024, 8:11pm UTC](https://forum.pololu.com/t/wixel-communication-between-computer-and-pololu-3p-2040oled/25709/8 "2024-07-10T20:11:19Z")

</div>

Thank you so much. I get it working now. I can receive the full byte, even the other standard byte I send from the computer. I can receive x01 and x00 when I send x01 and x00. Also, when I use an encoder and decoder, so the command would pass through. I just unplug and plug the tx rx line again into the robot. Maybe it would be the connecting problem.

Zhewei
