About Me

Michael Zucchi

 B.E. (Comp. Sys. Eng.)

  also known as Zed
  to his mates & enemies!

notzed at gmail >
fosstodon.org/@notzed >


android (44)
beagle (63)
biographical (104)
blogz (9)
business (1)
code (77)
compilerz (1)
cooking (31)
dez (7)
dusk (31)
esp32 (4)
extensionz (1)
ffts (3)
forth (3)
free software (4)
games (32)
gloat (2)
globalisation (1)
gnu (4)
graphics (16)
gsoc (4)
hacking (459)
haiku (2)
horticulture (10)
house (23)
hsa (6)
humour (7)
imagez (28)
java (231)
java ee (3)
javafx (49)
jjmpeg (81)
junk (3)
kobo (15)
libeze (7)
linux (5)
mediaz (27)
ml (15)
nativez (10)
opencl (120)
os (17)
panamaz (5)
parallella (97)
pdfz (8)
philosophy (26)
picfx (2)
players (1)
playerz (2)
politics (7)
ps3 (12)
puppybits (17)
rants (137)
readerz (8)
rez (1)
socles (36)
termz (3)
videoz (6)
vulkan (3)
wanki (3)
workshop (3)
zcl (4)
zedzone (26)
Saturday, 06 July 2024, 09:28

Electrified Kilt!

I caught up with some old mates recently and one of them gave me a couple of ESP-01 board to play with. I wasn't really sure what I was going to do with them, one plan was a wifi-connected irrigation controller just for something to poke at and to learn about the devices and the i/o. But this act of generosity cascaded into a bit of a spending spree on aliexpress where i've added some esp32-c3's, a bunch of sensors, relay boards, power modules, solderless breadboards, LED strips ...

Once I got them working I wasn't really sure what to do with them, I have some ideas for the light strips for xmas but since I had them and winter solstice was coming up I decided to do something a bit silly and see if I could successfully 'electrify' one of my kilts!

Moving geometric pattern.

Animated 3D Simplex Noise.

The pictures don't really do it justice - the leds are very bright at night and very colourful and animate very smoothly. I'm using a Makita battery which is a bit hefty to hang off my belt but it's what I had available and has enough juice to run it for about 20 hours or something stupid.

We're having a mid-winter 'light show' thing at the moment and I wore it out again last night (the opening night), I should've done a mainy on foot but I didn't really have the gumption for it and just stayed in the one pub all night. One does feel a bit self concious wearing it although on the solstice I walked home lit up like an xmas tree some time late at night (about an hour's walk).

Hacker Hacking

It turned out to be more work than I expected, from working out how to lay out and attach the leds (sewing them on, so I need to unsew to wash it), soldering up an adapter board, plus of course all the coding.

I started with some of the code in FastLED but all I really have left is some of the colour palettes.

I used Arduino initally to get the devices 'live' but quickly moved onto the FreeRTOS sdk - Arduino is interesting enough but its' a bit clunky to work with compared to proper tools. And I gotta say some of the quality of code is pretty low. I also started the LEDs showing with an ESP-01 board (esp8266) but then moved to an ESP32-C3 which is a much more interesting board. It's the first time I've played with a RiscV processor - TBH I find some of the ISA decisions a bit weird but due to the simplicty of the instruction set and enough registers the compiler mostly does a pretty good job of compiling it. Mostly. It does some weird shit when you return a structure in registers (a 2-vector) like move the stack pointer down and up and doesn't store anythin gon the stack.

The first time I wore it for the solstice I noticed the colours were a bit flat - the Perlin noise from FastLED wasn't being scaled qutie correctly so it was missing a big part of the range. I experimented a lot with it but ended up scapping it and converting the Java implementation of Simplex Noise from Stefan Gustavson into C and then into fixed-point. I also experimented with a lot with the code, various micro-optimisations and using a hash function rather than a permute table, gradients generated from bits or from lookup tables, and so on.

I was going to write a text scroller and even found (and created) some tiny fonts. But in the end I couldn't think of anything worthwhile to write so I decided not to bother coding it up. I created some tiny animations but they looked a bit shit with such a small number of pixels to work with so decided to drop them as well. Instead I render some simple geometric shapes on the fly using signed distance fields which also let more easily play with the colours. This was another journey into writing some fixed-point affine transforms, sincos functions and inverse square root which the internet provided starting points for which I cleaned up or simplified for better RISCV optimisation. And I implemented a version of the R250 random number generator but with a smaller number of coefficients and parameter choices which sped it up a bit more and use that to drive everything. I even hooked up a web server I wrote (not using the ESP SDK one) that you can connect to via wifi but I couldn't really think of anything useful to do with it.

I was worried about the cost of calculation and spent a good few days trying various optimisations but the simplex algorithm was already significantly faster than the noise routines from FastLED and in the end it wasn't a problem. I think the fastest 3D simplex calculation was about 280 cycles, the FastLED 3D noise was about 520 iirc. There are only 50 leds and the colours are easily updated 125 times/second - that's with up to two planes of 3D Simplex Noise or a basic SDF graphic. One somewhat small but still effective optimisation technique to remove the 8 and 16 bit integral types used heavily in ARM or AVR code - these usually require extra operations since the RISCV CPU has only 32 bit types.

The gamma curve of the leds I have is pretty rough - at the low end the steps are very noticeable so I implemented 2 bits of temporal dither (aka 'frame rate control') to try to help. So the LEDS themselves are actually updated 500 times/second and every fourth timeout I re-render the graphics. There is more that could be done to adjust the colour curves and so on but really I couldn't be bothered. I also didn't investigate the ESP32 timers and interrupts and just run it off an RTOS timeout handler.

So anyway I came up with 2 different noise types - one a higher contrast scaled simplex noise with mostly monochromatic palettes, and a smoother one with more colourful palettes. Apart from the z dimension the smoother one can also move up or down, left or right. And 5 different SDF patterns - a line, a cross, a rectangle, half plane, quarter plane and two quarter planes. These rotate or move and the line/cross/rectangle are repeated on an 8x8 grid. There's about a dozen different palettes plus 8 monochromatic ones created on the fly which can also be complemented (i.e. purple+green or just purple+black). These run for a randomised time and then slowly fade into the next routine. One last thing I added was it flashes for 5 seconds every now and then (at different rates) and on a separate cycle to everything else just to add a bit more bling.

I even wrote an Xlib 'kilt simulator' I could use to rapidly test the routines!

Hard noise in purple.

Rotating fat SDF line.

Ahh well that kept me off the streets for a couple of weeks and got a few laughs and a lot of weird looks. I'll (probably?) eventually get around to uploading the code, I have to work out where I got all the bits from first. I'm not involved with any forums any more and mastadon isn't really my thing so nobody will end up seeing it anyway. I filed a bug report with FastLED about their 8 bit blend function which isn't quite correct.

It was also fun doing a bit of coding again - although CMake could certainly fuck off. Shit like that puts me off wanting to code again for a job, although maybe I should start thinking about it again.

Tagged esp32, hacking.
Driver for HLK LD2410C | Summer
Copyright (C) 2019 Michael Zucchi, All Rights Reserved. Powered by gcc & me!