On the Pi · the onboard display

The monitor that runs on the Pi itself.

No internet needed: a Pi, a browser and a lab network.

Besides this website, the Raspberry Pi serves its own display over the lab network. It is the web-based HMI from the report, the one that runs on the Pi, and the offline fallback for a demo: with no internet at all, the Pi still draws the waveform and shows the classifier's answer. When the Pi is on, the same display is also public at live.eecsyorku.app, through a Cloudflare Tunnel.

  • 0

    cloud calls · runs on the Pi

  • 5000

    default port · python -m hmi

  • 1

    command to start it

01 · Why it exists

A display that does not need the internet.

What it is

A small Flask web server written in Python, and one page built from the same code as this website. Start it withpython -m hmi on the Raspberry Pi, open the Pi's address from any laptop on the same network, and the browser draws the waveform and the classification. The server reads the ADC and classifies the newest window with the trained model on the Pi's own CPU.

It has two views, chosen with Live | Recorded in its header: Live, the newest seconds from the ADC, and Recorded, the same recording monitor as this website's, where Through the hardware shows the files the Pi has recorded through the speaker and microphone. When the Pi is on, the same display is online at live.eecsyorku.app, through a Cloudflare Tunnel. If the Pi is off or cannot connect, visitors see an offline page instead.

Why it exists

The report promises a web-based HMI that runs on the Pi and opens in a browser. This is that display. It needs only the Pi and a browser, so it keeps working when a venue has no internet: it is the offline fallback for demos.

This website is the public view of the same project. It needs the internet to load, and it cannot reach a Pi that is switched off.

Side by side

This website and the Pi's own display

What differs between this website and the display the Raspberry Pi serves itself
QuestionThis websiteThe Pi's own display
Where it runsStatic pages in your browser, served by Cloudflare. No server code runs for them.A Flask server on the Pi. Your browser draws the page it sends.
Needs the internetYes, to load the pages.No. It needs only the network between the Pi and the browser.
Where the data comes fromRecordings and results exported ahead of time. The Live monitor link opens the Pi's own display when it is online.Live: the PCM1808 ADC (a replay of .wav files when started for a demo). Recorded: the same exported recordings as this website, and the files the Pi has recorded through the hardware.
ClassificationAnswers computed ahead of time by the trained model and shipped with the pages.Computed on the Pi's own CPU by the trained model, for the Live view and for each file recorded through the hardware. The offline baseline in the Recorded view is the same model's answer, computed ahead of time.
The rendererplot.js, a byte-for-byte copy.plot.js, the original, unchanged since the midterm.
Best forExplaining the project to anyone with a link.A demo with no internet, and the display the hardware's samples will appear on.

Both draw the waveform with the same renderer, so a plot on one looks like a plot on the other.

02 · The screens

Every part of the display, explained.

These are real screenshots, not mock-ups: the Pi's display, taken in a browser on the development computer with the same code the Pi runs. Point at a numbered marker, or Tab to it, to see what a part shows. The list under each picture says the same in words.

FIG. 1 · The Pi's display, Live view · replay of 9979_TV.wav and 84987_PV.wav

Real screenshot · 1440 px wide

Screenshot of the Pi's display in the Live view. The header's Live and Recorded switch has Live selected, and a large status word says Replaying files. The plot panel shows the newest 10 seconds of a recording with the latest 5 second window marked. Beside it the Classification card shows that window's result, its confidence, the vote-share meter against the threshold and the recent windows, and the Input card names the replayed files, the sample rate, the time acquired and how long one classification took.Screenshot of the Pi's display in the Live view. The header's Live and Recorded switch has Live selected, and a large status word says Replaying files. The plot panel shows the newest 10 seconds of a recording with the latest 5 second window marked. Beside it the Classification card shows that window's result, its confidence, the vote-share meter against the threshold and the recent windows, and the Input card names the replayed files, the sample rate, the time acquired and how long one classification took.
The Pi's display in the Live view, a few seconds after start-up. On the Pi it reads the PCM1808 ADC; this picture was taken on a computer with no hardware attached, so a real-time replay of two recordings stands in for the ADC, and the page says so. Dataset label, not a model output: 9979_TV is a murmur recording. In the window shown (3.0–8.0 s) the model answers "Murmur absent", which is a miss: half of this recording's 5 s windows fall below the threshold, and the whole recording (FIG. 2) is found only narrowly. Recordings: CirCor DigiScope Phonocardiogram Dataset v1.0.3, PhysioNet, ODC-By 1.0.

Open the full-size screenshot Open the full-size screenshot

  1. Live | Recorded

    The page's two views, in its header. Live shows the Pi's input as it arrives; Recorded is the recording monitor. Recorded keeps its place in the address (/#recorded), so a link can open either view.

  2. Status

    What the feed is doing, in one large word. While the Pi answers it is the input's state: Capturing, No signal from the ADC, ADC not available, or Replaying files, as here. Otherwise Connecting, Offline or Paused. The line under it says when the last samples arrived.

  3. Sweep, Scroll and Pause

    Sweep writes the trace left to right like a bedside monitor; Scroll moves it past a fixed pen. Pause holds the display and stops asking the Pi for samples until you resume.

  4. Newest samples

    The newest 10 s, drawn by plot.js on labelled axes, with the latest 5 s window the classifier used marked as a band. From the ADC these are the samples after the anti-alias low-pass and decimation to 4000 Hz: the samples the classifier receives.

  5. Readouts

    How long the Pi has been acquiring, the span drawn, the sample rate and the band the model keeps (20–500 Hz).

  6. Classification card

    The model's answer for the latest 5 s window, re-classified about once a second: the label, the confidence and the meter, which shows the share of the random forest's trees that vote murmur, against the fixed threshold of 0.32. Confidence is the share of trees that agree with the answer, not a probability. One window, not a whole recording, and a research output, not a diagnosis.

  7. Recent windows

    One cell per window the Pi has classified, oldest first, the newest outlined: a circle for murmur absent, a triangle for murmur present, and the share of trees voting murmur.

  8. Input card

    What feeds the display and how it is doing. On the Pi it is the PCM1808 ADC: capturing, no signal, or not available, with the reason. Here it names the replayed files and the one now playing. Then the sample rate, the time acquired and how long one classification took; that time was measured on the computer that took the screenshot.

FIG. 2 · The Pi's display, Recorded view · 9979_TV.wav · tricuspid

Real screenshot · 1440 px wide

Screenshot of the Pi's display in the Recorded view. The header's Live and Recorded switch has Recorded selected, and a Result shown control has Offline baseline chosen rather than Through the hardware. Below are four recording cards, then the plot panel with Play and the waveform of 9979_TV.wav, with S1 and S2 ticks, hatched murmur bands and the analysis window, an overview of the file and the view controls. Beside it the Classification card gives the model's answer for the whole recording and for each window, and the Recording card describes the file.Screenshot of the Pi's display in the Recorded view. The header's Live and Recorded switch has Recorded selected, and a Result shown control has Offline baseline chosen rather than Through the hardware. Below are four recording cards, then the plot panel with Play and the waveform of 9979_TV.wav, with S1 and S2 ticks, hatched murmur bands and the analysis window, an overview of the file and the view controls. Beside it the Classification card gives the model's answer for the whole recording and for each window, and the Recording card describes the file.
The Pi's display in the Recorded view on 9979_TV.wav, with Offline baseline chosen: the same monitor as this website's Recording monitor, served by the Pi. Dataset label, not a model output: murmur, holosystolic, grade III/VI; the recording is in the test split, held out from training. The Classification card shows the trained model's own answer for the whole recording. Time in seconds from the start of the file; amplitude in file units (full scale ±1). Recordings: CirCor DigiScope Phonocardiogram Dataset v1.0.3, PhysioNet, ODC-By 1.0.

Open the full-size screenshot Open the full-size screenshot

  1. Live | Recorded

    Recorded is selected: the recordings the Pi carries, in the same monitor as this website's Recording monitor page.

  2. Result shown

    Offline baseline, chosen here, is the model's score on the file, computed in software during training. Through the hardware is the same file as the Pi recorded it through the speaker, coupler, silicone layer and microphone. It shows a capture, a bench file whose score is held back until the whole bench is recorded, or Not measured; on the Pi's own page a file can be recorded from there.

  3. Recordings

    The recordings on the Pi, one card each. The chips are the dataset's labels, not the model's output. Blind reading hides them until you make your own reading.

  4. Play and view

    Play sounds the file and moves the view along with it. Window turns a page at a time; Strip chart scrolls the trace past a fixed pen.

  5. Waveform and marks

    One window of the file on labelled axes, drawn by plot.js: time in seconds, amplitude in file units (full scale ±1). The ticks and hatched bands are the dataset's S1, S2 and murmur annotations, and the band marks the analysis window the card describes. Point at the plot, or focus it and use the arrow keys, to read one sample: its time, its position in the file and its amplitude.

  6. Overview and controls

    The whole file in miniature, with the part on screen outlined, then where the view starts, how long it is (2, 5 or 10 s) and the amplitude scale.

  7. Classification card

    The model's answer for the whole recording: the mean, over 5 s windows taken every 2.5 s, of the share of the random forest's trees that vote murmur, against the fixed threshold of 0.32. Confidence is the share of trees that agree with the answer, not a probability. Then one cell per window, and the window on screen. A research output, not a diagnosis.

  8. Recording card

    The file, its valve, the dataset label, the sample rate and the length, and which half of the dataset it is in: here the test half, held out from training.

  9. See what the AI sees

    Opens five steps for the window on screen, from the raw samples to the decision.

03 · How it works

A small server and a built page.

The page is built once, on a computer with Node, from this website's own code; the Pi needs only Python. The server answers in JSON, and the page asks it for samples and draws them.

FIG. 3 · How a screen gets its data

In order

Browser

A laptop on the network, or the Pi's own screen.

  • The Pi pageLive | Recorded, built from this website's code into web/dist-pi.
  • plot.jsThe renderer: draws a window of samples. Unchanged since the midterm.

Flask server, on the Pi

Checks the request, reads a window of samples, asks the classifier, sends JSON.

  • hmi/app.pyThe routes under /api and the page itself. It does no signal maths.

Source and classifier

The source is the one part that changes when the hardware arrives.

  • WavFileSourceReads the .wav files in the data folder.
  • FileReplaySource, LiveMonitorA real-time replay of .wav files that feeds the Live view when no ADC is used.
  • AlsaCaptureSourceReads the PCM1808 through the Pi's I2S input (arecord, 48 kHz) and decimates to 4 kHz, behind the same BlockSource interface. Tested with a fake stream; not yet run against the wired ADC.
  • MurmurModelRandom forest on 26 MFCC summary numbers per window (13 MFCCs, mean and standard deviation).
Exists and runs todayNot built yet
The server only ever asks a source for the samples from one time to another, so a hardware source can slot in underneath without changing the JSON, the controller or the renderer.

A JSON API

The server's job is small: serve the built page, check each request, ask the source for the newest samples, ask the classifier about them, and send back JSON. It does no signal processing of its own.

The page, built from this website

The page is the Pi build of this website (npm run bundle:pi): the same components as the Recording monitor, plus the Live view. Live asks /api/live for new samples several times a second; Recorded reads the exported recordings and the Pi's /api/reacquired. If the built page is missing, the server falls back to the plain page from the midterm.

A renderer that did not change

plot.js draws one window of samples on labelled axes. It has not changed since the midterm. This website loads a byte-for-byte copy of it, so the waveforms on Home and the Recording monitor are drawn by the same code as the Pi's display.

A source you can swap

The display was built so its data source can move from a file to live samples without touching the renderer. The Live view runs that way: on the Pi, AlsaCaptureSource reads the PCM1808 ADC; for a demo with no hardware, a real-time replay of .wav files feeds the same loop. The capture source is written and tested against a fake stream, and has not yet run against the wired ADC.

The JSON routes

GET /, /_astro, /data
The built page and the recordings exported with it (the Recorded view's offline baseline).
GET /api/live
The newest samples of the acquisition loop and its latest classification, with the state of the input (Live view).
GET /api/reacquired
The files recorded through the hardware so far, each classified by the same model and threshold. A bench file's answer is held back until the whole bench is recorded.
POST /api/reacquire
Records one file while the page plays it through the speaker. Only from the Pi itself or its local network, never through the public tunnel.
GET /api/window
One window of a .wav file in the data folder with its classification: the plain fallback page uses it when the page is not built.

Where to look in the code

hmi/app.py
The Flask app: the built page, its data and the JSON routes.
hmi/__main__.py
python -m hmi and its options: host, port, --capture or --live, the built page's folder.
web/src/routes/monitor.astro
The page: the Live | Recorded switch and the two views. npm run bundle:pi builds it into web/dist-pi.
web/src/components/pi-monitor/
The Live view: the plot, the Classification card and the Input card.
web/src/components/recordings/
The Recorded view: the same recording monitor as this website, with Through the hardware.
hmi/static/plot.js
The renderer: draws one window of samples. Unchanged since the midterm.
pcg/sources.py, pcg/stream.py
Where samples come from: WavFileSource, the BlockSource interface, the replay and the LiveMonitor.
pcg/capture.py
AlsaCaptureSource: reads the PCM1808 through the Pi's I2S input and decimates it to 4 kHz.
pcg/reacquire.py
Records a file played through the hardware, lines it up with the original and stores it for the experiment.

04 · Start it

Four steps, then open it in a browser.

  1. Put the project on the Pi.

    On a computer with Node, build the page: npm run bundle:pi in web/ writes web/dist-pi. Then copy the project folder over, with scp or a USB stick, with web/dist-pi but not .venv: it belongs to one machine. The recordings are not in git, so copy the .wav files into data/: a Live replay plays them, and a file recorded through the hardware is lined up against its original there.

  2. Install the packages.

    cd project
    python3 -m venv .venv
    .venv/bin/pip install --only-binary=:all: -r requirements.txt

    Keep the exact versions in requirements.txt: the saved model is tied to the scikit-learn and numpy versions it was trained with. The first run can take minutes while the feature code warms up.

  3. Start the server.

    .venv/bin/python -m hmi   # Recorded only
    .venv/bin/python -m hmi --capture   # Live from the PCM1808 ADC, and Recorded
    .venv/bin/python -m hmi --live data/9979_TV.wav data/84987_PV.wav   # no hardware: Live from a replay, and Recorded

    The Live view is switched on by --capture (the ADC) or by --live with at least one .wav file (a replay stands in for the ADC, for a demo with no hardware). Give only one of the two. If the ADC is missing or silent, the page says so and retries every few seconds. With --capture, the Recorded view can also record a file through the hardware, from the Pi itself or its local network only.

  4. Open it from a laptop.

    On the same network, open http://<pi-hostname>.local:5000, or http://<pi-ip>:5000: run hostname -I on the Pi to find its address. On the Pi itself, http://localhost:5000 works.

    If the page does not load, check that both devices are on the same network and that it allows device-to-device traffic. Some campus and guest Wi-Fi does not.

Keep it on a private network

The Flask server has no login. On the lab network it is fine as it is, but do not expose it to the internet with a port forward. The public copy at live.eecsyorku.app does not do that: it runs the same display under the waitress server (--production) and reaches it only through a Cloudflare Tunnel.

Photo to come · the Pi running the display
Will show the Raspberry Pi serving the display, with a laptop open on its address. No photo has been taken yet.