OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Serial communication between Raspberry Pi Pico and PC

  • Thread starter Thread starter Binzky
  • Start date Start date
B

Binzky

Guest
I'm trying to achieve 2-way communication over USB (COM port) between Raspberry Pi Pico and Windows PC (Python). I'm unable to send from my PC to Raspberry Pi Pico nor the way back. Doesn't affect the LEDs on breadboard, nor messages get printed in terminal.

Code for PC:

Code:
import serial
import time

# open a serial connection
s = serial.Serial("COM7", 115200)

print(s)
# blink the led
while True:
    s.write(b"on\n")
    time.sleep(1)
    s.readline().strip()
    s.write(b"off\n")
    time.sleep(1)
    s.readline().strip()

Code on Raspberry Pi Pico:

Code:
import time
from machine import Pin
import sys

led = Pin(0, machine.Pin.OUT)
led2 = Pin(2, machine.Pin.OUT)
led2.value(0)
led.value(0)

def led_on():
    led.value(1)

def led_off():
    led.value(0)


while True:
    # read a command from the host
    v = sys.stdin.readline().strip()

    # perform the requested action
    if v.lower() == "on":
        led_on()
        print("Turned on!")
    elif v.lower() == "off":
        led_off()
        print("Turned off!")

What's the smartest way to debug code on the Raspberry Pi Pico? After acquiring the serial connection, standard print debug? Is there any way to use the sequence debugger in Thonny IDE?

I've tried methods from both serial and stdlib libraries without result. For PC I'm using PyCharm, for Raspberry Pi Pico Thonny. After flashing Raspberry Pi Pico I'm disconnecting the serial and run the script in PyCharm with different interpreter.
<p>I'm trying to achieve 2-way communication over USB (COM port) between Raspberry Pi Pico and Windows PC (Python). I'm unable to send from my PC to Raspberry Pi Pico nor the way back. Doesn't affect the LEDs on breadboard, nor messages get printed in terminal.</p>
<p>Code for PC:</p>
<pre><code>import serial
import time

# open a serial connection
s = serial.Serial("COM7", 115200)

print(s)
# blink the led
while True:
s.write(b"on\n")
time.sleep(1)
s.readline().strip()
s.write(b"off\n")
time.sleep(1)
s.readline().strip()
</code></pre>
<p>Code on Raspberry Pi Pico:</p>
<pre><code>import time
from machine import Pin
import sys

led = Pin(0, machine.Pin.OUT)
led2 = Pin(2, machine.Pin.OUT)
led2.value(0)
led.value(0)

def led_on():
led.value(1)

def led_off():
led.value(0)


while True:
# read a command from the host
v = sys.stdin.readline().strip()

# perform the requested action
if v.lower() == "on":
led_on()
print("Turned on!")
elif v.lower() == "off":
led_off()
print("Turned off!")
</code></pre>
<p>What's the smartest way to debug code on the Raspberry Pi Pico? After acquiring the serial connection, standard print debug? Is there any way to use the sequence debugger in Thonny IDE?</p>
<p>I've tried methods from both serial and stdlib libraries without result. For PC I'm using PyCharm, for Raspberry Pi Pico Thonny. After flashing Raspberry Pi Pico I'm disconnecting the serial and run the script in PyCharm with different interpreter.</p>
 

Latest posts

Top