Pico Pipette documentation · Pico Pipette on GitHub
Use this when you’re writing a lesson, course or project page and want readers to run code on their own Pico from the page itself. Each option needs one script tag and no build step.
The page must be served over https://, or from localhost while you write it: browsers only allow Web Serial there.
<pico-pipette>Load the element:
<script type="module" src="https://cdn.jsdelivr.net/npm/pico-pipette/src/pico-pipette.js"></script>
Put a <pico-pipette> wherever you want an editor, with the starting code inside it:
<pico-pipette rows="8">
from machine import Pin
led = Pin("LED", Pin.OUT)
led.toggle()
</pico-pipette>
The indentation all the lines share is removed. Write < as < and & as &, as anywhere in HTML.
Readers get Connect, Run, Stop and Start again buttons and the program’s output.
examples/blink-lesson.html
is a complete lesson page.
Give each editor the first one’s connection before adding it to the page, so they share one Pico:
other.connection = first.connection;
document.body.append(other);
If the lesson’s code imports a module of yours, save it on the Pico in beforeRun:
import { writeFile } from 'https://cdn.jsdelivr.net/npm/pico-pipette/src/picofs.js';
const el = document.querySelector('pico-pipette');
el.beforeRun = async (link, { say }) => {
say('Saving helpers.py on the Pico…');
await writeFile(link, '/helpers.py', helperCode);
};
<pipette-ide>For the full editor, as on the Pico Pipette site (files, packages, the REPL, variables and tabs):
<script type="module" src="https://cdn.jsdelivr.net/npm/pico-pipette/src/pipette-ide.js"></script>
<pipette-ide>
print("Hello from the Pico")
</pipette-ide>
Use only one per page: its parts have fixed ids.
Import the modules directly and build your own interface:
import { Connection } from 'https://cdn.jsdelivr.net/npm/pico-pipette/src/connection.js';
import { createEditor } from 'https://cdn.jsdelivr.net/npm/pico-pipette/src/editor.js';
const editor = createEditor({ value: 'print("Hello from the Pico")', rows: 8 });
document.body.append(editor.element, editor.where);
const connection = new Connection(navigator.serial);
runButton.onclick = async () => {
const link = await connection.connect();
const { stdout, stderr } = await link.run(editor.value);
output.textContent = stdout;
editor.markError(stderr);
};
npm install pico-pipette
then import 'pico-pipette' for <pico-pipette>, or import 'pico-pipette/src/pipette-ide.js' for <pipette-ide>.
Connection, PicoLink, the editor, and files on the Pico