Arduino Uno IR Battle System

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.
User avatar
wibblywobbly
Major
Posts: 6398
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: Arduino Uno IR Battle System

Post by wibblywobbly »

Just checked that I have the latest IDE, I do.
Downloaded the new zip.
Loaded the Sketch into two versions of Arduino, 1.0.6 and 1.8.
1.0.6 generates only one error, unfortunately it is servo related. :'(
The error aborts compiling or upload.
error.png
error.png (31.82 KiB) Viewed 6692 times
I did a quick video with the previous sketch to demonstrate what happens with the servo.
Only the servo is connected.
It is running off the USB, not the RX18.
Fire button is a momentary switch on D4/GND.
No response on servo.
The onboard led flashes to indicate that the switch has activated the circuit.

phpBB [video]


I tried hooking things up via the RX18.
Using the D4/GND switch the IR LED works perfectly.

This narrows the power issue down to the RX18 IR+ pin. I have removed all other circuits, just have the A0/GND pins and voltage divider. The IR LED remains inactive when the gun is fired.

One thing that did cross my mind. I seem to recall that when I was looking at the Uno last year, I set up a voltage measuring sketch that monitored the two IR pins on the RX18. The pins pulsed at 5v, but took a while to drop back to 0v. Most of the time they were fluctuating between 0v-3v when inactive. If the sketch is looking for high/low, and there is always voltage going through would that mean that the sketch would never reach a point where the high/low differential was detected, and therefore always remain inactive?
Tiger 1 Late
Panther G
King Tiger
M36 B1
User avatar
LukeZ
Lance Corporal
Posts: 177
Joined: Sat Apr 17, 2010 8:03 pm
Contact:

Re: Arduino Uno IR Battle System

Post by LukeZ »

Wibbly,

Arduino 1.0.6 is ancient, ancient history. Let's just use the most recent version for now and forget about the old one.

As for the rest of it, I can only offer useful advice if you follow the steps that were laid out. Please read my prior post once more and go through the steps precisely as written, and describe to me the result of each step. It will help if you also describe to me what you did at each step, even if it sounds like you're just repeating what I said, because it can help me identify if my instructions were clear or if they were interpreted slightly different than I intended.

Only then can we actually begin to narrow down the problem.
NO SUPPORT THROUGH PM - read why
User avatar
wibblywobbly
Major
Posts: 6398
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: Arduino Uno IR Battle System

Post by wibblywobbly »

LukeZ wrote:There are two issues here and they are not related.

1. Servo
For now do no bother testing the servo with the RX-18, use only the manual button to ground.

First, re-download the firmware from GitHub. I made a few changes that should eliminate some of the warnings the IDE was giving you earlier. I don't think they will make any difference to the servo, but it won't hurt.

Second, attach the servo as you have done (Sig to D8, Positive to Uno 5V, Negative to Uno Ground). Now test by momentarily bringing D4 to Ground. But it is not enough to simply say, "the servo does nothing"! I need to know whether putting D4 to Ground while the servo is attached does anything at all. Does it send the IR successfully, but not the servo? Or does it do neither? In other words, does everything work except the servo, or does connecting the servo cause nothing to work?
Installed 1.8.2, the latest version, threw up a load of warnings, but the Sketch uploaded.
Tried the servo test, but the servo was still dead.
Hmm...went and got another one (I have four new ones), plugged that in, and the damned thing worked! It was a dead new servo.
So, using the momentary button with the Uno hooked up to the PC via the USB, the servo is active.
I already know that the IR emitter works when the Uno is hooked up to the PC via the USB.
2. RX-18 Trigger
First, do NOT attach both RX-18 IR connections to the Uno! Especially do not connect one of them to ground. The RX-18 IR negative is an output, it is not a Ground connection. You could damage your RX-18 by connecting it to ground and firing the cannon as you have done.
The neg is not connected the molex pin has been disconnected. There is only one wire in the 5 pin plug, that is the IR+.
We may not get the RX-18 to work with the Uno, but if we do you only need to connect a single wire from the RX-18 to Uno A0 for the trigger. There is no looping back required, that is not how these electronics work. What we need to do is figure out which wire from the RX-18 might give us an adequate signal. You have assumed the positive IR signal from the RX-18 and that is a reasonable guess but it may not be correct. Try the following steps:
Ok, trying the following:
1. Disconnect the servo so we know that isn't causing any problems.
Done - Servo disconnected
2. Test fire the IR emitter (or just keep the Uno connected to your computer and watch the serial monitor) using the manual switch from D4 to Ground, to make sure the board is working correctly. The emitter should fire.
Yes it fires when connected to the USB and activated via the momentary button.
3. Next test fire the emitter by using a jumper to manually and momentarily connect A0 to +5v on the Uno. This lets us test if the firmware is reading A0 correctly. If it fires, proceed.
Yes it fires the emitter.
4. Now connect RX-18 IR positive wire (connector CN2-A on the RX-18) to Uno A0 (through a 10k resistor with another 10k to ground as you had earlier). Leave the RX-18 IR negative wire (CN2-B) disconnected! Now fire the cannon with your Heng Long transmitter. Does the Uno respond? Ie, does the serial monitor indicate anything?
No, the serial monitor remains blank.
The emitter does not function.
The onboard led does not flash.
5. If not, try the other way. Connect RX-18 IR negative (connector CN2-B on the RX-18) to Uno A0. Yes, I really said connect IR negative to A0. Leave the RX-18 IR positive wire (CN2-A) disconnected! Again try firing the cannon with the HL transmitter, and see if the Uno responds.
No, the serial monitor remains blank.
The emitter does not function.
The onboard led does not flash.
6. If that doesn't work, try connecting the RX-18 strobe output (CN3-G) to the Uno A0. This provides a clean 5v trigger source, the only drawback is that the RX-18 will probably only send the trigger if you have an airsoft attached. Maybe you don't want to use an airsoft but just attach one for this test (I believe the RX-18 needs to get the signal from the limit switch on the back of the airsoft unit before it will send the strobe signal).
You will never guess what I pulled out of the tank because I thought I would never need it....will resume test when I have re-established the circuit. :eh:
I didn't design this with the idea of integrating it with the RX-18, nor have I tested it (unfortunately I do not have an RX-18 right now or I would). There's no guarantee the two are going to be (easily) compatible. But let's see what the above produces.
I can appreciate that, my thoughts are that if a Uno or Nano can give someone access to IR battling then it gets them into the hobby, and the more people there are, the bigger the hobby becomes. This benefits everyone.

I'll post an update when I have sorted out a temporary loom for the strobe. This would really be the better option if I can get around the microswitch trigger, as the RX18 IR +/- can be used to power a high intensity muzzle flash led (which was why I assumed they were pos and neg).
Tiger 1 Late
Panther G
King Tiger
M36 B1
User avatar
LukeZ
Lance Corporal
Posts: 177
Joined: Sat Apr 17, 2010 8:03 pm
Contact:

Re: Arduino Uno IR Battle System

Post by LukeZ »

Great, thanks for doing all that. We are making progress. Sounds like the servo issue is resolved, we just need to figure out a way to trigger the Uno from the RX-18.

The IR +/- from the RX-18 are the signals to the IR emitter, obviously, and the signal is going to be an IR code modulated at ~40KHz so it is not at all a clean voltage source. The Uno theoretically should still be able to detect a falling pulse even from that, but it is not ideal.

I am wondering if the RX-18 maybe doesn't send the IR signal until it gets the trigger input from the limit switch on the airsoft/mechanical recoil units. This may explain why the Uno isn't picking anything up, perhaps nothing is actually happening. I believe the RX-18 waits until it gets the limit switch input before it does the strobe, the sound, and the track recoil. So it would not surprise me if it also waits to send the IR.

Hooking up an airsoft unit may solve the problem.
NO SUPPORT THROUGH PM - read why
User avatar
wibblywobbly
Major
Posts: 6398
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: Arduino Uno IR Battle System

Post by wibblywobbly »

Very quick question. The momentary switch will activate the IR and the servo when hooked up to the tank. Can this be used as a permanent switch? I am thinking that a solenoid switch that hits a microswitch, and is activated by the airsoft pulse would replace the AO detection and solve the mysterious signal loss. I can't see any reason why it wouldn't work, a solenoid is cheap and very small. I could use a Pico switch, but HL 2.4ghz tx's don't use standard signals.

Still puzzled about that AO detection. This sketch will read the voltage on A0 and echo it to the serial monitor, I wrote it to detect >3.25v and it detected that too. Is there any way of changing the sketch from high/low detection to voltage >3.25v, the RX18 IR is 5v when fired so anything below 3.25v would not trigger an IR pulse on the Uno.

All I did was hook up the RX18 IR +/- pins to AO and GND.
void setup()
{
Serial.begin(9600);
}

void loop() {

int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);

if (voltage>3.25)
{
Serial.println(voltage);
}
;
}
Tiger 1 Late
Panther G
King Tiger
M36 B1
User avatar
LukeZ
Lance Corporal
Posts: 177
Joined: Sat Apr 17, 2010 8:03 pm
Contact:

Re: Arduino Uno IR Battle System

Post by LukeZ »

wibblywobbly wrote:Very quick question. The momentary switch will activate the IR and the servo when hooked up to the tank. Can this be used as a permanent switch? I am thinking that a solenoid switch that hits a microswitch, and is activated by the airsoft pulse would replace the AO detection and solve the mysterious signal loss. I can't see any reason why it wouldn't work, a solenoid is cheap and very small. I could use a Pico switch, but HL 2.4ghz tx's don't use standard signals.
Yes, this will work. It seems like going around your elbow to get to your behind, but it will work. Why not just use the airsoft pulse as the input to A0? The other thing worth clarifying is that there is no "mysterious signal loss."
wibblywobbly wrote:Still puzzled about that AO detection. This sketch will read the voltage on A0 and echo it to the serial monitor, I wrote it to detect >3.25v and it detected that too. Is there any way of changing the sketch from high/low detection to voltage >3.25v, the RX18 IR is 5v when fired so anything below 3.25v would not trigger an IR pulse on the Uno.
Not sure what you mean here. If the trigger is truly 5v as you say, then the pin-change interrupt on A0 certainly will read anything above 3.25 volts. You can see this yourself if you look at the ISR (PCINT1_vect) function on the main sketch tab. It checks if the pin is high. If the voltage gets to 5v, that means it is high.
wibblywobbly wrote: All I did was hook up the RX18 IR +/- pins to AO and GND.
Again this makes no sense to me. This is what I warned you NOT to do! Do not connect the RX18 IR - pin to GND! It does not go to ground! Connecting it to ground not only could damage your RX18, it almost certainly will prevent the RX18 from sending the IR signal so whatever result you got from that test is not valid. Now I am doubting you understood instruction #4 and #5 earlier, and if so, it may still be possible to use either the RX18 IR positive or negative lines to trigger A0 and we still don't know.

It is just as likely that Heng Long uses the negative IR wire as the switch rather than the positive wire. On further thought my test #5 would not have worked correctly to test this. Let's repeat test #5 twice.

First, do it as instructed before: connect RX18 IR negative to A0 on the Uno through a 10k resistor. But this time do not use a second resistor to ground, get rid of that one. Do not connect the RX18 IR positive wire to anything! Leave it disconnected. See if this does anything.

If not, let's change a few things in code and try again. On or around line 81 in the main tab of the sketch, change this line:
digitalWrite(pin_VoltageTrigger, LOW);
to:
digitalWrite(pin_VoltageTrigger, HIGH);

This turns on the internal pull-up on A0, meaning the pin will remain high unless pulled low by an external force.

Secondly, on or around line 322 of the main sketch tab change this line:
if (digitalRead(pin_VoltageTrigger) == HIGH && (interrupt_time - last_interrupt_time > 250))
to:
if (digitalRead(pin_VoltageTrigger) == LOW && (interrupt_time - last_interrupt_time > 250))

Now A0 will be checking for a pull to GND.

Same as before, connect the Rx18 IR negative line to A0 through a 10k resistor. Do not use a second resistor to ground. Leave the RX18 IR positive wire disconnected from anything else. Then see what happens.
NO SUPPORT THROUGH PM - read why
User avatar
wibblywobbly
Major
Posts: 6398
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: Arduino Uno IR Battle System

Post by wibblywobbly »

Again this makes no sense to me. This is what I warned you NOT to do! Do not connect the RX18 IR - pin to GND! It does not go to ground! Connecting it to ground not only could damage your RX18, it almost certainly will prevent the RX18 from sending the IR signal so whatever result you got from that test is not valid. Now I am doubting you understood instruction #4 and #5 earlier, and if so, it may still be possible to use either the RX18 IR positive or negative lines to trigger A0 and we still don't know.
This was the first thing I did when I bought the Uno last year...not recently. I was testing an Open Source circuit to measure voltage, and then output it to the serial monitor.

Will get back to the testing asap, I am currently tidying up the installation.
Tiger 1 Late
Panther G
King Tiger
M36 B1
User avatar
LukeZ
Lance Corporal
Posts: 177
Joined: Sat Apr 17, 2010 8:03 pm
Contact:

Re: Arduino Uno IR Battle System

Post by LukeZ »

Ok, that's good. As a coder, I only understand explicit and fully contextualized information. Leave out a crucial detail and I will not compute. :)
NO SUPPORT THROUGH PM - read why
User avatar
wibblywobbly
Major
Posts: 6398
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: Arduino Uno IR Battle System

Post by wibblywobbly »

Spent today being told that my Hotmail account had been hacked and trying to get it active again. Failed miserably. Luckily I have a domain name email address and email forwarding to hotmail, so I just switched it to another account until its sorted.

In between times I designed a geared recoil for the project tank, this approach is a lot less stressful on the servo, so hopefully my last one in the box will be ok.



@Luke. My question about the microswitch was two fold. This set up can be used in a static artillery gun, landmines etc, so hooking it up to a microswitch and a pressure pad would be good for a battlefield, or even having a tank destroyer in a building etc. It will work away doing what it does without any tx.
Attachments
IMG_20170401_000812.jpg
IMG_20170401_000812.jpg (73.6 KiB) Viewed 6648 times
Tiger 1 Late
Panther G
King Tiger
M36 B1
User avatar
wibblywobbly
Major
Posts: 6398
Joined: Fri Oct 17, 2008 9:30 am
Location: South Wales Valley
Contact:

Re: Arduino Uno IR Battle System

Post by wibblywobbly »

Ok, back on the case, got distracted by a few things.

Just for reference, this is what appears when I upload the sketch to the Uno.
In file included from sketch/Motors.cpp:8:0:
sketch/Motors.h:23:1: warning: 'typedef' was ignored in this declaration
};
^
sketch/Servo.cpp:210:6: warning: always_inline function might not be inlinable [-Wattributes]
void OP_Servos::setPulseWidthTimer(uint8_t WhatChannel)
^
sketch/Servo.cpp:194:6: warning: always_inline function might not be inlinable [-Wattributes]
void OP_Servos::setPinLow(uint8_t WhatChannel)
^
sketch/Servo.cpp:185:6: warning: always_inline function might not be inlinable [-Wattributes]
void OP_Servos::setPinHigh(uint8_t WhatChannel)
^
In file included from sketch/Tank.h:14:0,
from sketch/Tank.cpp:8:
sketch/Motors.h:23:1: warning: 'typedef' was ignored in this declaration
};
^
In file included from sketch/Tank.cpp:8:0:
sketch/Tank.h:81:1: warning: 'typedef' was ignored in this declaration
};
^
sketch/Tank.h:95:1: warning: 'typedef' was ignored in this declaration
};
^
In file included from sketch/Tank.h:14:0,
from /home/rob/Desktop/new ir/TankIR-master/TankIR/TankIR.ino:33:
sketch/Motors.h:23:1: warning: 'typedef' was ignored in this declaration
};
^
In file included from /home/rob/Desktop/new ir/TankIR-master/TankIR/TankIR.ino:33:0:
sketch/Tank.h:81:1: warning: 'typedef' was ignored in this declaration
};
^
sketch/Tank.h:95:1: warning: 'typedef' was ignored in this declaration
};
^
/home/rob/Desktop/new ir/TankIR-master/TankIR/TankIR.ino: In function 'void setup()':
/home/rob/Desktop/new ir/TankIR-master/TankIR/TankIR.ino:117:37: warning: invalid conversion from 'int' to 'ESC_POS_t' [-fpermissive]
ESC_POS_t SERVONUM_RECOIL = 0; // Recoil servo is servo #0 (Port B0)
I tested the following:
First, do it as instructed before: connect RX18 IR negative to A0 on the Uno through a 10k resistor. But this time do not use a second resistor to ground, get rid of that one. Do not connect the RX18 IR positive wire to anything! Leave it disconnected. See if this does anything.
Tested this.
Used the revised circuit described above.
No recoil.
If not, let's change a few things in code and try again. On or around line 81 in the main tab of the sketch, change this line:
digitalWrite(pin_VoltageTrigger, LOW);
to:
digitalWrite(pin_VoltageTrigger, HIGH);
Tested this.
Used the revised circuit described above.
No recoil.
No IR emission.

Rechecked for connectivity using the momentary button.
Recoil functions.
Emitter functions.
Secondly, on or around line 322 of the main sketch tab change this line:
if (digitalRead(pin_VoltageTrigger) == HIGH && (interrupt_time - last_interrupt_time > 250))
to:
if (digitalRead(pin_VoltageTrigger) == LOW && (interrupt_time - last_interrupt_time > 250))
Tested this.
Used the revised circuit described above.
No recoil.
Rechecked using momentary button - Emitter and recoil function.

For what its worth, and don't shoot me for saying it, lol, I can use the RX18 +/- pins to power an led. As an led will only light up if the anode and cathode are the correct way around, is this an indication that the RX18 positive is positive, and the RX18 negative is negative?



^
Tiger 1 Late
Panther G
King Tiger
M36 B1
Post Reply

Return to “Open Panzer Tank Control Board”