Hi,
I'm trying to implement a serial connection between my arduino and an autohotkey script.
I am using files from:
http://arduino.cc/forum/index.php/topic,55429.0.html
To test, I am trying to turn on an LED via a (string) serial command.
I know that the arduino code pretty much works, because I can type "on" into the arduino serial monitor, and the LED turns on..
The arduino is locked to COM10 on my computer.
My test AHK script:
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Windows XP +??
; Author: ahklerner / kruzan
;
; Script Function:
; Arduino GUI Example
;
; set some defaults
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; serial settings
ARDUINO_Port = COM10
ARDUINO_Baud = 9600
ARDUINO_Parity = N
ARDUINO_Data = 8
ARDUINO_Stop = 1
; setup arduino serial communication
arduino_setup(start_polling_serial:=false)
; *****************GUI CODE***************
^s::
arduino_send("on")
;*************************************************************************************
; *****Do not edit below this line unless you want to change the core functionality of the script*****
;*************************************************************************************
; called when the gui is closed
;also called when program exits
GuiClose:
OnExit:
; make sure to cleanly shut down serial port on exit
arduino_close()
; this is important!! or else theprogram does not end when closed
ExitApp
#include %A_ScriptDir%\include\Arduino.ahk
My test arduino sketch:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
char serialIn[20];
char holder = -1;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
pinMode(9, OUTPUT);
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
int index = 0;
while (Serial.available() > 0)
{
if (index < 19)
{
holder = Serial.read();
serialIn[index] = holder;
index++;
serialIn[index] = '\0';
}
}
Serial.println(serialIn);
if (strcmp(serialIn, "on") == 0)
{
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
}
else
{
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
Whenever I attempt to run the test.ahk script, I receive an error (attached screenshot).
I can't figure out what is causing this. I have set the Baud equal to the sketch, and the COM port is correct.
If anybody has some time to lend a hand, I'd appreciate it.
Thanks,
-BBX
test.ahk (1.27 KB)
serialAHKtest.ino (1.06 KB)