Kajo Lab 101

From light sensor to Forth replay.

Follow one change in light from a sensor to a recorded LED command. Then work through three operations on the Forth data stack.

From light to a number.

The photoresistor changes resistance with light. Paired with a fixed resistor, it produces a voltage the Pico can read on pin GP26. The analogue-to-digital converter (ADC) converts that voltage to a number from 0 to 4095. The firmware turns it into an input byte from 0 to 255 for the Forth program.

The program uses that code and its previous decision to choose the LED command. On the breadboard, the LED has its own connection to GP15 through a series resistor.

Follow a change in the recording.

Each observation is a timed snapshot of the raw reading, the input Forth received and the recorded LED command. Observation 425 comes three observations after 422 in the same Pico capture.

Night Light capture · time from the first observation
ObservationRaw ADCInput byteLED command
422 8.419969 s1942121OFF
425 8.479979 s141888ON

The program requests ON below 92 and OFF at 116 or above. In between, it keeps its previous decision. Which number in observation 425 crossed the ON threshold?

Check your prediction

88 is the input byte Forth compares with 92. The raw ADC reading was 1418. Because 88 is below 92, the program issued ON. The recorded command describes what the program requested. Visually checking the LED is a separate test.

The data stack in three steps.

Forth works with small operations called words. Its data stack holds values. A word can remove values from the top of the stack and put a result back there.

2 3 +

Start with an empty stack. Read the expression from left to right. What is left after the + word runs?

Step through the stack

Read each stack from bottom to top, with the top value on the right.

  1. Push 2[2]The first number goes on the empty stack.
  2. Push 3[2 3]3 goes above 2 and becomes the top value.
  3. Run +[5]The addition word takes both numbers off the stack and puts their sum back.

The Night Light program uses the stack to compare its input with the thresholds. Between observations it remembers the last decision in memory. In Kajo Lab, you can pause and inspect both as the program runs.

Where the other pieces fit.

The program in this recording is written in Forth.

Forth and the Forth VM
Forth expresses the rule. The virtual machine, or VM, executes it. Lab can feed it the same captured inputs again so you can step through a decision.
Rust and the Kajo CPU
Rust is the language used to build Kajo’s Forth machine and firmware. A separate research compiler can also turn a small subset of Rust into instructions for the Kajo CPU, an invented processor.
Native ARM kernel
Kajo’s experimental kernel runs on the Pico’s own Arm processor. Its scheduler decides which task runs next. When a hardware timer interrupts a task, the kernel can pause it and resume it later.

Try it in Kajo Lab.

If you have Kajo Lab on Windows, you can inspect the full capture offline without a Pico.

  1. Download the capture and use Open recording or session… in Kajo Lab.
  2. In Signals, select a point near 8.45 s. With the trace focused, use the Left and Right arrow keys to find observations 422 and 425. Compare the input and LED command.
  3. At observation 425, open Program and choose Forth. Use Inspect observation, then Next frame to follow changes on the data stack.

Study references.