Hello,
I have a Arduino Uno R3 with a 16*2 Linksprite 16 X 2 LCD Keypad Shield for Arduino - LinkSprite Playgound LCD display shield that is hooked up to a flow meter to read pulses and totalize flow. This is mounted on a farm sprayer that is pulled behind a tractor.
Initially I had the Arduino hooked directly up to the DC battery power on the tractor. While I knew I was pushing the limits with the Arduino voltage regulator only rated for 15 volts and the alternator on the tractor outputting 13-14 volts, the power draw was very low so I thought it might be OK. Initially it appeared that the display worked fine, but I noticed that sometimes I would get strange characters showing up on various parts of the display. Sometimes the data I was displaying would show up in a different part of the display in addition to where it was suppose to be. If I would push the reset button, (which executes a lcd.clear function) the display reads correctly and the extra characters go away.
I then tried to power the project with it still hooked up to the tractor, but the tractor not running. I left it powered on this way for a day with no problems. I figured there must be some type of electrical noise or spike in the power that was causing my problems, so I hooked up a small DC to DC converter out of an old cell phone car charger. The converter is a switching type based on this IC MC34063 Datasheet pdf - DC to DC converter controller. Operating from 3.0V to 40V. Output switch current of 1.5A without external transistors. - Contek Microelectronics. It is set up to output 8 volts. After powereing thru this converter I still have the same problem, not only when the tractor is running, but all the time.
I don't believe the issue is in the sketch, but I will post it below.
In looking around the forum a little I picked up that repeatedly using the lcd.print function may not be a good idea if what it is printing doesn't change. I also saw delays being added in another post. Because it worked fine with the tractor shut off and powered directly from the battery, I am still thinking it is a power issue, but I don't know for sure. If anyone would know what is causing this problem and how to rectify it, I would appreciate the help.
Thanks!
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int pulseIn2 = 2; // interupt number 0
const int kFactor = 1358; // calibration constant with two implied decimals
const int resetButton = 3;
volatile int pulses;
unsigned int gallons;
void setup()
{
attachInterrupt(0, countPulse, FALLING);
pinMode(10, OUTPUT); // backlight
digitalWrite(10, HIGH);
pinMode(pulseIn2, INPUT);
digitalWrite(pulseIn2, HIGH);
pinMode(resetButton, INPUT);
digitalWrite(resetButton, HIGH);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("DNS Farms");
lcd.setCursor(2, 1);
lcd.print("flow totalizer");
delay(2000);
lcd.clear();
}
void loop()
{
uint8_t oldSREG = SREG; // save current interupt status
cli(); // disable interupts (can also use noInterrupt())
if(pulses >= kFactor)
{
gallons++;
pulses = (pulses - kFactor);
}
SREG = oldSREG; // restore old interupt status
lcd.setCursor(5, 0);
lcd.print(gallons);
lcd.setCursor(3, 1);
lcd.print("Gallons");
if(digitalRead(resetButton) != HIGH)
{
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("*RESET*");
delay(1000);
lcd.clear();
gallons = 0;
uint8_t oldSREG = SREG;
cli();
pulses = 0;
SREG = oldSREG;
}
}
void countPulse()
{
pulses = (pulses + 100);
}