Random garbage on LCD, power supply issue?

I'm building a reverse geocache. It's powered by a nine-volt through a LM78M05C and then a Polulu power switch. I don't have any smoothing caps, but I've hooked it up with crystal, RST resistor, etc; it works.

When I run the sketch, sometimes it works perfectly. Other times, around 1 in 3, it gets to a point in the sketch where it prints garbage to the screen. It's often the same garbage though. That would seem to suggest to me that I'm not undersupplying something, but what else would cause a sporadic problem like that..?

Also, when I run it, occasionally the LCD backlight doesn't turn on, but the GPS unit does. Both of these are powered through transistors that are turned on in code... therefore... code issue?

I've eliminated all EEPROM reading/writing, so data is static, other than what gets edited while it runs.

Any tips?

Thank you much!

Alright, I’ve noticed something. It gets buggy as consecutive runs accrue. The first couple of runs one after another are fine, but then I start getting inaccurate readings from the GPS unit (which is fine, I’m sure), and inaccurate math from the arduino itself. I’ve tried with several ATMEGAs, and it’s consistent. Eventually garbage gets sent to the screen, and sometimes the LED backlight (a transistor turn on in setup) doesn’t come on.

Nothing is overheating… could this be a faulty crystal??

again, any thoughts very much appreciated, thanks guys!

It's powered by a nine-volt

If this is a 9v PP3 then it really is not suitable. The max current draw and capacity from one of these is not suitable for your application. That might be causing the issues you are finding.

Mowcius

I had considered that, but it indifferentiably presents the same issue when run from the USB-BUB (http://www.moderndevice.com/products/usb-bub) as well...

Could the USB-BUB have the same problem? And how would you suggest addressing this?

Also, when I run it, occasionally the LCD backlight doesn't turn on, but the GPS unit does.

Maybe you need some delays if it is turned on in setup. Sometimes there can be issues if you try and run things too fast in setup. Not sure about why but delays can help for many things.

It may be a current draw issue but it may not. If you have the same issue with the USB-BUB board then I would suspect that it's not as a USB port can supply at least 400mA which should be plenty unless your LCD is really large with a really power hungry backlight.

but then I start getting inaccurate readings from the GPS unit (which is fine, I'm sure)

This is a common problem. What baud rate is it on? How fast are you taking the data from it? Maybe you want to slow the baud rate. If it's only for the reverse-geocache then I would have thought it would not be very time-critical.

Not so sure about the characters on the LCD yet...

Mowcius

Everything is staggered on startup now, but there's still a problem after a couple runs, even without the GPS attached.

Also, when I restart it immediately after a failed run, sometimes the arduino doesn't even start.. Could this be memory corruption happening somehow? I think i'm powering it adequately, as USB BUB and 9V from a wall-wort produce the same results.

Thank you for helping me think of things to check! Any other ideas?? :P

It sounds like you have a whole heap of issues... Can you share code / schematics? If so then it will be easier for people to help, it sounds like you are getting noise on some of the connections perhaps? It would explain odd readings from the GPS and the LCD getting the wrong data...

Have you check all the connections or tried a rewire? Have you tried each component on it's own? I'd start by checking the gps unit, then check the LCD, then put just those together, see what happens...

Noise… that didn’t occur to me. Thank you. I’ll work on a schematic, mine was roughly done on a sheet of grid paper.

Here’s the code: (I’m

#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <NewSoftSerial.h>
#include <TinyGPS.h>

#define GPSRX 7
#define GPSPWR 8
#define PWROFF 9
#define LCDLED 11
#define SERVOCOM 12
#define SERVOPWR 13

template int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}

template int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}

LiquidCrystal lcd(14, 15, 16, 17, 18, 19);
TinyGPS gps;
NewSoftSerial nss(GPSRX, 3);

struct config_t
{
float DESTLAT;
float DESTLON;
int TRIES;
boolean SOLVED;
}
cfg;

void setup() {
//cfg.DESTLAT = 45.613797; // This is for reinitializing data after, for example, tries run out
//cfg.DESTLON = -122.936325;
//cfg.TRIES = 99;
//cfg.SOLVED = 0;
//EEPROM_writeAnything(0, cfg);

//DATA
pinMode(GPSPWR, OUTPUT);
pinMode(SERVOPWR, OUTPUT);
digitalWrite(GPSPWR, 1);
digitalWrite(SERVOPWR, LOW);
EEPROM_readAnything(0, cfg);
nss.begin(4800);

//GREETING
for (int i = 1; i <= 255; i++) {
analogWrite(LCDLED, i);
delay(3);
}
lcd.begin(8,2);
lcd.print(" Hi :)");
lcd.setCursor(1, 1);
lcd.print(“Hannah”);
delay(2000);

//CHECK TRIES
if (cfg.TRIES == 0) {
lcd.clear();
lcd.print(“You’ve”);
lcd.setCursor(0,1);
lcd.print(“used all”);
delay(2000);
lcd.clear();
lcd.print(“of your”);
lcd.setCursor(0,1);
lcd.print(“tries!:(”);
delay(2000);
lcd.clear();
delay(1500);
lcd.print(“Call me!”);
lcd.setCursor(0,1);
lcd.print(" ;)");
delay(5000);
SHUTDOWN();
}

//WAIT FOR GPS

lcd.clear();
lcd.print(“GPS WAIT”);
delay(1000);

lcd.clear();
lcd.print(“Locating”);
delay(1000);

bool newdata = false;
unsigned long start = millis();
while (millis() - start < 60000) {
if (feedgps()) newdata = true;
lcd.setCursor(0,1);
lcd.print(newdata);
lcd.print(" “);
lcd.print(60 - (millis() - start)/1000);
lcd.print(” ");
if (newdata) break;
delay(200);
}
digitalWrite(GPSPWR, LOW);

//UPON FAILING

if (!newdata) {
lcd.clear();
lcd.print(“GPS FAIL”);
delay(1000);

lcd.clear();
delay(250);
for (int i = 0; i < 3; i++) {
lcd.print(" Signal");
lcd.setCursor(0,1);
lcd.print(“failure!”);
delay(1000);
lcd.clear();
delay(300);
}
lcd.print(" Try");
lcd.setCursor(0,1);
lcd.print(“again…”);
delay(5000);
SHUTDOWN();
}

//UPON SUCCESS
float distance = 9999;
int km = 0;
if (newdata) {
lcd.clear();
lcd.print(“GPS SUCC”);
delay(1000);

float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
lcd.clear();
distance = distance_between(flat, flon, cfg.DESTLAT, cfg.DESTLON, 1);
if (int(distance) > 1000) {
distance /= 1000;
km = 1;
}
else {
distance = int(distance);
}

lcd.clear();
lcd.print(distance);
delay(1000);
}

//UPON SOLVING
if (distance < 10) {
lcd.clear();
lcd.print(“Hurray!!”);
lcd.setCursor(0,1);
lcd.print(":slight_smile: :slight_smile: :)");
delay(2000);
//operate servo here
delay(3000);
cfg.SOLVED = 1;
EEPROM_writeAnything(0, cfg);
SHUTDOWN();
}

//UPON NOT SOLVING
for (int i = 0; i < 3; i++) {

lcd.clear();
lcd.print(“NO SOLVE”);
delay(1000);

lcd.clear();
lcd.print(“Distance”);
lcd.setCursor(0,1);
if (km == 1) {
lcd.print(distance);
lcd.print(“km”);
}
else {
lcd.print(int(distance));
lcd.print(“m”);
}
delay(3000);
lcd.clear();
cfg.TRIES -= 1;
lcd.print(cfg.TRIES);
lcd.print(" tries");
lcd.setCursor(0,1);
lcd.print(“left ;)”);
delay(3000);
EEPROM_writeAnything(0, cfg);
SHUTDOWN();
}

}

void loop() {
}

void SHUTDOWN() {
for (int i = 255; i >= 0; i–) {
analogWrite(LCDLED, i);
delay(3);
}
pinMode(PWROFF, OUTPUT);
digitalWrite(PWROFF, HIGH);
}

Continued…

bool feedgps() { while (nss.available()) { if (gps.encode(nss.read())) return true; } return false; }

float distance_between(float lat1, float long1, float lat2, float long2, float units_per_meter) { // returns distance in meters between two positions, both specified // as signed decimal-degrees latitude and longitude. Uses great-circle // distance computation for hypothised sphere of radius 6372795 meters. // Because Earth is no exact sphere, rounding errors may be upto 0.5%. float delta = radians(long1-long2); float sdlong = sin(delta); float cdlong = cos(delta); lat1 = radians(lat1); lat2 = radians(lat2); float slat1 = sin(lat1); float clat1 = cos(lat1); float slat2 = sin(lat2); float clat2 = cos(lat2); delta = (clat1 * slat2) - (slat1 * clat2 * cdlong); delta = sq(delta); delta += sq(clat2 * sdlong); delta = sqrt(delta); float denom = (slat1 * slat2) + (clat1 * clat2 * cdlong); delta = atan2(delta, denom); return delta * 6372795 * units_per_meter; }

Also, when I restart it immediately after a failed run, sometimes the arduino doesn't even start.. Could this be memory corruption happening somehow? I think i'm powering it adequately, as USB BUB and 9V from a wall-wort produce the same results.

Hmm. This is intriguing. What arduino are you using or is it a custom board?

I would not have thought noise was your issue. Only maybe when the servo activates.

Mowcius

It's powered by a nine-volt through a LM78M05C and then a Polulu power switch. I don't have any smoothing caps, but ...

Does this mean that you didn't use the required input capacitor (or the optional output capacitor) for the voltage regulator? The input capacitor is required for a reason, it prevents oscillations that can produce erratic operation.

Don

It's a custom board.

I have caps immediately before and after the power regulator. Or rather, one from +9 to GND and on +5 to GND. I don't know why I didn't consider those "smoothing caps" in my mind...

Are there other places I ought to have caps?

Occasionally during regular runs there are even just extra characters printed to the screen. For example; it boots, says "Hi Hannah!" and then two seconds later is changes to "Hi Hannah!f"

Noise..?

Thanks for the support guys!

... oy vey. In an atypically revoltingly stupid move, I skipped out on checking the GPS as the culprit, assuming the servo would cause issues before the GPS would. I've had 8 clean runs now with the GPS disabled in firmware, allowing the box to time out and do a clean shutdown.

Here's the goober messing things up: http://seniord.ece.iastate.edu/dec0803/manuals/EM-406%20Product_Guide1.pdf

I've noticed that when I do power the GPS, the power LED is on veeery faintly at first, and then a couple seconds later it reaches it full brightness. I'm no EE, but does this mean this guy's got a "capacitance" that needs a bit of time to "fill"? (Don't laugh! :P ) Is it drawing too much current through the transistor..?

Orrrr, since it sends data about what it's doing even before it's "locked on", could it be signal line interference?

Thank you so much for keeping with me :)

I'll keep monologue-ing my discoveries in case anyone has an epiphany they wouldn't mind sharing:

The signal line for the GPS has been ruled out. The only time there is a problem is when the GPS is actively powered by the transistor. Which leaves, it seems to me, insufficient powering. I've supplied the LM78M05C with both 9 (~7 in reality) and 18V to rule the battery out.

Find below a partial circuit "diagram" - please forgive the crudeness.

Mystery solved. Transistors I was handed were, in fact, darlington pairs, causing rapid and extreme fluctuations in the power supply undetectable by your household mm.

Anyway, thanks for the tips.