POV WiFi Streaming with c

While I wrangle the hardware for the next tutorial (building the actual poi), I thought I would add a side note here. The Processing and Java code I have been using for my Smart Poi WiFi transmission and image generation is kind of slow. There is a reason that most game developers choose to code their graphics in c/c++. It’s ten times faster. Take the image below:

Some nice triangle colours generated and transmitted using c

Why use c when I have a perfectly good processing sketch to make these types of colours and patterns in a few lines of code? Well if you look at the c program I uploaded to github here: https://github.com/tomjuggler/SmartPoiGenerate

The main.c has a delay in it.

//simulated delay:
            int c = 1, d = 1;

            for ( c = 1 ; c <= 4000 ; c++ )
                for ( d = 1 ; d <= 1500 ; d++ )
                {}
        }
//send next line to poi now

Without the delay, the pixels are sent too fast for the ESP8266 to display them in sequence! Actually, with the emulator running, the delay must be even greater, because of Serial speeds being so much slower than WiFi. The whole thing crashes pretty quick if you remove the delay here. For actual LED strip it’s a bit faster, I use c <= 500 or so.

Interestingly (frustratingly?), the delay in sending is not the only variable to take care of when streaming. Wireless card/software send speeds differ across devices, and congestion affects network send speeds. A slow send speed can result in a spread out image. Too fast and the image is compressed.

Ultimately, using c is so much faster that it’s worth it just for the speed increase. Have a look at the readme in the repo above, and the code of course. I have implemented some basic shapes like triangle, circle, square with colours in c. It works with the emulator from the previous tutorial.