handling EEPROM read failure

Hello,

I am in the middle of a project where a previously stored value in the EEPROM is read out to determine if a pin is to be pulled high or low. So the value stored in the EEPROM is either 0 or 1.

Now, if for some reason the EEPROM read should fail, I want the Arduino to just do nothing and give out a warning sound.

Programming a warning sound is not the issue, but how can I implement a safeguard against EEPROM read failure? Is there a simple command?

I have tried

if(!EEPROM.read(address)) { }

but of course that doesn't work when the EEPROM value is 0.

Any ideas?

  • Carguy

How many times are you writing to the EEPROM location? If it's not many, you really aren't likely to ever see a failure.

if for some reason the EEPROM read should fail,

How will you know that the read failed ? Maybe set a variable to say 99, do the read and test the value of the variable. If it is still 99 then the read failed. You will need to create a failed reading to test this. How will you go about that ?

This is likely an xy problem. Why are you so worried about EEPROM failing, exactly? It's not known to be unreliable.

ok this is basically all part of a simple car alarm system.

It is supposed to work like this:

When you turn the ignition to the "II" position (that's usually when your car stereo comes on and various lamps in the instrument cluster light up), you have to push a secret button for five seconds which will then either activate or deactivate the alarm. If the alarm is active (marked by a continuous warning sound) and you turn the ignition over to "III" to start the car, the horn and hazard lights will go off for 30 seconds and the fuel pump (crucially) will be shut down by switching the fuel pump relay.

So far, so good, but because I am messing with critical electrical circuits of my car, I want to make sure the Atmega just does nothing if there is any problem with it, i.e. for example if it can't retrieve the stored EEPROM value or if there's a dead connection somewhere.

The EEPROM will be read once every time you turn the ignition to "II", and overwritten if you activate or deactivate the system by pushing the button. The Atmega itself will be mounted on a standalone board and will be "always-on" behind a diode and a capacitor to minimize wear from switching cycles (although I haven't decided yet if being always-on puts more wear on it than switching it on and off with the ignition).

Under the best circumstances, the EEPROM will thus last close to 40 or 50 years, I know that.

I just want to make sure nothing affects driving safety or the ability to start the car if there's a problem, any problem with the Atmega. That's all.

The electrical environment of automobile power wiring is extremely noisy and can easily damage or destroy unprotected circuitry. Make sure you understand how to protect your circuitry against voltage reversals and transients of up to several hundred volts.

See for example http://www.littelfuse.com/~/media/electronics_technical/application_notes/varistors/littelfuse_suppression_of_transients_in_an_automotive_environment_application_note.pdf

Now, if for some reason the EEPROM read should fail...

That is simply not possible.

Detecting a write failure typically involves including a CRC with the data.

ok I see... well, all the better if an EEPROM failure isn't possible.

Still a bit new to Arduino, so forgive my ignorance :wink:

I also know that it's going to be a challenge to protect the circuit against the environment in a car. I am working on that in my head as we speak.

On the other hand, I have seen plenty of projects online where somebody put an Arduino in a car one way or another and never had any complaint or malfunction. So it's not impossible.

On the face of it, my project is relatively simple; monitoring the ignition, and letting a button switch an alarm system on or off which if triggered sounds the horn, flashes the hazard lights and switches the fuel pump relay off. Even this will have to be protected against noise and overvoltage and whatnot, but again, I could think of much more delicate Arduino/Atmega circuitry to be put in a car. The only real danger I can see is that my circuit would somehow shut the fuel pump off at highway speed, but that's one of the things I am trying to figure out at the moment.

I don't understand the purpose of the EEPROM here. What do you need to "remember" continuosly?
You could simply power the micro controller from position "II" of the key. Power cycling is not a problem for a chip of this little (electrical) power. It does not wear from self heating because it does not produce substantial heat.

  • Added after reading reply #7
    A good fail-safe mode would be to enter an infinite loop after you decided that the alarm is off, or even put the processor to sleep so it can not longer interfere with your fuel pump.

I want the Atmega to remember if the alarm was armed the last time the ignition was on. If I don't have the Atmega "always-on" (haven't decided yet which way I am going to do it) but only when the ignition is on, how is it going to know if it was armed or disarmed the last time it was on?

Also, if somebody thinks he can shut up my alarm system by disconnecting the battery after he triggered it, it'll be handy if the Atmega will remember that the alarm was triggered the last time the battery was connected, so it will go off again (this does not mean that the alarm won't quit at all; either way, I will program it so that any alarm sequence will only last 30 seconds at a time, and will only go off again if you've actively re-triggered it).

I see your point. But as stated by Coding Badly, an EEPROM read cannot fail, it will always return something. You have to decide what to do if it is not what you expected.

BTW how do you arm the alarm?

  1. it is annoying to have to remember to push a button to arm the alarm every time. Sooner or later you will forget to arm it.
  2. even if you deliberately do not want to arm it e. g. in your garage, you cannot be sure whether it is armed or not the next time you start your car, so you will always reach for the disarm button

Conclusion: it is best to always arm the system when you turn the ignition off. Maybe provide a delay of a minute in case you choke the engine and have to restart it. This makes it impossible to power it thru the ignition. An "always on" solution is more suited. You could even consider a small backup battery that keeps it alive in case the car battery is disconnected

Hello,

I've already thought of most of that.

olf2012:
v1. it is annoying to have to remember to push a button to arm the alarm every time. Sooner or later you will forget to arm it.

I see your point too; but one of my previous cars got stolen, and a while ago somebody tried to steal this car as well. Having to push a button to disarm an alarm system is a minor inconvenience compared to having to deal with cops and insurance when somebody does steal your car. It's a freaking nightmare.

And besides, knowing that it's a purpose-built system that I spent weeks developing myself will outweigh that inconvenience for a tech geek like me... :smiley:

There are aftermarket alarm systems aplenty on the market, yes; but none of them really do what I have in mind. And besides, a purpose-built system will take a bit longer for somebody to figure out. Time is something car thieves don't really have, at least not when they've already made an alarm go off unexpectedly at 3am on the curb and the car stubbornly refuses to start. There's still a good number of cops around in this part of town at night, and I live only three blocks away from a major police station. And arming/disarming the system will be deliberately cryptic and not self-explanatory.

olf2012:
2. even if you deliberately do not want to arm it e. g. in your garage, you cannot be sure whether it is armed or not the next time you start your car, so you will always reach for the disarm button

I've thought of that too. I'm going to mount a small 1.5'' cone speaker which I took out of an old desktop computer on the board, and it will sound a reminder tone everytime the ignition is on "II" and the system is armed. That way, there's pretty much no way you will actually forget to disarm it before you turn it over, unless you are indeed deaf. It'll be one three-second tone not much different from the one that the lights make when you forget to turn them off ("tone()" function with "666" as pitch parameter), so that'll also, at least initially, obfuscate its significance to a car thief.

I still welcome your ideas, but I've had this whole thing in my head for a few weeks now, so I have already thought a number of things through. Which doesn't mean there can't still be gaping holes in my logic, at least I wouldn't be surprised if there were... :smiley:

  • carguy