.bat not running in first click

Hi guys I have a trigger script on the nano and a .bat file that tells it to turn on /off

My problem is when I double click the .bat file it does nothing first time round, when I double click again it works perfectly after that any ideas please.

So, how are we supposed to know whats wrong without ou posting the Arduino code, the batchfile code and what you think should happen?

Let's see some code ?

Exactly what does the .bat file do in relation to the Arduino ?

Sorry Guys
Code as follows

#include <NeoPixelBus.h>
#include <NeoPixelAnimator.h>

const uint16_t PixelCount = 24; // make sure to set this to the number of pixels in your strip
const uint16_t PixelPin = 7; // make sure to set this to the correct pin, ignored for Esp8266
const uint16_t AnimCount = 1; // we only need one
const uint16_t TailLength = 12; // length of the tail, must be shorter than PixelCount
const float MaxLightness = 0.5f; // max lightness at the head of the tail (0.5f is full bright)

NeoGamma colorGamma; // for any fade animations, best to correct gamma

NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);

NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object

char inData; // Allocate some space for the string
int i;
boolean triggerLights = false;
bool checkserial (){
if (Serial.available() > 0){
inData=Serial.read();
if (inData == 'I'){
Serial.println("On");
triggerLights = true;
SetRandomSeed();
DrawTailPixels();
animations.StartAnimation(0, 45, LoopAnimUpdate);
}else if (inData == 'O'){
Serial.println("Off");
triggerLights = false;
animations.StopAnimation(0);
strip.ClearTo(0);
return false;
}
}
return true;
}
bool dodelay (int d){
for (int i=0; i<d; i++){
delay(1);
if (!checkserial()){ return false;}
}
return true;
}

void SetRandomSeed()
{
uint32_t seed;

// random works best with a seed that can use 31 bits
// analogRead on a unconnected pin tends toward less than four bits
seed = analogRead(0);
delay(1);

for (int shifts = 3; shifts < 31; shifts += 3)
{
seed ^= analogRead(0) << shifts;
delay(1);
}

// Serial.println(seed);
randomSeed(seed);
}

void LoopAnimUpdate(const AnimationParam& param)
{
// wait for this animation to complete,
// we are using it as a timer of sorts
if (param.state == AnimationState_Completed)
{
// done, time to restart this position tracking animation/timer
animations.RestartAnimation(param.index);

// rotate the complete strip one pixel to the right on every update
strip.RotateRight(1);
}
}

void DrawTailPixels()
{
// using Hsl as it makes it easy to pick from similiar saturated colors
float hue = random(360) / 360.0f;
for (uint16_t index = 0; index < strip.PixelCount() && index <= TailLength; index++)
{
float lightness = index * MaxLightness / TailLength;
RgbColor color = HslColor(hue, 1.0f, lightness);

strip.SetPixelColor(index, colorGamma.Correct(color));
}
}

void setup()
{
Serial.begin(19200);
strip.Begin();
strip.Show();
}

void loop()
{
dodelay(1);
// if (triggerLights){
animations.UpdateAnimations();
strip.Show();
// this is all that is needed to keep it running
// and avoiding using delay() is always a good thing for
// any timing related routines
// }else{
// animations.StopAnimation(0);
// strip.ClearTo(0);
// }
}

This is being used on my photobooth "I" led on "O" Led off

when i pull out the usb then push back in and run my .bat file it does nothing then i click on it again then it works.

This is the .bat code

@ECHO OFF

SET COMPORT=COM6

mode %COMPORT% BAUD=19200 PARITY=n DATA=8 STOP=1 dtr=off

echo I > \.%COMPORT%

Also a little Video to explain whats going on

I dont know much about coding im not a expert i cant work out why its doing this Thanks Guys

To make it easy for people to help you please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

When the PC opens the serial port the Arduino will reset and the PC program must allow time for that before trying to send any data. It could well be that using a .bat file is not a suitable approach, or maybe you should use the .bat file to run a more sophisticated program on your PC that does the real work. This Python - Arduino demo may give you some ideas.

...R

The photobooth is triggering the .bat

#NoTrayIcon

if 1 contains countdown_start
{
run %A_ScriptDir%\LED RING ON.bat, , Hide
}
if 1 contains capture_start
{
run %A_ScriptDir%\LED RING OFF.bat, , Hide
}

Its Very hard to explain Sorry

The program runs on a windows 10 on a pc
Its Called DarkRoom Booth V3
inside the software u can add .bat files to turn on leds before the camera triggers then turn off just before it triggers ( Takes a picture )

So before pic i add led on.bat
then During i add led off.bat

The problem is when i boot up the pc the first time ledon is executed the neopixel dont light up

Example pic 1 no led
pic 2 it works
pic 3 it works
i only take 3 pics

Then next person starts the booth
pic 1 led works
pic 2 works
pic 3 works

Do u get me ????
My video show that also but im doing it manual just to show you guys

MasterMark2017:
This is the .bat code

@ECHO OFF

SET COMPORT=COM6
mode %COMPORT% BAUD=19200 PARITY=n DATA=8 STOP=1 dtr=off
echo I > \.%COMPORT%

The last line of your bat file will open the serial connection (COM6), send 'I' and then close the serial connection.
Open and closing the serial connection will reset (most) arduinos (this was already mentioned in #6 by Robin2).
When you arduino will reset it may not recognize serial data in the way you like. I had the same problem some time ago, when serial data was sent via command line.
You can try to prevent "auto reset".
You did not mention what Arduino board you use, but with UNO, Nano or Mega it will work like this:
Put a condenser with about 10 to 100 µF between Reset pin and GND. This will prevent "autoreset".
Of course you have to remove the condenser if you want to program the board.

There are other ways to prevent auto reset but this is a method that works with most arduino boards.

Have you got a link for the cap I need to use please been to maplins today and they sell loads off different ones

The cap is not critical.
Every (electrolytic) capacitor with more than 5 volts and 10 to 100 microfarad will do.

Silly question but does the plus of the cap go on the reset

Yes, plus of the cap goes to reset pin, minus goes to GND pin.

And if you want to upload a program to the Arduino you must remove the cap. (Alternative: you press reset button at the right time, just in this moment when upload starts. Maybe you have to practice to find the right moment).

There are no silly questions :slight_smile: