sending and receiving data from different scripts

June 29, 2024, 18:09

_hxil

so im working on a project that needs real time audio input, im using just a pico so the pi itself cant take the audio input. to get around this, im trying to use regular python on my laptop to get the sound and then send the data to the pi, but i need advice figuring out how

eric_44794

You can accomplish this task by capturing audio data on your laptop using Python and then sending that data to your Raspberry Pi Pico for further processing. Here's a high-level plan on how you might achieve this: Capture Audio on Laptop: You'll need to use a library such as pyaudio to capture real-time audio on your laptop. Send Data to Raspberry Pi Pico: You can send the captured audio data to the Pico over a serial connection (like USB). Process Data on Pico: Write code on the Pico to receive the incoming data and process it as needed.

_hxil

Already got most of that working, it's just getting the data from the laptop to the pico I'm not sure about. Connected through USB anyway since my laptop is the power source rn I just don't know how to get the data from one to the other

eric_44794

The Pico can be programmed to receive data via its USB interface using the USB Serial functionality. First, flash MicroPython on Your Pico and then Write and Upload Code to the Pico. Next,Send Data from Laptop to Pico and run the script so that you get data.

_hxil

Link to a tutorial or something? Sorry I'm new lol

oops.se

To clarify, USB (Universal Serial Buss) can carry different ways of communication, ex. HID (mouse, keyboard), Serial, Audio and this is called profiles. Pico has a Serial profile available over USB. So to transport stuff between the PC and Pico, use the serial port, on Windows its called COMx (X is a number).

_hxil

id tried similar, pico is on COM5 so i tried connecting the python script to the com but it wouldnt work because it was in use by the pico

oops.se

The Pico cant lock the COM port on the PC, there must be an app on the PC that locks it, perhaps a python IDE?

_hxil

yea cause i was tryna send the data from a python script to a thonny script on the pico

_hxil

so it was thonny locking the COM port not the pico itself?

oops.se

Yes, that is correct. So you need to find a way around it, for example you could do a SoftSerial and add a second USB Serial Adapter to the PC. Or drop the Thony-Pico and use the serial for "PC App" to Pico.

_hxil

advice on how to go about it if i forget thonny? sorry this is my first project lol

oops.se

Do a Serial echo script on the Pico and make it to run at start/boot. Kill Thonny. Make a PC script thaat sends ddata and see if you get it in return from the Pico.

_hxil

trying this but from what i can figure out, its not working because the pico and the python script cant connect to the same COM at the same time

oops.se

You are thinking in the wrong direction. The PC with it's Python script uses the COM port. The Pico uses its serial port, NOT the COM port. Look on it as a door between two rooms. The rooms is the Pico in one room and the PC in the other. The doorway is the serial communication. The door handle is the COM port for the PC in the PC room. The door handle for the Pico is the serial, example from machine import Pin,UART To open the door the PC uses COM and the Pico uses UART. The Pico cant use COM as it belongs to the door handle that is in the PC room and vice versa.

oops.se

I have done this several times in other project.

_hxil

all i have is a usb cable to connect my laptop to the pico and pins to connect the pico to the LED's. i need more than that to make this work dont i

oops.se

See my explanation about USB above!

oops.se

No.

oops.se

But I would advice you to start with beginners project as a beginner and to read the faq section, https://discord.com/channels/818384379197784084/1194546099575341117