Count car-starts
-
And no, movin the code from loop to send does not help. The problem is that you will get recursive calls. send calls resend which calls send which calls resend which calls send which calls resend....and so on. For each call, the Arduino will store all variables on the stack and memory usage will grow and grow.
-
And no, movin the code from loop to send does not help. The problem is that you will get recursive calls. send calls resend which calls send which calls resend which calls send which calls resend....and so on. For each call, the Arduino will store all variables on the stack and memory usage will grow and grow.
@mfalkvidd
OK, so you have to go back to where it comes from -
@mfalkvidd
Sorry, didnt work. Almost same errorCar_counter_1.2:84: error: expected '(' before '!' token Car_counter_1.2:86: error: expected '(' before '!' token expected '(' before '!' token -
@mfalkvidd
But if I put ! inside ( it worksif (!resend((volumeMsg.set(starts)), 5))return; -
OK, let me see if I understand your overall flow.
You have your node connected to switched 12V power in the car. When you turn on the car, the uC gets power, when you turn off the car it loses power. When the car is cranking, the voltage drops enough that it tends to reset again (or else the cranking position on your key switch actually cuts off auxiliary power used by the uC).
So if you are at home and in range, loop() is called by the Arduino runtime just once; at the end of loop() the uC goes into an infinite busy loop rather than return, staying there until power is lost again. If you are away from home or the packets are lost for other reasons, resend() will cause a return from loop(), so that loop() will be called again by the Arduino runtime, so it will just keep trying until either power is lost, or it makes contact with your wireless network again.
Meanwhile every time it starts, the first byte of eeprom is incremented in setup(), and then loop() tries to fetch VAR1, and send VAR1+eeprom(0) back. If it succeeds, then the first byte of eeprom is zeroed.
Right?
That sounds reasonable. My immediate concern would be inconsistent operation during cranking, if the input voltage went just low enough to make the uC unstable. If your car's wiring cuts the power entirely, not a problem. Likewise there appears to be time for the uC to boot, and fully update eeprom, before losing power during cranking. (It's best not to be writing eeprom as voltage drops). It appears that those are not problems for your system tho.
-
@tbowmo
Yes, but I dont want to jeopardize my cars :)
12v can be handle by the Arduino Pro min on RAW pin@flopp said:
12v can be handle by the Arduino Pro min on RAW pin
Cars go well above 14V during operation (as well as having noise glitches on top of that). If the regulator is only good up to 12v, operation could be marginal. Hence the suggestion from @tbowmo of a couple of diodes in the power feed, to drop a bit of the voltage as seen by the regulator.
-
OK, let me see if I understand your overall flow.
You have your node connected to switched 12V power in the car. When you turn on the car, the uC gets power, when you turn off the car it loses power. When the car is cranking, the voltage drops enough that it tends to reset again (or else the cranking position on your key switch actually cuts off auxiliary power used by the uC).
So if you are at home and in range, loop() is called by the Arduino runtime just once; at the end of loop() the uC goes into an infinite busy loop rather than return, staying there until power is lost again. If you are away from home or the packets are lost for other reasons, resend() will cause a return from loop(), so that loop() will be called again by the Arduino runtime, so it will just keep trying until either power is lost, or it makes contact with your wireless network again.
Meanwhile every time it starts, the first byte of eeprom is incremented in setup(), and then loop() tries to fetch VAR1, and send VAR1+eeprom(0) back. If it succeeds, then the first byte of eeprom is zeroed.
Right?
That sounds reasonable. My immediate concern would be inconsistent operation during cranking, if the input voltage went just low enough to make the uC unstable. If your car's wiring cuts the power entirely, not a problem. Likewise there appears to be time for the uC to boot, and fully update eeprom, before losing power during cranking. (It's best not to be writing eeprom as voltage drops). It appears that those are not problems for your system tho.
@Zeph
Fully correct :) thanks for summarizing.Car A have a built in USB where I, today, take power. I have to test if the voltage will go low so the uC will not get correct power but not 0 volt(restart), I don't know what will happen then. This was your question?
Car B have cigarette plug(12v output) so I use a converter to 5V, I think these converters can handle low input and still have 5V on output.I will test it for a while and count starts in my head(good luck)
Next idea is to have a buzzer to beep when it has successfully sent data to Controller, just as information and if it beeps when I am away from home I have a mistake in the sketch
-
@flopp said:
12v can be handle by the Arduino Pro min on RAW pin
Cars go well above 14V during operation (as well as having noise glitches on top of that). If the regulator is only good up to 12v, operation could be marginal. Hence the suggestion from @tbowmo of a couple of diodes in the power feed, to drop a bit of the voltage as seen by the regulator.
-
OK, let me see if I understand your overall flow.
You have your node connected to switched 12V power in the car. When you turn on the car, the uC gets power, when you turn off the car it loses power. When the car is cranking, the voltage drops enough that it tends to reset again (or else the cranking position on your key switch actually cuts off auxiliary power used by the uC).
So if you are at home and in range, loop() is called by the Arduino runtime just once; at the end of loop() the uC goes into an infinite busy loop rather than return, staying there until power is lost again. If you are away from home or the packets are lost for other reasons, resend() will cause a return from loop(), so that loop() will be called again by the Arduino runtime, so it will just keep trying until either power is lost, or it makes contact with your wireless network again.
Meanwhile every time it starts, the first byte of eeprom is incremented in setup(), and then loop() tries to fetch VAR1, and send VAR1+eeprom(0) back. If it succeeds, then the first byte of eeprom is zeroed.
Right?
That sounds reasonable. My immediate concern would be inconsistent operation during cranking, if the input voltage went just low enough to make the uC unstable. If your car's wiring cuts the power entirely, not a problem. Likewise there appears to be time for the uC to boot, and fully update eeprom, before losing power during cranking. (It's best not to be writing eeprom as voltage drops). It appears that those are not problems for your system tho.
-
@Zeph said:
It's best not to be writing eeprom as voltage drops
This is correct. However, shouldn't the BOD take care of that problem? Might be a good idea to set the BOD to 4.3V i stead of the default 2.7 though?
@mfalkvidd said:
@Zeph said:
It's best not to be writing eeprom as voltage drops
What does that mean exactly? Write to eeprom when power disappear, how is that possible without power?
This is correct. However, shouldn't the BOD take care of that problem? Might be a good idea to set the BOD to 4.3V instead of the default 2.7 though?
Perfect, then it will die sooner I guess
-
@mfalkvidd said:
@Zeph said:
It's best not to be writing eeprom as voltage drops
What does that mean exactly? Write to eeprom when power disappear, how is that possible without power?
This is correct. However, shouldn't the BOD take care of that problem? Might be a good idea to set the BOD to 4.3V instead of the default 2.7 though?
Perfect, then it will die sooner I guess
@flopp said:
What does that mean exactly? Write to eeprom when power disappear, how is that possible without power?
Writing is not instantaneous. It might only take a millisecond, but during that time things can happen. So when the write starts, there is enough power. But half-way through the write power is lost. That leaves the eeprom in an unknown state.
-
@flopp said:
What does that mean exactly? Write to eeprom when power disappear, how is that possible without power?
Writing is not instantaneous. It might only take a millisecond, but during that time things can happen. So when the write starts, there is enough power. But half-way through the write power is lost. That leaves the eeprom in an unknown state.
@mfalkvidd
Ok, I read it "to write as counting voltage drop" but it was "write to eeprom during voltage drop".
It is now clear, thanks -
A more exotic "hack" could be to tap into the OBD2 interface, and for example check engine RPM to see if motor is running, or not.
See this link..
http://mechanics.stackexchange.com/questions/24171/how-to-detect-engine-ignition-on-off-status-using-obd2 -
A more exotic "hack" could be to tap into the OBD2 interface, and for example check engine RPM to see if motor is running, or not.
See this link..
http://mechanics.stackexchange.com/questions/24171/how-to-detect-engine-ignition-on-off-status-using-obd2 -
There is an howto here http://www.instructables.com/id/Hack-an-ELM327-Cable-to-make-an-Arduino-OBD2-Scann/ looks pretty simple to get going, and read out the RPM's..