short introduction of myself: (skip if not interested)
as this is my first Post in this Forum i would like to introduce myself. My Name is Daniel i am a mechanical engineer and i am interested in electronics and µControllers since many years. Normally i am working with Arduino's. But i do like Python so much, that i bought a couple of Pi Pico's. And here we are now.
Back to Topic
I am working on a simple Project, where my laptop sends one byte via UART 1 on Pin 6(tx) and 7(rx) and the pico reads it and prints it. Thats it. But i am struggling with this obvious simple task.
Here is my Code "main.py" (copied to the board via Thonny):
Code: Select all
from machine import UART, Pin, Timer
import time
uart1 = UART(1,baudrate=9600, bits=8, parity=None, stop=1)
led = Pin(25, Pin.OUT)
timer = Timer()
timer_read = Timer()
def blink(i):
led.toggle()
def uart_read(x):
while uart1.any() != 0:
reply = uart1.read()
if reply != None:
uart1.write(reply)
uart1.read() #to clear the uart if any
timer_read.init(freq=10, mode=Timer.PERIODIC, callback=uart_read)
timer.init(freq=time_freq, mode=Timer.PERIODIC, callback=blink)
while True:
pass
If i am sending a HEX "01" i expect to get a HEX "01" back but it is a HEX "40" and "00". A HEX "EE" returns a HEX "DF" and "00". And so on... In my opinion it can't be caused because of different encodings, because i am watching at the HEX Values only.
Do you have any suggestions what is wrong in my thinking or in my code?
This simple task can't be that hard!? I am working on this since two days now and i am still at the starting point.
Thank you in advance
Best regards
Daniel