In this tutorial for IoAbstraction’s taskManager I explain the differences between traditional loop based programming; which is very common on the Arduino platform and event based programming based on taskManager. Although event based programming looks slightly more complicated at first, as the sketch and surrounding code gets more complex, eventing will scale to that much easier. Eventing task frameworks make ongoing maintenance much easier. Example: Two LEDs blink at different rates.
Recently, I have made a fork of Arduino LiquidCrystal (HD44780 display driver library) that allows the library to work with the IO abstraction library, meaning you can configure a display to use Arduino pins, an i2c 8574 IO expander or shift registers by simply changing one line of code in your sketch. There are two additional examples provided with this version that show how to use the fork with both a shift register and an 8574 i2c IO expander.
Here we demonstrate the IO Abstraction library on an Arduino with a PCF8574 i2c 8-bit IO expander chip. We use the device in order to receive input from a switch and light an LED. It’s about the most basic example possible that has both input and output. To use this example, first download the IoAbstraction library. Devices such as the PCF8574 provide an easy way to expand both input and output capabilities using a single chip, and because it’s on i2c, needs only two pins from the Arduino (SDA and SCL).
If like me you use both 8 bit AVR and 32 bit boards, you’ve probably already noticed that there’s no EEPROM support on some 32 bit boards. I think that’s quite unfortunate as EEPROM storage is very useful for many applications. Relying on memory backup like many systems today do, is nowhere near as reliable (a flat battery loses everything). Further, I’ve even seen discussions where people suggest using an area of program Flash as an EEPROM, I don’t personally like it as flash write cycles are generally an order of magnitude lower than EEPROM, but it’s now supported via the EEPROM class wrapper.
Sometimes there is a need for more IO than can be catered for using an single set of pins, even on the MEGA, or maybe you just want to combine Arduino pins with some pins on an PCF8574 IO expander chip. In this case IoAbstraction now supports that, you create an abstraction of type MultiIoAbstraction. See the sketch that has Arduino pins and PCF8574 on the same IoAbstraction in the packaged examples.
IoAbstraction includes support for touch screens. The support is built in layers to allow for different drivers to be added over time. However, at the moment there is support for resistive touch screens on analog pins. This library can work with such touch screens regardless of analog input resolution, as long as the device is supported by IoAbstraction. As with switches and rotary encoder support, this component deals with debouncing the user input and also working out if the user has selected or held, therefore supporting drag operations.
Using IoAbstraction you can write a sketch / program that uses Arduino pins, shift registers and IO expander devices at the same time, very much like you’d normally use Arduino pins. This library also provides simple interrupt handling that again is consistent across Arduino, mbed and IO expander ICs. What do we mean by consistent, we mean that configuring a pin, adding an interrupt, reading from pins, and writing to pins is the same across Arduino, mbed, PCF8574, MCP32017 and shift registers.
I recently bought a Heltek Wifi kit 8 and noticed that although the board itself seems to be a good board the pin-outs, both online and on the silk screen of the board are wrongly specified. For example the silk screen shows SDA and SCL on non standard pins, but this is not the case as far as I can tell. To get this information, I’ve followed the schematic then proven these findings with in circuit testing to prove it.
Using SwitchInput for buttons and rotary encoders SwitchInput is a button and rotary encoder management library that treats button presses and encoder adjustments as events, similar to web and UI applications. Supporting as many switches and rotary encoders as you need, in an event driven way, working along with TaskManagerIO to keep your code clean. Key points: Buttons using either pull down or pull up logic connected directly or via any supported IO expander De-bouncing of events on all buttons and encoders to significantly reduce duplicate callbacks.
There are times when your program needs to react to your device being turned off, for example to save the current state of an Arduino sketch to EEPROM before shutting down, or to disengage relays in a power module to ensure there is a clean shutdown. Usually, the power loss detector is designed as part of the power supply, so here I’ve put together an example power supply that we can study, note that this is not intended as an exemplar of power supply design, and is rather incomplete, but to serve as a crude model that we can study to see how to detect power loss.