works from serial monitor, works from screen but frequently fails from script

Hi all.

Using a Mac, Yosemite, Arduino Uno, EasyDriver and stepper motor(s). I have a 10 uF capacitor from reset to ground to prevent reseting.

I am sending a single character to the Arduino to index a stepper motor in sync with an image capture sequence. I am using applescript and calling a shell script "echo 'f'> /dev/cu.usbmodem1431". The Arduino sketch reads the character and rotates forward with 'f' and reverse with 'b'. After the rotation logic, there is an LED blink step so that I can see if the logic was executed.

The shell script works most of the time but then fails 10% of the time. There is no pattern to the failure. I see the rx flash on the Arduino but no rotation The same command fails sometimes from the command line in the same randomness and frequency. When it fails, I get no LED blink and I get no voltage change at the stepper (when it works I measure a big voltage change).

The sketch, driver and motor work 100% of the time using the serial monitor to input the characters. It also works 100% if I use screen from the Mac terminal.

I tried a new board but get the same outcome. I was hoping that someone could help me fix this.

How do you expect any useful response when you have not shown us all the code you are talking about.

Why do you need to prevent the Arduino from resetting?

Perhaps you should write a proper program for your PC to send data to the Arduino.

...R

First time in this forum and not sure how to post code.

Here is the sketch reduced to just blinking when a character 'f' is received.

#define DIR_PIN 2
#define STEP_PIN 3
#define LED 13

void setup() {
Serial.begin(9600);

pinMode(13, OUTPUT);
}

void loop(){

if ( Serial.available())
{
char ch = Serial.read();

if(ch == 'f'){ // is ch a f? then blink the led

digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);

}

if(ch == 'b'){ // is ch a b? then do nothing

}

}

}

I get the blink 100% of the time from the serial monitor and 100% if using Screen function from terminal but it fails about 30% from the shell script. Below is the line of code from the applescript but you can also initiate by inputing the quoted portion in the terminal app.

do shell script "echo -n f > /dev/cu.usbmodem411"

I am shooting a sequence of images and must repeatedly call this script to move a microscope stage and then capture a frame, save a file and repeat. The Arduino resets every time a serial connection is made and it misses the character while resetting.

I did more experimenting and used an increasingly longer string of characters before the 'f'. As the string got longer the incidence of failure went down from about 30% of the time so now it is 1-2% of the time. So maybe this problem has something to do with timing.

patmurphey:
First time in this forum and not sure how to post code.

Seems like a good reason to read How to use the Forum. Post your program using the code button </> so it looks like this and is easy to select and copy to a text editor.

In your original post you also mentioned applescript and a shell script. You need to show us that code also.

The examples in Serial Input Basics are simple reliable ways to receive data. This Python - Arduino demo illustrates both sides of the communication.

...R