p'lisp

Hardware and pins

For: People who wire things up: LEDs, sensors, badge add-ons. Everything here is subject to change before the calculator ships.

The p'lisp calculator is built to be opened up and wired to. Besides the keys, the screen and the two wheels, the board has a row of holes, a port for badge add-ons and two Qwiic connectors. Your apps can use them. For the rest of the hardware, see the Calculator page.

Subject to change. The board is still being finished. The pins below are read from the board's own design files, so this page changes when the board does.

The pins

Wire row

Plain holes: solder on a header or wires.

GND3.3 VTXRX354243GND
LabelGPIOWhat it is
GND–Ground
3.3 V–Power out
TX28Serial: the calculator's console for now
RX29Serial: the calculator's console for now
3535A pad your app can use
4242A pad your app can use
4343A pad your app can use
GND–Ground

SAO port

Plain holes: solder on a header or wires.

3.3 VGNDSDASCL3637
LabelGPIOWhat it is
3.3 V–Power out
GND–Ground
SDA38I2C (shared with the Qwiic ports)
SCL39I2C (shared with the Qwiic ports)
3636A pad your app can use
3737A pad your app can use

Qwiic, left

A connector, fitted at the factory.

GND3.3 VSDASCL
LabelGPIOWhat it is
GND–Ground
3.3 V–Power out
SDA38I2C (shared with the Qwiic ports)
SCL39I2C (shared with the Qwiic ports)

Qwiic, right

A connector, fitted at the factory.

GND3.3 VSDASCL
LabelGPIOWhat it is
GND–Ground
3.3 V–Power out
SDA38I2C (shared with the Qwiic ports)
SCL39I2C (shared with the Qwiic ports)

Power for your parts is 3.3 V through a 200 mA fuse.

The Qwiic connectors and the SAO port share one I2C bus, so a sensor on any of them answers at its own address. Qwiic parts plug in with no soldering.

Driving the pins from an app

An app never touches a pin directly. Like sound, it returns effects, things it asks the calculator to do, and gets events back with the answers. The calculator's own code does all the timing. An app that uses the pins says :io in its :uses.

EffectDoes
[:io/pin 35 :out], or :in, :up, :down, :adcSets the pad's mode. :up and :down are inputs with a pull-up or pull-down; :adc reads a voltage, on 42 and 43 only
[:io/write 35 1]Sets an output high (1) or low (0)
[:io/pwm 43 hz permille]Pulses a pad, 9 Hz to 150 kHz, on for permille thousandths of the time. One of 35, 42 and 43 at a time, and one of 36 and 37
[:io/read tag 42]Reads a pad: its level, or 0 to 4095 on an :adc pad
[:io/i2c tag addr bytes n]Sends bytes to the part at addr on the I2C bus, then reads n bytes, at 400 kHz
[:io/spi tag bytes {:hz :mode}]Sends and receives on SPI: clock on 42, out on 43, in on 35. Your app drives the chip-select pad
[:io/uart bytes]Not yet. TX and RX are the calculator's own console for now

Answers come back as [:io/data tag value], or [:io/error tag reason] when something went wrong, where tag is the name you gave a read, I2C or SPI request (for a pad setting, it is the pad's number). When an app ends, every pin goes back to a plain input, so nothing stays switched on by accident.

Try it in the simulator

This app lights pad 35 when you press 1, turns it off with 0, and asks a temperature sensor on the I2C bus for a reading when you press 5. The simulator has a pretend sensor at address 0x44, so it answers even without hardware. Paste it into the Workbench and press Run, as in Your first app.

(ns my.pads
  "Light a pad and read a sensor. 1 turns pad 35 on, 0 turns it off, 5 asks the sensor on the
  Qwiic port for the temperature."
  (:require [plisp.app :refer [defapp]]))

(def sensor 0x44)

(defn init
  "Make pad 35 an output, ready to light an LED."
  [cx]
  [{:on false :temp nil :err nil} [[:io/pin 35 :out]]])

(defn tenths
  "The temperature in tenths of a degree, from the sensor's first two bytes."
  [[hi lo]]
  (- (quot (* 1750 (+ (* hi 256) lo)) 65535) 450))

(defn step
  "Keys ask for pad and sensor work; the answers come back as events."
  [m [tag a b] cx]
  (case tag
    :key      (case a
                :k/d1 [(assoc m :on true) [[:io/write 35 1]]]
                :k/d0 [(assoc m :on false) [[:io/write 35 0]]]
                :k/d5 [m [[:io/i2c :temp sensor [0xFD] 6]]]
                [m []])
    :io/data  [(assoc m :temp (tenths b) :err nil) []]
    :io/error [(if (= a :temp) (assoc m :err b) m) []]
    [m []]))

(defn draw
  "The pad's state, the last reading, and the keys."
  [m screen]
  (let [t (:temp m)]
    [[:clear]
     [:text 64 8 (if (:on m) "PAD 35: ON" "PAD 35: OFF") {:align :center}]
     [:text 64 28 (cond (:err m) "NO SENSOR"
                        t (str (if (neg? t) "-" "") (quot (abs t) 10) "." (rem (abs t) 10) " C")
                        :else "PRESS 5 TO READ")
      {:align :center}]
     [:text 64 55 "1 on  0 off  5 read" {:align :center :font :small}]]))

(defapp pads
  {:id :my/pads :name "Pads" :version 1
   :input #{:raw} :uses #{:io}}
  :init   init
  :update step
  :view   draw)

On a real calculator, put an LED and a resistor between pad 35 and GND. The simulator's sensor answers at once, but a real one usually needs a few milliseconds to measure: send the command with n set to 0, then read the 6 bytes in a second :io/i2c a moment later. Check your sensor's data sheet for its address and commands.