User Tools

Site Tools


ir-for-mary

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ir-for-mary [2023/11/18 12:29] – created adminir-for-mary [2023/11/18 14:29] (current) – admin
Line 1: Line 1:
 ====== Connect Hichi IR to the Pi Pico ====== ====== Connect Hichi IR to the Pi Pico ======
  
 +===== Connection =====
  
 +
 +{{::pico-mary_steckplatine.png?600|}}
 +
 +
 +
 +===== Ping-Pong string: Hello, Pico!  =====
 +
 +Should return:
 +
 +<code bash>
 +send data Hello, Pico!
 +Received: b'Hello, Pico!'
 +</code>
 +
 +The Code:
 <code python> <code python>
-# Bibliotheken laden 
 from machine import UART, Pin from machine import UART, Pin
-from time import sleep+import utime
  
-# UART0 initialisieren +# Define GPIO pins 
-uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1), bits=8, parity=None, stop=1) +tx_pin = 0  # GPIO pin for TX 
-print('UART0:', uart0) +rx_pin = 1  # GPIO pin for RX
-print()+
  
-# UART1 initialisieren +# Initialize UART 
-uart1 = UART(1, baudrate=9600, tx=Pin(8), rx=Pin(9), bits=8, parity=None, stop=1) +uart = UART(0, baudrate=9600, tx=tx_pin, rx=rx_pin)
-print('UART1:', uart1) +
-print()+
  
-# Daten zum Senden +while True: 
-txData = 'Hallo Welt' +    # Send data 
-print('Daten senden:', txData)+    data_to_send = "Hello, Pico!" 
 +    print('send data', data_to_send) 
 +    uart.write(data_to_send)
  
-# Daten senden +    # Wait for a short duration (adjust as needed) 
-uart0.write(txData) +    utime.sleep_ms(100)
-sleep(1)+
  
-# Daten empfangen und ausgeben +    # Check for received data 
-rxData = uart1.readline() +    if uart.any(): 
-print('Daten empfangen:', rxData.decode('utf-8')) +        received_data = uart.read(uart.any()) 
-</code>+        # Process the received data here 
 +        print("Received:", received_data.decode('utf-8')) 
 + 
 +    # Wait for a short duration before the next iteration 
 +    utime.sleep_ms(500)</code>
  
ir-for-mary.1700310565.txt.gz · Last modified: by admin