Registration Notice

Due to increased spam, forum registration must be manually approved by a moderator! Please see this post for instructions.

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Standalone Tank IR
« on: January 18, 2017, 08:18:27 PM »
For the fun of it I've taken some code from the TCB having to do with IR, simplified it and packaged it as a self-contained sketch for running on any Arduino Uno/Nano/or other board with ATmega328 processor.

The sketch can be downloaded here: TankIR

What does it do? Basically it lets you send and receive tank IR signals. Sending (ie, "firing the cannon") can be triggered in three ways:
  • Manually with a pushbutton (connect pin D4 to ground)
  • With a positive 5 volt trigger on pin A0 from some other circuit (greater than 5 volt inputs are possible but further input protection will be required)
  • Or the device can automatically fire a repair IR signal in response to being fired at by some other tank (useful as an "automatic tank repair station.")
The sketch can also control a recoil servo which will articulate whenever the cannon is fired (pin D8). Cannon fire will also cause a brief positive signal to appear on pin D6, this could be used to trigger a Taigen High Intensity Flash unit.

Within the sketch is a file called "A_Setup.h" (it will appear as a tab in your Arduino editor). That is where all user settings can be adjusted. Recoil servo end points and retract and return times can all be adjusted, as well as which protocols are sent and which are received.

Leave your Arduino attached to your computer with a USB cable and open the Serial Monitor from within the Arduino IDE to see informational messages printed during operation.

NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Hardware Notes
« Reply #1 on: January 18, 2017, 08:19:59 PM »
Hardware Notes

Included in the project files is a simple schematic in PDF format, please review it for wiring details. An Arduino Nano is shown but the pins are the same for the Uno.

You can connect a standard Tamiya "apple" directly to your Arduino (Tamiya 53447). The Tamiya apple combines an IR receiver and notification LEDs; the LEDs already have current limiting resistors included inside the apple. If you build your own receiver and use your own hit notification LEDs, you need to include your own current limiting resistor appropriate to the LEDs you choose. Most Arduinos can't source more than 40mA per pin.

For the IR transmitter you can use the Tamiya IR LED that is included with the apple. We have also found the Vishay TSAL6100 (DigiKey 751-1203-ND) to be a comparable replacement.

For maximum distance the IR transmitter should be driven far beyond its typical current rating, but even so it still needs a current limiting resistor. The LED will survive the high current because the IR signal is very brief. In testing we have found a 3.3 ohm, 1 watt resistor to be the best compromise between range and LED longevity.

If you wish to send repair signals it is often desired to prevent the beam from traveling very far. In this case a higher value resistor is used inline with the IR emitter - we have found 1k ohm will give you a range of just a few feet.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline Rileyelf

  • 11
    • View Profile
  • Brighton, UK
Re: Standalone Tank IR
« Reply #2 on: May 24, 2017, 02:17:27 PM »
Hello, new bloke here!

I designed my own Arduino powered tank battle system a while back, great to see this project!    I did a cut down version like this specific part to run a Panzerturm...  This runs a servo for a random time, fires the cannon then rests for a reload period and starts again.   Adds an interesting feature to the battleground!    I have also designed my own tank sound system which works pretty well.

Here's a video of the Panzerturm during dev....

https://www.youtube.com/watch?v=LaTYOzBSGUo

Drew.

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #3 on: May 25, 2017, 12:36:52 PM »
I've always known there were others working on Arduino tank projects, it's been nice to meet several of you recently. That's a good idea for your autonomous Panzerturm. A similar functionality could be added to the TankIR sketch, it is already set up to control up to 4 servos, right now only a single one is being used for the recoil. One of the others could be set to turret rotation and then as you did code it to turn and fire randomly. If you or anyone else would like to add these or other features don't hesitate to submit a pull request to the GitHub project.

I'm sure many people would be even more interested in your sound project. If you want to share more details about that feel free to start a thread in the Sound Forum.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Wibbly

Re: Standalone Tank IR
« Reply #4 on: November 16, 2017, 02:50:53 AM »
I built a standalone artillery gun, all of the IR cannon and hit functionality works, the gun is triggered via a microswitch acting as a hidden landmine, so when a tank runs over it, the gun is fired from a short distance away. Tanks can fire at the installation, and the led's flash in the diorama.

So far so good.

The one thing missing is a cannon sound.

To create a test bed I used a separate Uno and downloaded this sketch:
http://www.instructables.com/id/Audio-Player-Using-Arduino-With-Micro-SD-Card/

Quote
*/

#include <SPI.h>       //Enable use of SD library
#include <SD.h>        //Read MicroSD card
#include <TMRpcm.h>    //Play music from MicroSD card


//This value is assumed by the TMRpcm library, so I don't recommend altering it!
const int SD_ChipSelectPin = 4;

//Plug the speaker's red (non-GND) wire into this pin on the Arduino
//TMRpcm assumes this is 9 on Arduino, so I don't recommend altering it!
const int speakerP = 9;

//File name of the WAV audio file loaded on the MicroSD card
//Remember to include the file extension (should be .WAV)
const String audioFileTitle = "music.wav";

//Create TMRpcm object
TMRpcm tmrpcm;

void setup(){

  tmrpcm.speakerPin = speakerP;

  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    Serial.println("SD fail"); 
    return;   // don't do anything more if not
  }
 
  //Need to convert String variable to char*, per TMRpcm documentation
  char charBuf[audioFileTitle.length()+1];
  audioFileTitle.toCharArray(charBuf, 50);
 
  //Play the test sound
  //This sound file will play each time the Arduino powers up or is reset
  tmrpcm.play(charBuf);
 
  //Report to the user
  Serial.println("Sound file played!");
}

void loop()

tmrpcm.play("test.wav");
//delay(5000);
}

which is part of this project on Instructables.

To get a decent volume I used:

Arduino Uno
PAM8403 amplifier, the version with a volume control.
Voltage regulator set to 5v to power the amplifier (a resistor could be used)
SD card

After a bit of playing around, it all works. I get the cannon sound when I press the Uno reset button.

So, I now have a tank IR system, and a sound system, but running on separate Arduino's.

Does anyone know whether I can import the sound sketch into the Tank IR sketch, and where it should go in order that I get the sound when the cannon is fired? I am also concerned regarding the wiring/circuits, eg is there a conflict between the SD card hook up and the Tank IR?


 

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #5 on: November 16, 2017, 01:49:42 PM »
Wibbly, I already added support for the Adafruit sound effects board to the project (as discussed here), no coding required, just use the sketch from the GitHub. Read the instructions on that page for how to interface with the Adafruit board, you can see I've also updated the schematic. It supports 4 sounds, cannon fire, cannon hit, destroyed, and repair sound.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline CodeWarrior

  • 29
    • View Profile
  • Detroit suburb, Michigan, USA
Re: Standalone Tank IR
« Reply #6 on: November 06, 2020, 07:26:21 AM »
I hope it's OK to add a new post to an older topic but here goes:  I have downloaded the TankIR sketch into an Arduino Mega 2560 with the intention of using it with some of the Tamiya 1/35 tanks.  While I understand that it was pieced together from several other works it's nonetheless an amazing piece of code with clearly allot of effort having gone into it. 
I implemented the schematic exactly as shown in the .pdf and the code compiled properly without any problem.  The only change which was made was to the A_Setup file where the IR_FIRE_PROTOCOL was to to IR_TAMIYA_35.  The issue is that the circuit does not indicate a hit if one is received from my Tamiya Panther nor does the tank receive a hit when the circuit fires a shell.  Can someone confirm that the the code was tested on the Tamiya 1/35 platform and that no further changes were required other than what was already mentioned?  I would guess that the code was tested and that I have some issue with my setup but I wanted to ask the basic question before digging into things further.  I really don't want to take up anyone's time on this other than to get a quick response confirming that the setup should be working with the only change required having been the one I've already made. 
I would like to make sure that the TankIR authors (Luke + others?)  know that I am very appreciative of the work which has been done on it and the fact that it was made available to all of us.
There are 10 kinds of people:  Those who understand binary and those who don't.

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #7 on: November 08, 2020, 01:27:31 PM »
Hi CodeWarrior, my apologies for the slow reply. Yes, the firmware has been tested with a 1/35 Tamiya model, I used the Sherman but they should all be the same.

One thing you mentioned is that you compiled the code on an Arduino Mega2560 board, however the standalone TankIR firmware is designed for use on an Arduino Uno/Nano/328-compatible board. I don't know if that is part of your problem or if you just made a typo when describing your setup.

You can easily verify that your circuit is at least sending a signal by watching the IR emitter with a digital camera, or your phone, or by hooking up a standard LED with human-visible light to the output instead of an IR LED. This will at least tell you if the firmware is trying to do what you think it should. Beyond that there are many troubleshooting avenues to take, and where to start depends on where you think the issue probably resides.

I do believe the firmware works, so be sure to double-check your wiring and such.

Keep me posted on what you find and I'm sure we can figure out the problem eventually.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline CodeWarrior

  • 29
    • View Profile
  • Detroit suburb, Michigan, USA
Re: Standalone Tank IR
« Reply #8 on: November 08, 2020, 04:05:25 PM »
     Luke- I'm happy to receive a reply no matter how long it takes.  I appreciate your taking the time to write and share the benefit of your experience.
     I used an Arduino Uno with much the same results as using the Mega 2560.  I figured they were a similar core (328 I believe) and I am able to see IR shells being transmitted from both the TankIR (Mega 3560) circuit and the Tamiya Panther.  I recorded 5 IR shells from each and plugged them into a Google Sheet to compare them.  I used a WIO Terminal to read and display the IR timing in the Arduino IDE monitor.  You did a very nice job of documenting the structure of the unusual Tamiya 1/35 protocol.  With the aid of it I was able to see that the IR signal looks basically identical between the Tamiya and TankIR software.  I've included a screenshot of the first byte of so of each of the two groups of 5 signals.  The issue I'm having is that the WIO terminal only shows the first 50 marks and 50 spaces giving me 100 total bits worth of data.  It could be that the signals lose commonality after the 6th byte, although that would be surprising giving how well the two systems agree for the first 6 bytes.
     My next step will be to try the TankIR circuit on an 'Uno as you suggest.  If I can locate a true-blue 'Uno (versus a clone) I'll use that.  I don't know if clones vary much from the performance of a real 'Uno.  If that doesn't yield any results I'll log the full IR transmission of both TankIR and Tamiya systems.  I don't know why the WIO doesn't log the entire transmission but I may just write some simple code to log the whole thing.
CodeWarrior-TankIR-01.jpg
Standalone Tank IR CodeWarrior-TankIR-01.jpg
Views: 506
CodeWarrior-TankIR-02.jpg
Standalone Tank IR CodeWarrior-TankIR-02.jpg
Views: 509
CodeWarrior-TankIR-03.jpg
Standalone Tank IR CodeWarrior-TankIR-03.jpg
Views: 496
There are 10 kinds of people:  Those who understand binary and those who don't.

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #9 on: November 09, 2020, 12:48:35 PM »
Ok, you have made good progress already! It seems you have almost completely confirmed the similarity of the signals, which is good. The marks and spaces you have measured correspond exactly with what I have measured, and with each other.

There is some debugging code including in the TankIR project, if you uncomment these lines at around line 315 in the "Tank.cpp" file:
Code: [Select]
    IR_Decoder.decode();
    Serial.print(F("Decoded: ")); Serial.print(ptrIRName(IR_Decoder.decode_type)); Serial.print(F(" Value: ")); Serial.println(IR_Decoder.value);
    IR_Decoder.DumpResults();

It might help you see the full signal coming in from the Tamiya tank, or whether anything is being received or not. But I feel quite certain, as you surmised, that in fact the signals are no doubt the same for all 8 bytes, if you have already confirmed the first 6 (and I confirmed all 8 once upon a time!)

I'm inclined to think you might have a hardware or wiring problem since the firmware seems to be working correctly. I would double-check that you have the IR connected to the right pins, etc... (Use the camera trick to confirm that the IR is indeed transmitting). What IR transmitter LED and receiver are you using for the Arduino side - is it 1/16th Tamiya gear, Taigen, something else?

PS: In fact the 2560 (Mega) boards and the UNO (and other variants) use a different microprocessor, the former use the ATmega2560 chip and the latter the ATmega328. Of course either one can work, we use the ATmega2560 on the TCB, and the Uno for the standalone IR code. If the standalone IR code compiles on the 2560 board, that is a coincidence! Anyway, I'm sure your clone Uno is fine, I have used several without problems, and we can see from your capture that the firmware is running correctly.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline CodeWarrior

  • 29
    • View Profile
  • Detroit suburb, Michigan, USA
Re: Standalone Tank IR
« Reply #10 on: November 10, 2020, 02:18:01 PM »
     I did the following today:
     I took the TankIR shield off the Mega 2560 and placed it on an 'Uno.  Still no joy in terms of the Tamiya Panther receiving an IR shell.  Time to employ the trusty oscilloscope.  Looking at the 'scope trace I found that the IR LED (Vishay TSAL6100 from DigiKey) was indeed being driven with a signal.  I scratched my head for a bit and then decided to position the Panther within 10cm of the TankIR transmitter and, et voila, the Panther was shaken by a deadly infrared shell.  Success!  I recalled that I had increased the size of the IR LED limiting resistor so as to not risk overloading the IR LED.  While the WIO terminal could read the IR signal it seems that the Tamiya Panther needs a stronger signal.  Replacing the 1kΩ IR LED limiting resistor with a 3.3Ω (!) resistor, just like the schematic indicated I was to use, gave the TankIR circuit a very acceptable range for it's IR shells.  Next step was to investigate the IR receiver behavior.
     As I was already working with the o'scope I naturally attached the scope probe to the output of my IR receiver.  The receiver is a Vishay TSOP-38238, ordered directly from DigiKey.  I was not going to risk a bunch of unnecessary troubleshooting just because of having purchased potentially inferior surplus parts.  I did as you suggested and uncommented the debugging code you directed me to.  I was indeed receiving, and demodulating, IR shells from the Panther.  I monitored the 'Uno's A2 port ("Incoming hit sound trigger") expecting that it would change state if an IR shell was properly decoded.  Although I pummeled the TankIR circuit with multiple shells Port A2 never seemed to changed states. The test code in Tank.cpp did output data when a shell was fired but it seemed to stumble a bit after every 50th bit.  I decoded the first 3 bytes and included screenshots of that plus a .zip file of the test code dump in case you may have the time to briefly check them out.  Having already had more success for one day than I could handle I decided to call it quits at this point. 
    As you know I really appreciate all of the help you have given me so far.  I've already had more success than I could have hoped for in such a short period of time.

CodeWarrior-TankIR_Rx-01.jpg
Standalone Tank IR CodeWarrior-TankIR_Rx-01.jpg
Views: 490
CodeWarrior-TankIR_Rx-02.jpg
Standalone Tank IR CodeWarrior-TankIR_Rx-02.jpg
Views: 477
*
TankIR_Diagnostic_output-01.zip
(1.41 kB ~ Downloads: 137)
There are 10 kinds of people:  Those who understand binary and those who don't.

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #11 on: November 12, 2020, 01:46:53 PM »
Ok, you have made good progress. We are now halfway there! Yes, the 3.3 ohm resistor is very low, but we really have to overdrive the LED in order to get any range. I have found since the signal is so brief the LED can survive it quite well.

Now for receiving. In fact what you have reported tells me that some things are working as they should. It is actually as designed that the firmware seems to quit reading after the 50th bit, this limit is set by the RAWBUF define in the IRLib.h file (around line 247, there are some comments that go with it). You also found earlier some comments on how we send the 1/35 Tamiya signal - there is also a discussion on how we decode it, starting around line 378 in the IRLib.cpp file. You will see that for decoding of this particular signal, which is really quite different from the one all other models use (including Tamiya in 1/16th scale), we actually only read the first 3 bytes (no other protocol has those same first 3, or even the same receiving pattern, so we are not going to confuse it with something else). As you found with your Excel work, the firmware is actually detecting the first three bytes we would expect: 199, 242, 192

So we can rule out hardware issues, the Arduino is reading the signal from your Panther just fine, the issue is with decoding. I've spent some time refreshing my memory about what I wrote all those years ago, but I don't see any obvious problems with the code. The debug dump that you posted was exactly what we expect and it should have recognized it.

Let's try an even more detailed debugging routine. In file "IRLib.h" at or around line 52, you will see this line, which is also commented out:
Code: [Select]
// #define IRLIB_TRACE

Let's uncomment that, and also change it because it should be named this instead (so basically just replace that line with the following):
Code: [Select]
#define OP_IRLib_TRACE

Let's also change that dump test that we already uncommented earlier. This is what you had uncommented in "Tank.cpp" at around line 315:
Code: [Select]
    IR_Decoder.decode();
    Serial.print(F("Decoded: ")); Serial.print(ptrIRName(IR_Decoder.decode_type)); Serial.print(F(" Value: ")); Serial.println(IR_Decoder.value);
    IR_Decoder.DumpResults();

Let's change that first line to this:
Code: [Select]
    IR_Decoder.decode(BattleSettings.IR_FireProtocol);

This way it doesn't try to run through every possible protocol but only checks for the Tamiya 1/35 signal, since we already know that's what we're sending it.

Now give your Arduino a hit from your Panther and let us see what the Serial Monitor shows us...
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline CodeWarrior

  • 29
    • View Profile
  • Detroit suburb, Michigan, USA
Re: Standalone Tank IR
« Reply #12 on: November 13, 2020, 11:19:29 AM »
Luke Z-   Once again thank you for your help.  Unfortunately the TankIR circuit/software still does not recognize a hit from the 1/35 Tamiya Panther.  I made the two changes which you suggested and fired a shell from the Panther. 
     I posted pictures of a side-by-side comparison of the previous IR dump from TankIR and the dump with your suggested edits above.  The results are shown in the two .jpg’s attached below.  Not too surprisingly the two results diverged in their behavior after bit 50.  As you noted only the first 50 IR bits (start bit * 2 + 3 bytes *8 bits/byte * 2 IR bits/bit) are used anyway so this shouldn’t matter. I also included the screen dump in zip file below.  I know that no hit was sensed by TankIR because I didn’t see a change in neither port A2 nor D5 nor did I see any output in the serial monitor indicating a hit was received.  I have verified that the Tamiya Panther can fire a shell which can be sensed as a hit by putting the ‘Panther in Test Mode and having it shoot itself by firing at an IR reflective surface.
      I am a bit concerned about the statement from the compiler indicating:
“Sketch uses 25100 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 1864 bytes (91%) of dynamic memory, leaving 184 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.”
     This should not matter as anyone compiling for this core would get the same warning and yet the software was tested as functional.  FWIW I verified that the TankIR circuit can still produce shells which register a hit on the ‘Panther.
      I remain puzzled by the apparent inability of my TankIR implementation to receive infrared hits.


CodeWarrior-TankIR_Rx-03.jpg
Standalone Tank IR CodeWarrior-TankIR_Rx-03.jpg
Views: 255
CodeWarrior-TankIR_Rx-04.jpg
Standalone Tank IR CodeWarrior-TankIR_Rx-04.jpg
Views: 256
*
TankIR_Diagnostic_output-02.zip
(1.45 kB ~ Downloads: 135)
There are 10 kinds of people:  Those who understand binary and those who don't.

*

Offline LukeZ

  • 1196
    • View Profile
  • France
Re: Standalone Tank IR
« Reply #13 on: November 13, 2020, 03:36:51 PM »
Ok, I see the changes I suggested weren't sufficient, if it had worked it would have given us even more information about what exactly is causing the decoder to fail to identify the signal, but it would not have changed any inherent ability.

However, this comment caught my attention:
I am a bit concerned about the statement from the compiler indicating:
“Sketch uses 25100 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 1864 bytes (91%) of dynamic memory, leaving 184 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.”

In fact that should not happen, and to avoid that very situation is why we only decode the first 3 bytes of the 1/35th signal. Did you perhaps change the value of RAWBUF around line 246 in IRLib.h? That is the only thing I can think of that would blow up the global variable allocation (the value of RAWBUF should be 51). In fact the sketch should compile with something around 1,462 bytes of dynamic memory, around 71% of the total, not 91%.

Here is what I would suggest next - redownload the firmware from GitHub and start again clean, change only the IR_FIRE_PROTOCOL to IR_TAMIYA_35 in the A_Setup.h file, and try again and see what happens. If it still doesn't work, I will give you a sketch with the extra debugging options hopefully enabled this time.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline CodeWarrior

  • 29
    • View Profile
  • Detroit suburb, Michigan, USA
Re: Standalone Tank IR
« Reply #14 on: November 14, 2020, 10:08:31 AM »
Thank you for your extremely quick reply.  I did as you suggested: Reloaded TankIR from Github with the only change being made is to change IR_FIRE_PROTOCOL to IR_TAMIYA_35.  With just this being made compiling the code yielded the same statement from earlier:

“Sketch uses 25014 bytes (77%) of program storage space. Maximum is 32256 bytes.
Global variables use 1864 bytes (91%) of dynamic memory, leaving 184 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.”

This caution was present in the original code from the first time it compiled.  The behavior of the system with the reloaded code is the same as with the previous code:  The TankIR shells cause damage to the Tamiya Panther but there is no effect on the TankIR circuit from the ‘Panther shells.
You are right to think that I might investigate/consider changing RAWBUF to a larger value- I noted that the max value would be 255.  I figured this would not help the understanding of the issue as only the first 50 bits are read by TankIR to recognize a hit.  Because of this I didn’t make any changes other than what we discussed.
I’m wondering if there may have been changes made to the Arduino IDE which somehow altered the manner in which the code compiles.  It may be hard to see in the screenshot- I am using version 1.8.13 of the Arduino IDE.  I have included a screenshot of my Arduino IDE so you can see the compile environment being used.  It will be obvious that I use a "Dark Mode" color scheme as I find it a bit easier to view than the stock offering.  This should not have any effect on the compiler itself.
CodeWarrior_Arduino_IDE.jpg
Standalone Tank IR CodeWarrior_Arduino_IDE.jpg
Views: 258
There are 10 kinds of people:  Those who understand binary and those who don't.

 

bomber-explosion