# How-to: Reading the REPL output of a Raspberry Pi Pico on a PC via USB

**URL:** <https://forum.core-electronics.com.au/t/how-to-reading-the-repl-output-of-a-raspberry-pi-pico-on-a-pc-via-usb/16785>\
**Category:** Uncategorized\
**Created:** [7 April 2023 02:04 UTC](https://forum.core-electronics.com.au/t/how-to-reading-the-repl-output-of-a-raspberry-pi-pico-on-a-pc-via-usb/16785 "2023-04-07T02:04:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.core-electronics.com.au/u/Steven)\
**Post date:** [7 April 2023 02:04 UTC](https://forum.core-electronics.com.au/t/how-to-reading-the-repl-output-of-a-raspberry-pi-pico-on-a-pc-via-usb/16785/1 "2023-04-07T02:04:06Z")

</div>

With my Raspberry Pi cactus, I migrated my Home Assistant server to a second hand “thin client” PC I got off eBay. But how could I get data from my Piicodev atmospheric/air quality sensors on the PC?

Sure, Core stock a [USB to I2C adapter with Qwiic](https://core-electronics.com.au/adafruit-mcp2221a-breakout-general-purpose-usb-to-gpio-adc-i2c-stemma-qt-qwiic.html), but I had no desire to reverse engineer the Piicodev libraries to get it to work - I wouldn’t know where to start.

I _could_ use a Pi Pico W, and output the sensor to data over WiFi to an MQTT broker on the PC, but I wanted something simpler and more reliable.

What if, I were to connect a Raspberry Pi Pico via USB to the PC, print sensor data to the REPL, and then simply have a Python script on the PC read the REPL output over the USB connection?

It works! Here’s my code to the read the REPL on the PC. Note the name of the Raspberry Pi Pico is something like `Board CDC`.

```auto
from serial import Serial
from serial.tools import list_ports
from time import sleep
from ast import literal_eval

def get_serial_device(name):
    ports = list(list_ports.comports())
    for port in ports:
        if name in port.description:
           return Serial(port.device)

pico = get_serial_device('Board CDC')

while True:
    data = literal_eval(pico.readline().decode().rstrip('\n'))
    # print(data)
    sleep(0.002)

```

My pico simply prints my readings as a dictionary to the REPL e.g. `{'tempC': 26, 'humRH': 42}`, etc.

From scouring the internet, it’s possible to go the other way (send data from the PC to the Pico, but I’m yet to try it - looks more involved but I’ll report back if I can get it to work.

Hope this “hack” is helpful for some of you - especially since fully fledged Pis are impossible to get right now.

@Michael In the future, would Core consider making a Piicodev USB adapter so we can program our favourite Piicodev modules on a PC?

---

<div class="post-metadata">

**Author:** ![Liam120347](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/liam120347/32/5003_2.png) [@Liam120347](https://forum.core-electronics.com.au/u/Liam120347)\
**Post date:** [9 April 2023 04:23 UTC](https://forum.core-electronics.com.au/t/how-to-reading-the-repl-output-of-a-raspberry-pi-pico-on-a-pc-via-usb/16785/2 "2023-04-09T04:23:49Z")

</div>

Hi Steven,

Really neat guide!

> [@Steven](#):
>
> In the future, would Core consider making a Piicodev USB adapter so we can program our favourite Piicodev modules on a PC?

This sounds interesting, what kind of applications could you use it for?  
Its a shame that you don’t see dedicated IO on computers anymore (RS232 UART or Pins like the RPi)

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.core-electronics.com.au/u/Steven)\
**Post date:** [9 April 2023 08:46 UTC](https://forum.core-electronics.com.au/t/how-to-reading-the-repl-output-of-a-raspberry-pi-pico-on-a-pc-via-usb/16785/3 "2023-04-09T08:46:27Z")

</div>

No use case any projects in mind, but ny thinking was given the chip shortage, it might open up more opportunities to use the Piicodev range.
