So, there was a little.... ahem....:uhoh3: saltwater incident with my dosing setup. Long story short, I'm down one Arduino UNO. I also don't have a serial enabled LCD anymore. :sad2:
Rather than order a new LCD, I'm going to use one that I have here. But this one isn't serial enabled. The old one used Rx and Tx and Serial.print. This one has to use the LCD library, and takes a whole bunch of pins.
So here's the solution. I'm going to put it on SPI. I have some pin extenders and other components that all speak SPI, so that's the natural way to go. If I need the four pins back, I can add on a pin extender at a cost of a single pin.
I'm going to take a 74HC595 8-bit shift register and connect the output pins in order to the data pins of the LCD 0-7. The SCK (pin 13) will go to the 595's clock. The MOSI (pin 11) is going to the data input on the 595. I'm going to use pin 10 for the enable pin on the LCD and also for the RCK on the 595. RCK puts the data from the shift register into the output register. Since I will have the OE (output enable) tied to ground the ouput will immediately show up on the pins as soon as I pulse RCK. Since the 595 is faster than the LCD, the same pulse gets the output onto the pins before the LCD reads it. So the same signal also serves as the Enable line on the LCD.
I'm going to do the SPI in 8-bit mode, just out of personal preference. I could have used 4-bit and saved one pin on the Arduino, but the code would be more involved and I think I am going to end up adding an 8-pin extender eventually to this project.
Since I'm using all the pins on the 595 for the 8-bit input, I have to use a pin on Arduino for the RS pin to the LCD. I'm going with pin 8 for right now.
Also, since I'm going to be inside the code and rebuilding the circuit, I figure I might as well get that stupid speed sensor out and put a proper rotary encoder in. The one I have doubles as a push-button. So it may end up being the only control I need. I need the pins anyway since I am going from 2 to 5 on the LCD. This one will only take 2, where the old one took 4.
And I might as well bring it up to Arduino 2.2 as well. Some of the template functions won't format in 2.2 so I'm going to move them to the C++ portion.
This got me to thinking about more to do while I'm under the hood. I don't like the way I have the schedule being input. I think I just want start time and stop time and an interval. And I want an option to set one schedule off the other so I don't have to input them both. That should be easy enough.
I'm also changing the time of day math from long to int and using minutes past midnight instead of seconds. Do I really need second by second resolution on my dosing times? I don't think so. By using int instead of long, I am saving myself almost 50% of the size of the schedule.
The last idea, and this one really got me thinking, was to save myself one more math step and make it so I can input my water volume and my alk recipe and put the dose in alkalinity units. Say, add 0.5dkH per day instead of add 60mL per day. That would be pretty simple math. Something to think about, but it would be one step towards a doser that you only have to input your test results into and it figures out the dosing to hit your targets for you. That might be cool. It tells you that you need to test, you input the result, and it alters the dose or does a booster if necessary. Hmmmmm.....
That might make this not such an overkill project of a doser.
Thoughts???