Skip to content

BackyardBrains/pxt-spikerbit

Repository files navigation

Spiker:Bit extension

MakeCode • EMG • EEG • ECG

This extension enables the use of the Backyard Brains Spiker:Bit with the Microsoft MakeCode editor. The Spiker:Bit records electrical activity from the brain (EEG), muscles (EMG), and heart (ECG), making neuroscience and physiology experiments accessible in educational settings. Use this extension to create interactive projects and explore real‑time bio‑signals in your classroom or lab. For more details about the Spiker:Bit please check our product page Backyard Brains Spiker:Bit.

Further learning and lesson ideas:

Use as Extension

This repository can be added as an extension in MakeCode.

~ hint

Note for micro:bit V1 users: On micro:bit V1 boards, you may notice a slight glow on some LEDs. This is due to shared use of certain pins (e.g., pin P9) between the LED matrix and the Spiker:Bit. This visual effect is harmless and does not affect the functionality of the Spiker:Bit or the micro:bit.

~

Edit this project

To edit this repository in MakeCode.

Example

Here is the API with teacher‑friendly examples. You can copy these into MakeCode JavaScript editor.

Classroom example: show EMG envelope on the LEDs for 3 seconds, then stop.

spikerbit.startMuscleRecording()
loops.everyInterval(100, function () {
    let value = spikerbit.musclePowerSignal()
    let bar = Math.map(value, 0, 1023, 0, 25)
    led.plotBarGraph(bar, 25)
})
basic.pause(3000)
spikerbit.stopRecord()

API Functions

Muscle Group

startMuscleRecording() #spikerbit-startmusclerecording

Starts recording muscle (EMG) signals.

spikerbit.startMuscleRecording();

musclePowerSignal(): number #spikerbit-musclepowersignal

Returns the last envelope value of the EMG signal.

let power = spikerbit.musclePowerSignal();

// Raw EMG function is not exposed; use the envelope with musclePowerSignal().

Heart Group

startHeartRecording() #spikerbit-startheartrecording

Starts recording heart (ECG) signals.

spikerbit.startHeartRecording();

heartSignal(): number #spikerbit-heartsignal

Returns the last measured ECG signal.

let signal = spikerbit.heartSignal();

heartRate(): number #spikerbit-heartrate

Returns the calculated heart rate based on the last two heart beats.

let rate = spikerbit.heartRate();

Brain Group

startBrainRecording()

Starts recording brain (EEG) signals.

spikerbit.startBrainRecording();

brainSignal(): number #spikerbit-brainsignal

Returns the last measured EEG signal.

let signal = spikerbit.brainSignal();

brainAlphaPower(): number #spikerbit-brainalphapower

Returns the alpha wave power of the EEG signal.

let alphaPower = spikerbit.brainAlphaPower();

Helper Utility

print(value: number): void #spikerbit-print

The print function sends a numeric value to the serial output with the label "Value".
This allows students and teachers to easily record or visualize data in MakeCode Data Logger or any serial monitoring tool.

You can use it to print measurements from any Spiker:Bit signal, such as the EMG envelope, raw ECG or EEG values, heart rate, or EEG alpha power.

spikerbit.print(spikerbit.heartRate());

signalBlock(): number[] #spikerbit-signalblock

Returns a array of the raw recorded signal from the internal buffer, sampled at 250 Hz (one value every 4 ms).

Key behaviour:

  • Input (optional)
    • the time window (in milliseconds) of past data to return.
    • Default = 1000 ms (≈1 second).
    • The maximum allowed value is 1000 ms, which corresponds to the buffer size.
  • Output
    • An array of numbers, each element being one recorded sample.
    • The length of the array is durationMs / 4 (rounded down), since samples are collected every 4 ms.
  • Signal type
    • The function returns whatever signal is currently being recorded:
      • EMG → EMG envelope (muscle power signal)
      • ECG → raw heart signal
      • EEG → raw EEG values
  • Buffer / limits
    • The internal buffer stores up to 250 samples (≈1 second). If durationMs is larger than what the buffer contains, the function just returns the available samples.
  • Edge cases
    • If the buffer is empty (e.g., recording hasn’t started yet), the returned array will also be empty.
let signalBlock = spikerbit.signalBlock();
let shortSignalBlock = spikerbit.signalBlock(500);

maxSignalInLast(durationMs: number): number #spikerbit-maxsignalinlast

Returns max value of signal for the specified duration in milliseconds. For EMG it returns max of power (envelope) of the signal. For EEG and ECG it returns max of raw signal. Uses an internal buffer sampled at 250 Hz.

let maxDuringLastSecond = spikerbit.maxSignalInLast(950);

numPeaksInLast(durationMs: number): number #spikerbit-numpeaksinlast

Returns the number of peaks in the signal for the specified duration in milliseconds.

let numPeaks = spikerbit.numPeaksInLast(950);

stopRecord() #spikerbit-stoprecord

Stop recording and clear internal buffers.

stopRecord();

Metadata (used for search, rendering)

  • for PXT/microbit

About

Spiker:Bit – MakeCode micro:bit extension for EMG/EEG/ECG biosignal recording

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages