adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.11k stars 1.22k forks source link

Problem with UART transmission between two Raspberry Pi Pico #8407

Closed Flashton91 closed 8 months ago

Flashton91 commented 1 year ago

CircuitPython version

On the transmitter microcontroller I use version 8.2.4. On the receiver microcontroller I use version 8.2.6.

Code/REPL

################# transmitter microcontroller #################
import sys
import time
from ulab import numpy as np
import board
import busio

uart = busio.UART(board.GP4, board.GP5, baudrate=9600, timeout=5)

def sending(data):

    uart.reset_input_buffer()
    time.sleep(0.01)
    uart.write(data)
    time.sleep(0.01)
    return print(data)

k = 1
while k < 50:

    data = np.zeros((3, 3), dtype=np.uint8)
    data[0,0] = k
    time.sleep(10)

    sending(data)
    if k == 49:
        k = 0
        time.sleep(20)
    time.sleep(0.1)

    k = k + 1

################# receiver microcontroller #################

import time
import board
import busio
import digitalio
from ulab import numpy as np

#uart = busio.UART(board.TX, board.RX, baudrate=9600)
uart = busio.UART(board.GP4, board.GP5, baudrate=9600, timeout=5)
uart.reset_input_buffer()

bf = np.zeros((3, 3), dtype=np.uint8)

while True:
    if uart.in_waiting:

        uart.readinto(bf)
        print(bf)

Behavior

Hello. I previously wrote here that there is a problem with transferring ndarray between two Raspberry Pi Pico microcontrollers. Setting the speed to 9600 and the timeout to 5 helped me then.

After trying to connect two microcontrollers with different versions of CircuitPython, I saw that the receiver microcontroller was reading ndarrays filled only with zeros.

I tried changing wires and power supplies, testing on different microcontrollers, but everywhere I saw only zeros.

array([[0, 0, 0], [0, 0, 0], [0, 0, 0]], dtype=uint8)

Please tell me what could be the problem?

Description

No response

Additional information

No response

dhalbert commented 9 months ago

@Flashton91 Did you ever get this working?

Did you tie the grounds of the two boards together? That's necessary for electrical reasons.

dhalbert commented 8 months ago

Closing for now. Please reopen if you have further information.