Ok, I understand now. You're right, these Chinese MFUs often prefer to toggle the ground signal rather than the positive, so you were correct to use the button input D4 (which triggers when held to ground) rather than the 5 volt input A0 (which triggers when brought to 5 volts). Your friend correctly identified the problem with the 5v input which was left floating, and disabled it by setting it to OUTPUT. That works fine. For others reading this, you can do the same, or as mentioned before, add a resistor between A0 and ground if you don't want to change the code.
18:27:40.756 -> Button State: 118:27:41.021 -> 18:27:41.021 -> ---------------------------------------------18:27:41.021 -> BATTLE INFO18:27:41.021 -> ---------------------------------------------18:27:41.021 -> Is Repair Tank? No18:27:41.021 -> Fire Protocol: Tamiya18:27:41.021 -> Hit Protocol 2: Heng Long18:27:41.021 -> Repaired by: Clark Repair18:27:41.021 -> Send MG IR Code: No18:27:41.021 -> Accept MG Damage: No18:27:41.021 -> Damage Profile: Tamiya Spec18:27:41.021 -> Weight Class: Medium18:27:41.021 -> (6 cannon hits, 5.0 sec reload, 20.0 sec recovery)18:27:41.064 -> 18:27:41.064 -> 18:27:41.064 -> 18:27:51.406 -> Button State: 118:27:51.671 -> 18:27:51.671 -> ---------------------------------------------18:27:51.671 -> BATTLE INFO18:27:51.671 -> ---------------------------------------------18:27:51.671 -> Is Repair Tank? No18:27:51.671 -> Fire Protocol: Tamiya18:27:51.671 -> Hit Protocol 2: Heng Long18:27:51.671 -> Repaired by: Clark Repair18:27:51.714 -> Send MG IR Code: No18:27:51.714 -> Accept MG Damage: No18:27:51.714 -> Damage Profile: Tamiya Spec18:27:51.714 -> Weight Class: Medium18:27:51.714 -> (6 cannon hits, 5.0 sec reload, 20.0 sec recovery)18:27:51.714 -> 18:27:51.714 -> 18:27:51.714 -> 18:28:27.490 -> Button State: 118:28:27.753 -> 18:28:27.753 -> ---------------------------------------------18:28:27.753 -> BATTLE INFO18:28:27.753 -> ---------------------------------------------18:28:27.753 -> Is Repair Tank? No18:28:27.753 -> Fire Protocol: Tamiya.... cannot copy more lines ----> Rongyos
// CANNON FIRE// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>>void FireCannon(){ if (!Tank.isDestroyed) // Check if the tank is not destroyed { if (Tank.CannonReloaded()) // Only fire if reloading is complete { if (Tank.isRepairTank())
My happiness was not long. Unfortuntely, the phantom firing is not visible on the serial monitor, but still there. I have another idea with this, can you please put a code which activates the IR emitter pin a little bit later? I mean, the ir pin activated or start to wait the cannon function after 2 secs from bootup. I put a button state in every initial bootup but its value 1 every time.
#define USE_5VOLT_TRIGGER false
Referring the reload led notification, unfortunately its not working. If I set it true its on all the time, until it gets a hit, making hit notification effect but reload notification is not active.
MOD: I just realized I can shoot the cannon after being destroyed (during recovery time). It is not desirable, so I just modified the cannon.ino with this simple stuff (tested, working)
The GitHub is now updated with all these changes. I hope now everything will work, please let me know your results.
08:17:47.916 -> ---------------------------------------------08:17:47.916 -> BATTLE INFO08:17:47.916 -> ---------------------------------------------08:17:47.916 -> Is Repair Tank? No08:17:47.916 -> Fire Protocol: Tamiya08:17:47.916 -> Hit Protocol 2: Heng Long08:17:47.916 -> Repaired by: Clark Repair08:17:47.916 -> Send MG IR Code: No08:17:47.916 -> Accept MG Damage: No08:17:47.916 -> Damage Profile: Tamiya Spec08:17:47.916 -> Weight Class: Medium08:17:47.916 -> (6 cannon hits, 5.0 sec reload, 20.0 sec recovery)08:17:47.916 -> 08:17:47.916 -> 08:17:47.916 ->
Hi Rongyos, At this point there are so many different symptoms which don't seem to have any relation to each other, that it is hard to say what is going on. If the board board is reseting/freezing/locking, or just in general acting bizarre (not completing the serial statements, erratic servo behavior, etc...) something is not right, but yet I experience none of these on my end. So there are two possible explanations: 1. Possibly we are still struggling with a compiler issue. I kind of doubt it, but if you want to replicate my setup I am using Arduino IDE version 1.8.13 with the AVR Boards set to 1.6.20. We already discussed changing the boards to 1.6.20, but maybe there is a difference with the compiler itself. You could try downloading and installing 1.8.13 from this link, and again make sure the AVR Boards is set to 1.6.20, and see if that improves anything. 2. The second option, is that you are using modifications to the code that are causing problems, or there are electrical issue with your custom board. Those are things only you can troubleshoot, but through a process of elimination it is still possible to reduce the number of possibilities until you find the culprit. [...]In summary, the only way to solve any technical problem of this kind is to simplify everything down the absolute minimum until you arrive at a state where things work as they should. Only then can you begin to make changes, one at a time, testing at each step, until a problem occurs. Then you know what the problem is.
2. there WAS a freeze. But it is a hardware issue. I think during the experiments I burnt out the IR emitter transistor or IDK, but when I try firing now, it fires 1 or 2 and the arduino is freezing. When I remove the IR LED (only the led) there is no issue anymore. Strange, there wasn't this issue before I could make a lot of cannon fire with this PCB.
But, when I connect it to the MFU and power it on (via the MFU PSupply) it does a phantom firing. I tried to disconnect the airsoft wire and power it on by the MFU and it was fine, worked correctly without phantom firing (I should probably make a hotkey in windows to write "phantom firing" ). I assume the Taigen "switch on" this pin later. Or (worst case scenario) it is always on LOW? (When I put digitalRead its always said it is 1 (high, right?)
You are correct, if digitalRead returns 1 that means HIGH. I'm certain the Taigen MFU keeps this pin HIGH except when the airsoft is fired, at which point it is held to Ground, but that doesn't mean there couldn't be some "noise" or a very brief signal on this pin when the Taigen starts - not long enough to activate an airsoft unit, but long enough for the Arduino to detect it and fire the cannon.
Now that I am thinking about it, it is also likely the voltage of this pin from the MFU, when the airsoft is not active, is greater than 5 volts. Of course the Nano can be damaged with input voltages higher than 5 volts, so this could also be a source of problems. You should try to measure this pin from the Taigen MFU with a voltmeter. If it is greater than 5 volts, there are ways to protect the Arduino, but we need to know what the voltage is.
It would also be good to check some other outputs on the Taigen, there are two more options I can think of: the flash trigger, and the IR port. I don't have a Taigen to test and my memory is not perfect, but I believe the flash pins were 5 volts. If so, that would be a better choice to connect to the Arduino.
So every time at least 1.9V is there in this pin. BUT! When I checked this pin switched off (fortunately my switch is disconnecting the + wire) connecting multimeter to battery + and airsoft pin it was around 7V visible (not much less then the battery actual voltage *DOUBLECHECKED it was 6,64 - 6,62Volts). When switching on the MFU its dropped from 7V to 1.99V and stayed there until I (I mean, my dear wife who helped me) fired the tank and it was 7.04V again (which is the actual battery voltage)
No, those are not activated until receiving a signal from a microswitch (it is located in the airsoft or recoil unit and pushed mechanically by those units). The initial triggering signal is from the airsoft, anyway Or.... maybe that should be solution if I connect the airsoft signal to the microswitch pin and then, the MFU triggers the gun fire function then sends out the 5V to IR. If so, I have to redesign my board again, and order it from pcb manufacturer :'(
Only some testing can answer these questions.
Very good! I suppose that does not solve the initial firing of the cannon when the Taigen MFU first powers up.
I'm glad you figured it out, and thanks for letting us know. After a very long time it sounds like you have a fully working product, congrats!