So I discovered:AssafL wrote:Arduino is awesome because you actually get to do very little programming. It is actually about taking stuff others wrote and using it in creative ways.
The first line of the display shows the analog A/D count and calculated input voltage from the pot on the left (range 0-5VDC, as shown on the big meter.) The second line shows the PWM D/A count and output voltage, as shown on the small meter (a little hard to see: it says 5.044V.)
Input and ouput are only off by about 0.02V, which is not material for the gear pump. The error is probably in the mapping numbers I lifted from the example code. But they appear to be pretty standard for 5VDC applications -- I've seen the same numbers in several examples. The conversion from A/D and D/A counts to voltage is based on factors I calculated, and they don't always match the meters due to the setup not being completely linear. Here's what it reads with the pot set to the middle of the range:
It's a little closer because that's where I calculated the conversion factors. That's also a more likely value for the gear pump, which never runs anywhere near max speed. Will revisit the D/A mapping and conversion factors when I connect the real pot.
In the first pass I didn't use an RC circuit to smooth the waveform. My meter deals with that just fine, and I suspect the gear pump would, too. It might even smooth the input signal. The frequency was about 500 Hz because the loop has a 2 ms delay to let the A/D converter stabilize. I extended that to 10 ms and got a more stable reading. Later I added a simple RC circuit consisting of a 15K resistor and a 1uf capacitor (happened to be tantalum.) That reduced the ripple to about 2 Hz. Haven't looked at it on a scope yet.
As you said, virtually all of the code came from two examples. The read/write code is from an example in the intro to using the online IDE. The LCD code came from a Hello World example in the manufacturer's driver library (Adafruit.) The rest was just calculating the conversion factors and aligning text on the display. It's 74 lines of code, most of which is comments, literals, etc. The heart of it is only 30 lines of code, and it could be done in less without the display formatting.
The code is most of what I need to do the gear pump speed limit. Just have to connect the pressure transducer and read it in the loop. When the limit is reached, it'll reduce the motor voltage in steps until the pressure limit is reached. Below that, the pot will determine motor speed and pressure. The display will show current pressure in BAR, the pressure limit, the motor voltage, and the motor RPM. I'll use the buttons to toggle between a limit of 10.5 BAR and 12 BAR, or maybe to set a specific limit (not sure if I can store any parameters in flash -- I do have an SD card interface if not, but that's a little more work.)
What's amazing about this is that I haven't read any books or tutorials about programming the Arduino and I haven't even looked at the I/O and library commands yet. The syntax looks like a simplified version of C, and I know several variants of that language. Yeah, I've been programming for almost half a century and I've done some PIC programming, but this was a lot easier than I expected. I'm pretty sure I can implement the rest without learning any new commands or syntax, though I'll probably Google around for pressure limit code or something similar.
The coding and testing took less than an hour. I probably spent a couple of hours troubleshooting two issues with the IDE. One was a virtual COM port conflict (my fault, but bad error message on their part) and they had a very old version of the LCD driver library that had issues saving/reading files (pathnames were all wrong.) Had to download and import the latest version. This is the kind of stuff that always takes the most time. The coding part usually goes pretty fast. The hardware assembly was straightforward, but I spent some time building a proto board to use it's connectors and breadboard (for the RC circuit.) Ended up removing and reinstalling headers on the LCD a couple of times, but that had to do with changing my mind about how to stack the boards.
I have to admit, it was fun!