Contributing to the Sensor Library


In the recent discussion about new features @ahmetus suggested it would be useful to have a draft style guide for submitting sensor interfaces for inclusion in the uLisp Sensor Library. Comments welcomed.


My belief is that the interface routines should be designed to be as simple as possible, adopting default settings to keep the functions short.

Where there are additional settings, these should be provided by a separate optional function, rather than making the main function try and cater for everything.


Each function should be named with a short version of the sensor part number, followed by -init for the initialisation function, -temp for the temperature function, and so on.

So the functions for the Si7021 Humidity Sensor would be named:

si7021-init, si7021-temp, and si7021-humidity.

This naming convention is designed so you can have multiple sensors installed at once without conflict, even if more than one provides a temperature reading, for example.

Integer or floating-point?

Where possible the routines should be designed to use integer arithmetic, so they can be run on 8/16-bit platforms. For example, this routine for the ADT7410 returns the temperature in sixteenths of a degree:

(defun adt7410-temp ()
  (with-i2c (str #x48) 
    (write-byte 0 str)
    (restart-i2c str 2)
    (let* ((hi (read-byte str))
           (lo (read-byte str))
           (tmp (logior (ash hi 5) (ash lo -3))))
      (- (logand tmp #x0FFF) (logand tmp #x1000)))))

A user who wants the temperature as a floating-point number, in °C, can do:

(/ (adt7410-temp) 16)

Sample output

An example of sample output from the routine should be shown; for example:

> (adt7410-temp)

shows that the temperature is 21.125°C.

I accept that many of the functions already in the sensor library don’t keep to these conventions, and I’ll update them in due course.

Currently there’s no way for users to upload new sensors to the library, but if you post them on the forum in this Sensor Library category I’ll add them to the library.

What new features would you like to see in uLisp?

Thanks for your consideration. I have no objection except si7021-humidity; it would be better if it named like si7021-hum :)

If most used ones could be added to ulisp, then we can have a great prototyping tool for all purposes. I’ll try to support your effort, at least I can do demo(I’ll be better-I’m learning this), and maybe written tutorial.

Interface seems reasonable. All we need is adapting Adafruit Sensors. I feel like neopixel led and all OLED display drivers should come first. Also E-Paper drivers are important too. Other than that, some most used and dirt chip chinese copies available sensors I know :

Here is the list of all of them that circuitpython supports, which means these are the generally used, you may find that circuitpython implementations is interesting, maybe it could be helpful for interfacing names too :

Audio Helpers

Music, noisemakers, and more.


Multi-color LED drivers.


Drivers used to display information. Either pixel or segment based.

Pixel based displays are implemented in two different ways. The original method called “framebuf” uses a traditional frame buffer model where all pixels are stored in the microcontroller’s ram. The newer method called “displayio” generates the pixels on the fly and relies on the display’s ram to store the final pixels. “displayio” drivers will also work with CircuitPython to display error messages and other output to the display when the user code is not using it.

The “displayio” drivers are recommended.



E-Paper / E-Ink


Real-time clocks

Chips that keep current calendar time with a backup battery. The current date and time is available through datetime .

Motion Sensors

Motion relating sensing including acceleration , magnetic , gyro , and orientation .

Environmental Sensors

Sense attributes of the environment including temperature , relative_humidity , pressure , equivalent carbon dioxide ( eco2 / eCO2 ), and total volatile organic compounds ( tvoc / TVOC ).

Light Sensors

These sensors detect light related attributes such as color , light (unit-less), and lux (light in SI lux).

Distance Sensors

These sensors measure the distance to another object and may also measure light level ( light and lux ).


These chips communicate to others over radio.

IO Expansion

These provide functionality similar to analogio , digitalio , pulseio , and touchio .



@ahmetus thanks for the comprehensive list. A bit daunting, but something to aim for!

I have no objection except si7021-humidity; it would be better if it named like si7021-hum :)

Hmm I’m not sure about that; ‘temp’ is an obvious abbreviation for temperature, but ‘hum’ isn’t quite so intuitive, and nor is ‘press’, so I think we should keep those in full.


Maybe “humd” or “humdt” then…


There may be a culture clash here. Apart from some historically-determined names, Lisp has a tendency to use function and variable names that are much more verbose than is common in other programming languages. There are reasons to be less verbose with uLisp, but once you’re into the symbol table anyway those are more or less gone.


Sorry for that, but if you do all of them, you’ll be ahead of circuitpython-micropython circus:) Because this is lisp, we have more interactivity in any circumstances, But I can shortened a bit with my priorities :)

  • Bosch Inertial Measurement Unit - BMI160
  • Electret Microphone Amplifier - MAX9814 with Auto Gain Control


Some of these would probably require uLisp functions written in C, rather than being purely written in Lisp like the other functions currently in the Sensor Library.

What do you envisage for the uLisp interface to the microphone amplifier? Would uLisp simply act as a controller, allowing you to start and stop recording to a memory buffer, and then replay that buffer? Or would uLisp record audio into the uLisp workspace so it could be manipulated by a Lisp program; for example, to do a Fast Fourier Transform?


Actually if you guide us as a C programmer - giving a detailed tutorial about how do you write sensor libraries with C for ulisp, defining some conventions for us, maybe we can be more helpful. I’m average programmer, some 7 - 8 language in my belt, and not a master none of them. I’m coming from web and mobil background. But Lisp was one of my first loves, I learned programming with Touretzky’s Gentle Introduction, and I have maybe fifteen Lisp books, still I’m not a macro or library writer, but I’m resourceful if I’m in. Always.

I’m also new in embeding space, other background I have is native mobil ios - android development.

I’m entuhastist because I loved Arduino and the other things comes with it because it’s so simple than mobil development. I know it hides behind enormous complexity, but eventually it is C, knowing and learning tricks should lead to progress, I hope it anyway.

Both ways do the job for me, most powerful chips like k210 and nRF52840 have Audio and FFT chips onboard, how we can use this? I’m prefer if we can use this chips for encoding and decoding powers. HAL is the key I suppose, not that I know much, again.

I have time, hope we can work together…


Would that be for performance reasons? I don’t think there’s any protocols involved that aren’t supported.


I was thinking for example of video or audio capture; I don’t think uLisp would be fast enough.


It can be fast enough with your ARM assembly and array support. Not for all devices, but k210 and nRF52840 definitely capable enough, and had plenty of ram. I think esp32-wrover module with extra psram also will be powerful enough.


I tested when I first run this on Maix bit; FFT Spectrum Analyses :

It uses onboard fft chip. I played Tangerine Dream Central Park, Spectrum was awesome! I didn’t record that in that time, I’m hoping I can do this with ulisp, if you ask, I’ll do again and record.


Hmm, yeah, “humidity” is pretty long to type and fit on the small screens uLisp works on.

That said, one of the things I like about Lisp is the convention of not using short forms like the ones you’re suggesting, because I find them hard to remember. See, and “These will annoy people” in CLiki.

Maybe the uLisp REPL needs symbol completion support.

Another idea is to define a set of uLisp conventional short forms in a prominent table in the uLisp Language Reference. Then one only needs to memorize that set of short forms, and one can assume complete words for everything else.


I know that and normally it is good tradition. But this is limited subset of Common Lisp as you know, it make sense if little brother uLisp use small names. Because he is little than big brother, and his place is so small. There for this doesn’t look weird in that context to me.

I don’t expect that until uLisp compiles. Too much resource limit at stake.

I agree, good idea, Emacs can do completion with some simple uLisp mode.


The functions in the Sensor Library are intended as a guide; users can rename them if they want shorter names. I think it’s more important that it’s clear what each function does from its name.