Jump to content

Looking for help with CommMG and Arduino


 Share

Recommended Posts

Hey all,

I'm trying to teach myself more about interfacing with an Arduino using Auto-it, and as a result I wrote these scripts cobbled from other things I found in this forum:

#include 'CommMG.au3'

$dll = DllOpen("user32.dll")
Global $CMPort = 3 ; Port
Global $CmBoBaud = 9600 ; Baud
Global $CmboDataBits = 8 ; Data Bits
Global $CmBoParity = "none" ; Parity
Global $CmBoStop = 1 ; Stop
Global $setflow = 2 ; Flow
Global $sportSetError = ''
_CommSetRTS(0)
_CommSetDTR(1)

_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)

For $i=0 To 9
HotKeySet("{NUMPAD"&$i&"}",'_SendSerial')
Next

HotKeySet("{End}",'_Exit')

While 1
If @error Then
_Exit()
EndIf
WEnd

Func _SendSerial()
Local $Number=StringRight(StringTrimRight(@HotKeyPressed,1),1) ; Converting mess of BS into a number to send to the Arduino
ConsoleWrite('HotKeyPressed : '&@HotKeyPressed&@CRLF)
ConsoleWrite("Sending : "&$Number&@CRLF)
_CommSendstring($Number)
EndFunc

Func _Exit()
DllClose("user32.dll")
_CommCloseport($CMPort)
ConsoleWrite("Quitting..."&@CRLF)
Exit
EndFunc

Arduino code:

#include
#include //for atol()

Servo myservo;

long pos;

void setup()
{
myservo.attach(9);
myservo.write(91);
Serial.begin(9600);
}

void loop()
{
if (Serial.available())
{
char input[11] = {Serial.read()};
pos = atol(input);
//Serial.println(pos);
pos = map(pos, 0, 9, 0, 180);
myservo.write(pos);
delay(15);
}
}

When I run _CommListPorts() (which I may be doing incorrectly as I'm pretty new at this and I've had some trouble finding good examples to learn from) I get a return of 0, but I can certainly use Arduino's Serial Monitor to send it the integer value I'd like. Needless-to-say, it's pretty late here and I'm confused. I'd be really happy if someone could help me get back on track or at least point me in the right direction. I've already scoured the other posts in here about Auto-it and Arduino interfacing as well as trying to use NetComm to suit my needs, but the learning curve seems to be a bit on the steep side. ...Thoughts? Also I am running Windows 7 64bit, could this be the issue?

edit: Also this is an Arduino uno, and I'm using USB to interface with it, device manager shows it as being on COM3, but changing the $CMPort to a different number doesn't result in an error. Is there some smart way I can debug this?

Edited by Ephemeron
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...