This time I'm going to share about the "ZeroSeg".
The ZeroSeg hat is a kit that does require soldering, it's all through hole and goes pretty quick but read the directions since there are couple of places that need to be done correctly.
The basics for this hat are:
- 8 qty 7-Segment characters (good for numbers and a few standard letters)
- A few built in Characters are:
- H - High
- L - Low
- E - Error
- P - Programming?
- Characters can also be managed in software
- 8 decimal dots
- 2 buttons (that are on good pins and work great)
I probably will use this board on my outdoor robot, while it may be a little hard to read in bright sunlight, adding a little "sun visor" over it will help.
The Windows IoT perspective on this hat was a bit different, my first use of SPI communication. Also the first time I was required to use the async and await keywords. To be clear I've been a professional business application developer with .NET for 13 years now, I've used BackgroundWorkers, and Threads and on a few occasions Application.DoEvents() to keep my UI responsive. In concept the async and await are a nice easy way to send a request and wait for the response. In practice I was very frustrated first by the constraints of the concept and then by the fact that I couldn't do standard synchronous SPI communication.
To be clear I'm still learning async & await so there are probably solutions to my complaints. In my experience I couldn't use this concept inside a property body or in a class constructor. Sure I would probably agree that those are the wrong places to use it, but as I said I was forced to use async/await because there isn't a synchronous api available for creating an SpiDevice.
My plan was to create a wrapper class to abstract away some of the "bit-twiddling" and "register-stuffing" involved in using the MAX7219. The first step was to setup the Spi device in the class constructor. Well constructors can't use the async keyword. So, I made another method "ConnectSPI" that has to be called after the constructor before you can use the class. The next problem was ConnectSPI was returning to the main code before it had completed. Well the next lines were the configuration lines I used to setup the display how I wanted it vs the default configuration. These lines would then fail because they needed to communicate over the SPI connection which wasn't ready. I feel like it's a hack but I created an IsReady property that gets set when the ConnectSPI method completes, and my main code has a while statement that spins until it's Ready. Overall not my proudest code, but it works.
The simplest usage of my class looks like this:
ZeroSeg seg = new ZeroSeg();
seg.ConnectSPI();
while (!seg.IsReady){}
seg.SetText("01234567");
There is a lot more opportunity to create a full 7-Segment Character set, but I decided to stop at simple. Feel free to modify the code to suit your needs.

No comments:
Post a Comment