I am completely new to this and just started exploring today. My setup includes a Chromebook running Chrome Version 96.0.4664.111 (Official Build) (64-bit) and a Raspberry Pi Pico with the Python bootloader loaded on it using drag & drop method. I am attempting to connect to the Pico serially from my browser in order to upload my source code since I cannot install Thawny on my Chromebook. After putting together a JavaScript function that utilizes the Web Serial API to establish a connection with the Pico, I encountered some challenges.
const filters = [
{ usbVendorId: 0x2E8A, usbProductId: 0x0003 },
{ usbVendorId: 0x2E8A, usbProductId: 0x0005 }
];
// Prompt user to choose an Arduino Uno device.
const port = await navigator.serial.requestPort({ filters });
const { usbProductId, usbVendorId } = port.getInfo();
// Wait for the serial port to open.
await port.open({ baudRate: 9600 });
const textDecoder = new TextDecoderStream();
const readableStreamClosed = port.readable.pipeTo(textDecoder.writable);
const reader = textDecoder.readable.getReader();
// Listen to data transmitted by the serial device.
while (true) {
const { value, done } = await reader.read();
if (done) {
// Allow closing of the serial port later.
reader.releaseLock();
break;
}
// value is a Uint8Array.
console.log(value);
}
// Listen to data transmitted by the serial device.
while (true) {
const { value, done } = await reader.read();
if (done) {
// Allow closing of the serial port later.
reader.releaseLock();
break;
}
// value is a string.
console.log(value);
}
const textEncoder = new TextEncoderStream();
const writableStreamClosed = textEncoder.readable.pipeTo(port.writable);
const writer = textEncoder.writable.getWriter();
await writer.write("hi");
// Allow closing of the serial port later.
writer.releaseLock();
I am struggling to figure out how to modify this program to enable file upload. Any help would be greatly appreciated as I am still learning and feeling exhausted from New Year's celebrations last night. Thank you!