hi, i have this project, i have a sensor attached to my atmega328 which senses if an object passes in front of it, i have connected the serial connection to excel using netcomm successfully, now, the goal of this project is that i have a count of how many objects pass in front of the sensor, i need this count to be inside the MCU and also excell. Meaning that if the excell has a number of 5, and the arduino was resetted it would resume the count on 5. but if the excell wasn't opened the arduino should keep the count where it left off, for example, if the count was on 8 and for some reason excell crashed, the arduino would keep the count from 8 to whatever number of objects passed after it.
The approach i thought of is something like having a bidirectional conection, so that everytime the arduino senses an object it will send the count number it has, then excell would make a comparison of the count and know which one to use, if another number else than the one arduino sent was the one used then it would send arduino the real count so it would update itself.
Im not sure how to accomplish this, im not asking to write a code, maybe just the steps the program should be doing, i've never worked with developing some kind of protocol, should i send some keyletters meaning each something?
simple is always the best, i wish to be able to reset it, how could i tell arduino if you receive through serial the word erase, restart the count to 0?
pato_llaguno:
hi, i have this project, i have a sensor attached to my atmega328 which senses if an object passes in front of it, i have connected the serial connection to excel using netcomm successfully, now, the goal of this project is that i have a count of how many objects pass in front of the sensor, i need this count to be inside the MCU and also excell. Meaning that if the excell has a number of 5, and the arduino was resetted it would resume the count on 5. but if the excell wasn't opened the arduino should keep the count where it left off, for example, if the count was on 8 and for some reason excell crashed, the arduino would keep the count from 8 to whatever number of objects passed after it.
The approach i thought of is something like having a bidirectional conection, so that everytime the arduino senses an object it will send the count number it has, then excel would make a comparison of the count and know which one to use, if another number else than the one arduino sent was the one used then it would send arduino the real count so it would update itself.
I'm thinking this might be backwards. My first approach would be something like this pseudocode:
if Object is sensed then do {
if excel is available then do { // If excel isn't availalble there is an issue, but we want to keep the count going while the issue is resolved
get numberFromExcel
if numberFromExcel is greater than localCount then do { // If numberFromExcel is greater assume Arduino reset and use the larger of the two
store numberFromExcel into localCount
}
Increment localCount
send localCount to excel
}
else do { // Excel isn't availalble so we will keep counting on our own until it comes back.
increment localCount
}
repeat
This takes all the processing away from excel and keeps your program flow all in one place (the Arduino). I haven't done anything like what you are doing so I don't know if that check for excel is a valid check. You don't want it to be a timeout check because you may have another sensor event while waiting for the timeout. If it is a valid check, you should also probably check to make sure the right file is open.
I suspect the concept here is a little more complex than your question implies ...
Suppose that the number in Excel is not the same as the number in the Arduino - how do you know which is correct?
What happens if the Arduino crashes and misses an object?
I think for simplicity you should decide that either Excel OR the Arduino is the master depending on your analysis of which is most likely to fail (Excel, in my view).
If you decide that the Arduino is the master then Excel can query it whenever it needs the latest number.
If you decide that Excel is the master then the Arduino doesn't need to store anything - just pass a "1" to Excel every time it detects something. If Excel is offline the Arduino could keep a temporary count and upload it to Excel when possible. Excel would then add this number to the total it already had and the Arduino would reset its count back to zero.