Hi,
I have an arduino pro mini connected to several servo motors and photomos relays.
I have a program running on Windows 7 that will run several .bat files when specific events are triggered.
I have attached a sample of a .bat file and the arduino program - basic stuff.
The arduino will move a servo when it receives a letter or number sent across the serial port - e.g. "f" or "g".
I put delays in the .bat files instead of in the arduino program so that I can modify timing events without having to modify the arduino program.
Everything works fine except when...
One problem that I run into is that if two .bat files are run at nearly the same time I get an "ACCESS DENIED" message displayed
in one of the command windows and the arduino fails to execute the .bat file commands completely.
I have to say I'm not sure where the error is occuring - I don't know if all the data is getting transmitted across the serial connection or if the info is being transmitted but not getting received by the arduino.
I was just wondering if anybody knew of a way to buffer the transmission across the serial connection - or spool the .bat files - or increase the communication - or add some code to the .bat files.
Any advice would be greatly appreciated.
@ECHO OFF
MODE COM5:9600,N,8,1 >NUL
ECHO b >COM5
PING 1.1.1.1 -n 1 -w 5000 >NUL
ECHO a >COM5
@ECHO OFF
MODE COM5:9600,N,8,1 >NUL
ECHO g >COM5
PING 1.1.1.1 -n 1 -w 5000 >NUL
ECHO f >COM5
#include <Servo.h>
Servo servo_01;
Servo servo_02;
Servo servo_03;
Servo servo_04;
Servo servo_05;
Servo servo_06;
int usb_switch_01 = 8;
int usb_switch_02 = 7;
int usb_switch_03 = 13;
void setup() {
servo_01.attach(10);
servo_02.attach(11);
servo_03.attach(9);
servo_04.attach(6);
servo_05.attach(5);
servo_06.attach(3);
servo_01.write(68);
servo_02.write(70);
servo_03.write(65);
servo_04.write(75);
servo_05.write(57);
servo_06.write(83);
pinMode(usb_switch_01, OUTPUT);
pinMode(usb_switch_02, OUTPUT);
pinMode(usb_switch_03, OUTPUT);
digitalWrite(usb_switch_01, LOW);
digitalWrite(usb_switch_02, LOW);
digitalWrite(usb_switch_03, LOW);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
int keyboard_button = Serial.read();
switch (keyboard_button) {
case 'a':
servo_01.write(68);
break;
case 'b':
servo_01.write(57);
break;
case 'c':
servo_01.write(56);
break;
case 'd':
servo_01.write(118);
break;
case 'e':
servo_01.write(119);
break;
case 'f':
servo_03.write(65);
break;
case 'g':
servo_03.write(55);
break;
case 'h':
servo_03.write(54);
break;
case 'i':
servo_03.write(106);
break;
case 'j':
servo_03.write(107);
break;
case 'k':
servo_05.write(57);
break;
case 'l':
servo_05.write(47);
break;
case 'm':
servo_05.write(46);
break;
case 'n':
servo_05.write(106);
break;
case 'o':
servo_05.write(107);
break;
case 'p':
servo_02.write(70);
break;
case 'q':
servo_02.write(46);
break;
case 'r':
servo_04.write(75);
break;
case 's':
servo_04.write(51);
break;
case 't':
servo_06.write(83);
break;
case 'u':
servo_06.write(107);
break;
case '1':
digitalWrite(usb_switch_01, LOW);
break;
case '4':
digitalWrite(usb_switch_01, HIGH);
break;
case '2':
digitalWrite(usb_switch_02, LOW);
break;
case '5':
digitalWrite(usb_switch_02, HIGH);
break;
case '3':
digitalWrite(usb_switch_03, LOW);
break;
case '6':
digitalWrite(usb_switch_03, HIGH);
break;
}
}
}