1

I am a total newb, I just started looking into this today. I have a a chromebook running chrome Version 96.0.4664.111 (Official Build) (64-bit), and a raspberry pi pico which I have loaded python bootloader on (drag & drop). I am trying to access the pico from my browser serially to load my source code since I cannot install thawny on my chromebook. I have pieced together this javascript function that uses web serial api to connect to the pico.

const filters = [
  { usbVendorId: 0x2E8A, usbProductId: 0x0003 },
  { usbVendorId: 0x2E8A, usbProductId: 0x0005 }
];

// Prompt user to select 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 coming from the serial device.
while (true) {
  const { value, done } = await reader.read();
  if (done) {
    // Allow the serial port to be closed later.
    reader.releaseLock();
    break;
  }
  // value is a Uint8Array.
  console.log(value);
}

// Listen to data coming from the serial device.
while (true) {
  const { value, done } = await reader.read();
  if (done) {
    // Allow the serial port to be closed 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 the serial port to be closed later.
writer.releaseLock();

I cannot find a way to make this program upload a file, I would really appreciate it if someone could help me out. Please excuse me if I'm being unclear or extremley stupid, I am completley new to this and I am really tired from new-years last night. Thanks!

  • Oh hey, I was just thinking about this exact same project! Curious though... my Pico wants to show up as a virtual mass storage device, and then I write a file to it. What protocol are you using? – Brad Jan 02 '22 at 02:51
  • 1
    I am just using glitch.com to make a serial file transfer website. I booted my pico to UF2 bootloading mode and drag-dropped the micropython bootloader onto it. My chromebook no longer sees it as an inert usb mass-storage device, but as a serial usb device. I need to send my code to it in that state for it to run. Any normal person would just get thawny ide for serial communication to the pico, but my chromebook is school-issued and I cannot install anything on it. so, I just need to send the main.py from web serial api in my browser. – pete-the-dev Jan 02 '22 at 15:01
  • fyi, the code above allows me to connect to the board and send small strings to the pico. just go to any website, press f12, and click the console tab. then copy-paste the aforementioned code into the console (yes, all of it) and a dialog should ask you to connect to a serial device, which, by usb filtering, only sees pi pico boards. (in serial mode of course). that's all it does, then sends "hi" to the pico, which does nothing. – pete-the-dev Jan 02 '22 at 15:04

1 Answers1

0

I have found a suitable solution to my question, tinkerdoodle.cc.