uLisp on the Sino:bit


#1

uLisp ARM Version 3.3 supports the Sino:bit, a single-board computer developed for use in Chinese schools. It is inspired by the BBC Micro:bit and Calliope mini, and shares many of their features:

Sino:bit on GitHub

The performance is the same as the BBC Micro:bit.

One interesting feature of the Sino:bit is its 12x12 LED matrix which you can program to display text in non-Latin characters, play games, or plot simple graphs. It might even be possible to display an analogue clock face on it. It is controlled by a Holtec HT1632C LED driver chip, simplifying the addressing and refreshing of the display.

Like the BBC Micro:bit it is based on the Nordic Semiconductor nRF51822 ARM Cortex-M0 microcontroller running at 16 MHz and with 256 Kbytes of flash program memory:

It’s available from the manufacturer Elecrow in Shenzhen, China:

Sino:bit on Elecrow

It includes two push buttons, banana plug/crocodile clip connections, a JST battery connector, and Grove connectors for I2C and serial. The board also includes an NXP MMA8653FC 3-axis, 10-bit digital accelerometer and an NXP MAG3110 3-axis digital magnetometer.

USB cable

Note that the Sino:bit appears to be quite finniky about what USB cable you use, at least on the MacBook Pro I was using. When you connect the board to the USB port a drive titled MICROBIT should be mounted. This wasn’t happening, and I couldn’t upload programs from the Arduino IDE. The solution was to use a USB cable no longer than 7" or 180mm.

Installing uLisp on the Sino:bit

The procedure is the same as for the BBC Micro:bit; see Installing uLisp on the BBC Micro:bit.

Pin connections

The Sino:bit has 8 pads which can take crocodile clips or banana plugs. Six of these are labelled P0 to P5 and are connected to I/O pins 0 to 5. The other two are labelled GND and VCC (+3.3V).

The board also includes two pushbuttons.

Buttons

The Sino:bit provides two pushbuttons on pins 5 (A) and 11 (B). You can read these with the following program:

(defun buttons ()
  (pinmode 5 nil)
  (pinmode 11 nil)
  (loop
   (print
    (list (digitalread 5) (digitalread 11)))
   (delay 1000)))

Run it by typing:

(buttons)

LED matrix

The Sino:bit provides a matrix of 12 x 12 LEDs, controlled by a Holtec HT1632C LED driver chip:

Initialising the driver

The following functions allow you to send a command to the display controller, and initialise the display:

(defvar *cmd* #b100)
(defvar *write* #b101)

; Write 8-bit command
(defun command (cmd)
  (with-spi (s 16 1000 1 0)
    (write-byte (logior (ash *cmd* 5) (logand (ash cmd -3) #x1f)) s)
    (write-byte (logand (ash cmd 5) #xe0) s)))

; Initialise LEDs
(defun init ()
  ; SYS_EN, LED_ON, BLINK_OFF, RC_MASTER, COMMON_16NMOS, PWM_CONTROL = 0xf
  (mapc command '(#x01 #x03 #x08 #x18 #x24 #xa8)))

Writing to the display

The LEDs are addressed by a series of 7-bit addresses. Each address can be set to a 4-bit data value to specify the state of a column of four contiguous LEDs.

The following function write writes a 4-bit data byte to specify the state of the 4 LEDs at one address:

(defun write (ads data)
  (with-spi (s 16 1000 1 0)
     (write-byte (logior (ash *write* 5) (ash ads -2)) s)
     (write-byte (logior (logand (ash ads 6) #xc0) (ash data 2)) s)))

So to set the bottom leftmost LED you would write #x01 to address #x02:

(write #x02 #x01)

Displaying a bitmap

The following function put displays a bitmap on the display:

(defun put (&rest byt)
  (dotimes (n 12)
    (with-spi (s 16 1000 1 0)
       (let ((col (nth (- 11 n) byt))
             (ads (* n 4)))
         (write-byte (logior (ash *write* 5) (ash ads -2)) s)
         (write-byte (logior (logand (ash ads 6) #xc0) (logand (ash col -6) #x3f)) s)
         (write-byte (logior (logand (ash col 2) #xfc)) s)))))

The bitmap is specified as a series of 12 12-bit numbers. For example, the following call displays the Chinese character displayed above:

(put #b100000111111
     #b101110101010
     #b101010101010
     #b101010111110
     #b101010101010
     #b101110101010
     #b100000111111
     #b001100010000
     #b001010100000
     #b111001111111
     #b001000100000
     #b001000010000)

To design a shape to be plotted draw it on squared paper, then rotate it through 90° counter-clockwise before translating it into binary numbers. In other words, the first binary number corresponds to the rightmost column of the pattern, and so on.

Analogue inputs

The Sino:bit mini provides six 10-bit analogue inputs, on pins 0 to 4 and 10. Five of them are available on the edge connector pins labelled P0 to P4.

MMA8653FC 3-axis, 10-bit digital accelerometer

The accelerometer is on I2C address 29 (#x1D).

MAG3110 3-axis magnetometer

The magnetometer is on I2C address 14 (0x0E). For details of using it see:

MAG3110 3-Axis Magnetometer


#2

I haven’t measured, but performance should be somewhat better than the micro:bit since management of the LED matrix is offloaded, leaving the MCU with more available cycles.


#3

I don’t know, I find it tasteless… The typical “copy design”: “It has corners? Let’s make MORE corners! It has LEDs? Let’s make MORE LEDs!”… But then make it finicky regarding the length of the USB cable. 🙄 The original British design had the novelty, IMHO, to combine the typical I/O — buttons and LEDs (because EVERY digital sensor and actuator can be well simulated with just these) — with “bigger pins”. Throw in a few other sensors, too The BBC micro:bit really feels like you can drop it a few times. Not “too” powerful, either, because these devices are NOT powerful in nature. The thing I like about the German development is that they made sure you will not short anything out and moreover, that you have four input channels and that makes it possible to make your own calculator keypad (2 ^ 16 - 1 are fifteen combinations, enough for the numbers, equal, plus, minus, multiplication and division). But the Brits got the price right and the Germans did not. Kids are supposed to burn two or three of these, shorten something out, make mistakes. That’s the whole point: you would NEVER experiment like that with your smartphone. And the Chinese? “Let’s make it cost as much as a feature phone, and let’s give it an identity crisis as to WHAT, actually, it IS.” — They should have sticked to their ESP8266 / ESP32 chips, which do not play this “imitation game”, but which are quite awesome in their own right.


#4

@Aeneas I agree with most of what you say. But having a 12 x 12 array of LEDs is pretty cool for some applications; for example, a simple 24-hour temperature chart, an analogue clock face, or a game of pong!

But perhaps the most significant difference between the three boards for uLisp is the fact that the Calliope mini has double the RAM of the others, giving it nearly three times the amount of Lisp workspace.

It’s a real shame that there isn’t a version of the BBC Micro:bit with the nRF51822-QFAC processor which has 32 Kbytes of RAM.