How to build a working IR Artillery Gun

This forum relates to the Open Source Tank Control Board (TCB). Please read the sticky and visit the main site to find out all about the board and how to install it.
T.Watson
Recruit
Posts: 37
Joined: Sat Jul 30, 2016 5:48 pm

Re: How to build a working IR Artillery Gun

Post by T.Watson »

I have tried your coding myself. from your video - I have been investigating and it seemed to me for the Anti-tank gun project sd storage should be the option and amplification as I like it 'Lemmy" loud :D

I decided to give it another go and started again- hence the question on the forum

Success for me and having no feedback buzzing etc has resulted from using an an Adafruit 'menucomands" for the Adafruit fx board which has the gun sound embedded, I am not using the sd board (I have one but its not on this circuit) - Iusing other libraries has resulted in feedback buzzing etc with 'menucommands' it stopped
Maybe I need to do a wiring diagram for you to have look at?

One of my friends is a serious programmer and he is/going to look at this as well, hopefully he will have had a look when I see him on friday - we will see...

I need to look at this a bit further myself - note I am new to programming - i like problem solving and as its a challenge......:D

here is the code dump


#include <Adafruit_TPA2016.h>

/*
Menu driven control of a sound board over UART.
Commands for playing by # or by name (full 11-char name)
Hard reset and List files (when not playing audio)
Vol + and - (only when not playing audio)
Pause, unpause, quit playing (when playing audio)
Current play time, and bytes remaining & total bytes (when playing audio)

Connect UG to ground to have the sound board boot into UART mode
*/

#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"


// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 5
#define SFX_RX 6

// Connect to the RST pin on the Sound Board
#define SFX_RST 4

// You can also monitor the ACT pin for when audio is playing!

// we'll be using software serial
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);

// pass the software serial to Adafruit_soundboard, the second
// argument is the debug port (not used really) and the third
// arg is the reset pin
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
// can also try hardware serial with
// Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);

void setup() {
Serial.begin(115200);
Serial.println("Adafruit Sound Board!");

// softwareserial at 9600 baud
ss.begin(9600);
// can also do Serial1.begin(9600)

if (!sfx.reset()) {
Serial.println("Not found");
while (1);
}
Serial.println("SFX board found");
}


void loop() {
flushInput();

Serial.println(F("What would you like to do?"));
Serial.println(F("[r] - reset"));
Serial.println(F("[+] - Vol +"));
Serial.println(F("[-] - Vol -"));
Serial.println(F("[L] - List files"));
Serial.println(F("[P] - play by file name"));
Serial.println(F("[#] - play by file number"));
Serial.println(F("[=] - pause playing"));
Serial.println(F("[>] - unpause playing"));
Serial.println(F("[q] - stop playing"));
Serial.println(F("[t] - playtime status"));
Serial.println(F("> "));

while (!Serial.available());
char cmd = Serial.read();

flushInput();

switch (cmd) {
case 'r': {
if (!sfx.reset()) {
Serial.println("Reset failed");
}
break;
}

case 'L': {
uint8_t files = sfx.listFiles();

Serial.println("File Listing");
Serial.println("========================");
Serial.println();
Serial.print("Found "); Serial.print(files); Serial.println(" Files");
for (uint8_t f=0; f<files; f++) {
Serial.print(f);
Serial.print("\tname: "); Serial.print(sfx.fileName(f));
Serial.print("\tsize: "); Serial.println(sfx.fileSize(f));
}
Serial.println("========================");
break;
}

case '#': {
Serial.print("Enter track #");
uint8_t n = readnumber();

Serial.print("\nPlaying track #"); Serial.println(n);
if (! sfx.playTrack(n) ) {
Serial.println("Failed to play track?");
}
break;
}

case 'P': {
Serial.print("Enter track name (full 12 character name!) >");
char name[20];
readline(name, 20);

Serial.print("\nPlaying track \""); Serial.print(name); Serial.print("\"");
if (! sfx.playTrack(name) ) {
Serial.println("Failed to play track?");
}
break;
}

case '+': {
Serial.println("Vol up...");
uint16_t v;
if (! (v = sfx.volUp()) ) {
Serial.println("Failed to adjust");
} else {
Serial.print("Volume: "); Serial.println(v);
}
break;
}

case '-': {
Serial.println("Vol down...");
uint16_t v;
if (! (v=sfx.volDown()) ) {
Serial.println("Failed to adjust");
} else {
Serial.print("Volume: ");
Serial.println(v);
}
break;
}

case '=': {
Serial.println("Pausing...");
if (! sfx.pause() ) Serial.println("Failed to pause");
break;
}

case '>': {
Serial.println("Unpausing...");
if (! sfx.unpause() ) Serial.println("Failed to unpause");
break;
}

case 'q': {
Serial.println("Stopping...");
if (! sfx.stop() ) Serial.println("Failed to stop");
break;
}

case 't': {
Serial.print("Track time: ");
uint32_t current, total;
if (! sfx.trackTime(&current, &total) ) Serial.println("Failed to query");
Serial.print(current); Serial.println(" seconds");
break;
}

case 's': {
Serial.print("Track size (bytes remaining/total): ");
uint32_t remain, total;
if (! sfx.trackSize(&remain, &total) )
Serial.println("Failed to query");
Serial.print(remain); Serial.print("/"); Serial.println(total);
break;
}

}
}






/************************ MENU HELPERS ***************************/

void flushInput() {
// Read all available serial input to flush pending data.
uint16_t timeoutloop = 0;
while (timeoutloop++ < 40) {
while(ss.available()) {
ss.read();
timeoutloop = 0; // If char was received reset the timer
}
delay(1);
}
}

char readBlocking() {
while (!Serial.available());
return Serial.read();
}

uint16_t readnumber() {
uint16_t x = 0;
char c;
while (! isdigit(c = readBlocking())) {
//Serial.print(c);
}
Serial.print(c);
x = c - '0';
while (isdigit(c = readBlocking())) {
Serial.print(c);
x *= 10;
x += c - '0';
}
return x;
}

uint8_t readline(char *buff, uint8_t maxbuff) {
uint16_t buffidx = 0;

while (true) {
if (buffidx > maxbuff) {
break;
}

if (Serial.available()) {
char c = Serial.read();
//Serial.print(c, HEX); Serial.print("#"); Serial.println(c);

if (c == '\r') continue;
if (c == 0xA) {
if (buffidx == 0) { // the first 0x0A is ignored
continue;
}
buff[buffidx] = 0; // null term
return buffidx;
}
buff[buffidx] = c;
buffidx++;
}
}
buff[buffidx] = 0; // null term
return buffidx;
}
/************************ MENU HELPERS ***************************/



FYI
The only command that works is pressing P in the serial monitor on an R3 board.....
Also note the wav sound file has have 11 characters including .wav
The audio has to be encoded at 16bit otherwise it plays in slow motion - filename 'T00NEXT1.wav' is the one used in this video

Anyhow hopefully this is a building block :)
T.Watson
Recruit
Posts: 37
Joined: Sat Jul 30, 2016 5:48 pm

Re: How to build a working IR Artillery Gun

Post by T.Watson »

sorry forgot to mention I am using different pins to the original code - I also think an arduino mega is probably the real solution to solve this after the number of breadboard configs I have played with:)
User avatar
wibblywobbly
Major
Posts: 6396
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: How to build a working IR Artillery Gun

Post by wibblywobbly »

Having successive sound files would theoretically stop the interference sound. My issue is created because I am only playing one, a gun firing. The sketch plays it, and then leaves the channel open, which creates all sorts of weird noises. This never turns off even if I press the reset button. I need to disable the audio immediately after playing the sound.

There is a solution, there always is one way or another, I will have to apply the grey matter when I get the chance.
Tiger 1 Late
Panther G
King Tiger
M36 B1
User avatar
LukeZ
Lance Corporal
Posts: 178
Joined: Sat Apr 17, 2010 8:03 pm
Contact:

Re: How to build a working IR Artillery Gun

Post by LukeZ »

Guys, I haven't followed this discussion of the sound stuff very closely, but it appears you are using one of the the Adafruit Audio FX boards (they have several) and that you are trying to use it it in "Serial" or "UART" mode. However that seems to me to be making it more complicated than it has to be. You can trigger up to 11 sounds just with pushbuttons - but we can use digital outputs on our IR board instead. This means you don't have to write any code to control your Audio FX board.

I've posted an update to the firmware for the Standalone TankIR project. The update includes also an update to the readme on that site, as well as the schematic PDF, so be sure to check those out.

The update will trigger the equivalent of a button press on outputs A1, A2, A3, A4 when the cannon is fired, a cannon hit is received, the vehicle is destroyed, or a repair operation occurs, respectively.

All you need to do is connect these outputs on your Arduino to the corresponding inputs on the Audio board. So Arduino A1 will go to Audio 1, A2 to 2, A3 to 3, and A4 to 4.

Now add the four sounds above to your Audio board, with these names:
T01.wav - your cannon fire sound
T02.wav - your cannon "hit" sound
T03.wav - your destroyed sound (device has received enough hits to be destroyed)
T04.wav - repair sound

You don't have to add all four sounds if you don't want. Also make sure the Audio board and your Arduino share a Ground connection, and both have power, and off you go.

Of course I have not tested this personally so let me know if it doesn't work.

I see Adafruit has many Audio FX boards. For those reading this later, probably you will want to use the ones with a built-in 2W amplifier. They have a 2 MB version and a 16 MB version.

Here is Adafruit's tutorial on these boards for more information.
NO SUPPORT THROUGH PM - read why
User avatar
wibblywobbly
Major
Posts: 6396
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: How to build a working IR Artillery Gun

Post by wibblywobbly »

This is where I am at the moment. No amp connected, so quiet but might be ok for the battlefield, and clear sound. It's on a loop for demo purposes. This is about as cheap as it gets.... :D.

Will try an amp later...

phpBB [video]
Tiger 1 Late
Panther G
King Tiger
M36 B1
T.Watson
Recruit
Posts: 37
Joined: Sat Jul 30, 2016 5:48 pm

Re: How to build a working IR Artillery Gun

Post by T.Watson »

Thank you Luke for posting the code for this :D
Much appreciated.
The video shows the sound amplified and wiring for the other parts working

In case the link above doesn't work:
phpBB [video]


Has any one any thoughts on connecting a PIR or ultrasonic detector (HRS04) to trigger the gun when another tank comes into range?


(Edited to show the video. WW)
T.Watson
Recruit
Posts: 37
Joined: Sat Jul 30, 2016 5:48 pm

Re: How to build a working IR Artillery Gun

Post by T.Watson »

I have to wired up a PIR to the arduino board and it now works the way I intended :D

phpBB [video]


I think I need to play with the PIR settings and figure out how to get rid of the annoying clicking sound.

Next stage will be to package it all with the PAK 40 I have built
Thank you for the help guys :D
User avatar
wibblywobbly
Major
Posts: 6396
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: How to build a working IR Artillery Gun

Post by wibblywobbly »

What is the range on the detection sensor? I am hoping to find something that detects movement within around 2 meters max.
Tiger 1 Late
Panther G
King Tiger
M36 B1
T.Watson
Recruit
Posts: 37
Joined: Sat Jul 30, 2016 5:48 pm

Re: How to build a working IR Artillery Gun

Post by T.Watson »

It says on the specs that it is up to 2 metres
T.Watson
Recruit
Posts: 37
Joined: Sat Jul 30, 2016 5:48 pm

Re: How to build a working IR Artillery Gun

Post by T.Watson »

Here is the schematic that shows how I wired the PIR into the circuit

Image

Parts for this project - I shopped around for these from eBay and Amazon mainly
Arduino R3 board £30 - I bought a beginners kit, if you know what you are doing and need you can get an arduino for as little as £6 on Amazon.
IR Emitter £3
Adafruit FXboard 2mb £4
TDA2030A Audio Amplifier Module Board Single Mono 18W £4
4 ohm speaker 15W (I could use a BIGGER speaker for this project :haha: ) This was the most expensive item as it was in a speaker box, around £12
9V Battery case and jump leads came with the arduino
Tamiya Apple (already had one)
Servo from local hobby shop plus I later found I had a spare....

The total comes to around £20-£25 for this setup
I managed to get most stuff sent by post for free

I have bought a DC 8-26V TPA3110 PBTL Mono Digital Amplifier Board for £1.60 from eBay which I have to put together.

For my very first attempt at electronics this has been some serious fun as well as challengingImageImage
It has also increased my confidence in playing with the electronics
Thanks to wibbly and Luke for replying to the posts
Hopefully one day I will gravitate to an arduino powered tank with motors

Luke - I hope the Openpanzer TCB manufacturing gets sorted, if it does I will be up for one to play with :D

UPDATE: THANKS to Luke (see posts below) the clicking has stopped!!
The Adafruit power FX board VCC connection needs to be connected to the 3.3V power port on the Arduino board
Last edited by T.Watson on Wed Aug 16, 2017 5:10 pm, edited 4 times in total.
Post Reply

Return to “Open Panzer Tank Control Board”