Sign in to follow this  
Followers 0
ShmoeMo

Arduino Led controlled by autoit

13 posts in this topic

Hi guys


I'm not sure if this post fits in this category.

Any way, is there anyone out there who can make a simple script that opens up a small window that has a button and when the button is pressed it turns on the led on the arduino. i just need a simple code like that so i can modify it and turn it into a small home automation control window i am just having an extremely hard time finding any working links or anything related to arduino controlling via autoit.

I have looked all over google and cannot find anything on how to control an arduino with autoit.

It would be greatly appreciated if anyone can shed some light on my little issue.

Thanks in advance.  :)


Cheers Liam :):)

Share this post


Link to post
Share on other sites



Arduino and autoit can talk to each other by Serial communication.

I had made a very simple GUI with autoit and a button to turn a LED on and off with a slider for brightness.
I remember you will need a UDF called CommMG. It's one I used and worked very well.

Cheers.

 

Share this post


Link to post
Share on other sites
3 minutes ago, RISHKARI said:

Arduino and autoit can talk to each other by Serial communication.

I had made a very simple GUI with autoit and a button to turn a LED on and off with a slider for brightness.
I remember you will need a UDF called CommMG. It's one I used and worked very well.

Cheers.

 

I have CommMG installed,
Would you still have that script handy???

Share this post


Link to post
Share on other sites

This is as basic as I can make it.

This is for Autoit.  Make sure to change the port to match what your arduino is on.

#include <CommMG.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $CMPort = 9
Global $CmBoBaud = 9600
Global $sportSetError = ''
Global $CmboDataBits = 8
Global $CmBoParity = "none"
Global $CmBoStop = 1
Global $setflow = 2
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
If @error Then
MsgBox(16,"Error!","Can't connect to Arduino on port - "&$CMPort)
Exit
EndIf
_CommSetRTS(0)
_CommSetDTR(0)

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("PC-2-Arduino", 199, 112, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE,"_ExitFunction")
$Group1 = GUICtrlCreateGroup("LED Pin-13", 8, 0, 185, 105)
$Button1 = GUICtrlCreateButton("Turn On / Off", 16, 16, 171, 41)
GUICtrlSetOnEvent($Button1,"LED_ON_OFF")
$Button2 = GUICtrlCreateButton("Blink 10 Times", 16, 56, 171, 41)
GUICtrlSetOnEvent($Button2,"LED_BLINK_10")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _ExitFunction()
     Exit
EndFunc

Func LED_ON_OFF()
_CommSendByte(1)
EndFunc

Func LED_BLINK_10()
_CommSendByte(2)
EndFunc

 

This is for Arduino.

char Address;
int LEDPIN = 13;
int LEDSTATE = 0;
void setup()
{
  Serial.begin(9600);
    while (!Serial);
  Serial.println("Waiting for data...\n");
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);
}
void loop()
{
  while (Serial.available() > 0)
  {
    Address = Serial.read();
    if (Address == 1) ONOFF();
    if (Address == 2) BLINK();
    
  }
}

 void ONOFF()
{
  if(LEDSTATE == 0) { //if is pressed
     digitalWrite(LEDPIN, HIGH);
     LEDSTATE = 1;
  } else { //if not pressed
     digitalWrite(LEDPIN, LOW);
     LEDSTATE = 0;
  }

}

 void BLINK()
{
for (int i=0; i <= 9; i++){
  digitalWrite(LEDPIN, LOW);
  digitalWrite(LEDPIN, HIGH);
  delay(100);
  digitalWrite(LEDPIN, LOW);
  delay(100);
   } 
  if(LEDSTATE == 1) { //if is pressed
     digitalWrite(LEDPIN, HIGH);
     LEDSTATE = 1;
  } else { //if not pressed
     digitalWrite(LEDPIN, LOW);
     LEDSTATE = 0;
  }

}

 

 

This is a very fast and rough sample.

Hope this helps my friend.

Cheers.

Share this post


Link to post
Share on other sites
10 minutes ago, RISHKARI said:

This is as basic as I can make it.

This is for Autoit.  Make sure to change the port to match what your arduino is on.

#include <CommMG.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $CMPort = 9
Global $CmBoBaud = 9600
Global $sportSetError = ''
Global $CmboDataBits = 8
Global $CmBoParity = "none"
Global $CmBoStop = 1
Global $setflow = 2
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
If @error Then
MsgBox(16,"Error!","Can't connect to Arduino on port - "&$CMPort)
Exit
EndIf
_CommSetRTS(0)
_CommSetDTR(0)

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("PC-2-Arduino", 199, 112, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE,"_ExitFunction")
$Group1 = GUICtrlCreateGroup("LED Pin-13", 8, 0, 185, 105)
$Button1 = GUICtrlCreateButton("Turn On / Off", 16, 16, 171, 41)
GUICtrlSetOnEvent($Button1,"LED_ON_OFF")
$Button2 = GUICtrlCreateButton("Blink 10 Times", 16, 56, 171, 41)
GUICtrlSetOnEvent($Button2,"LED_BLINK_10")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _ExitFunction()
     Exit
EndFunc

Func LED_ON_OFF()
_CommSendByte(1)
EndFunc

Func LED_BLINK_10()
_CommSendByte(2)
EndFunc

 

This is for Arduino.

char Address;
int LEDPIN = 13;
int LEDSTATE = 0;
void setup()
{
  Serial.begin(9600);
    while (!Serial);
  Serial.println("Waiting for data...\n");
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);
}
void loop()
{
  while (Serial.available() > 0)
  {
    Address = Serial.read();
    if (Address == 1) ONOFF();
    if (Address == 2) BLINK();
    
  }
}

 void ONOFF()
{
  if(LEDSTATE == 0) { //if is pressed
     digitalWrite(LEDPIN, HIGH);
     LEDSTATE = 1;
  } else { //if not pressed
     digitalWrite(LEDPIN, LOW);
     LEDSTATE = 0;
  }

}

 void BLINK()
{
for (int i=0; i <= 9; i++){
  digitalWrite(LEDPIN, LOW);
  digitalWrite(LEDPIN, HIGH);
  delay(100);
  digitalWrite(LEDPIN, LOW);
  delay(100);
   } 
  if(LEDSTATE == 1) { //if is pressed
     digitalWrite(LEDPIN, HIGH);
     LEDSTATE = 1;
  } else { //if not pressed
     digitalWrite(LEDPIN, LOW);
     LEDSTATE = 0;
  }

}

 

 

This is a very fast and rough sample.

Hope this helps my friend.

Cheers.

Oh my god, thank you, you are a life saver, i have been looking for the past 2 days for something like this.

Thanks again. :):):)

Share this post


Link to post
Share on other sites

No worries mate, make sure to let us know if it works perfectly for you.
This should help others out aswell. :)

Cheers.

Share this post


Link to post
Share on other sites
23 minutes ago, RISHKARI said:

No worries mate, make sure to let us know if it works perfectly for you.
This should help others out aswell. :)

Cheers.

Will do mate, ill give it a test once im home in a day or 2, should have bought the ardunio with me :( haha

Share this post


Link to post
Share on other sites
10 minutes ago, ShmoeMo said:

Will do mate, ill give it a test once im home in a day or 2, should have bought the ardunio with me :( haha

Ah yes them moments can be annoying.
I reuploaded the sketch to another Arduino (Nano) and it works perfect.  I was using a Uno at first and that was fine to.
Only issue I see you having it is CommMG not being included correctly.

I will say I had the CommMG UDF and DLL in the same folder as the AutoIT Script so that way no issues would occur.

Good luck, I hope the script/sketch is clear enough for you as a base. :)
Cheers.

Share this post


Link to post
Share on other sites
On 12/3/2016 at 0:04 AM, RISHKARI said:

Ah yes them moments can be annoying.
I reuploaded the sketch to another Arduino (Nano) and it works perfect.  I was using a Uno at first and that was fine to.
Only issue I see you having it is CommMG not being included correctly.

I will say I had the CommMG UDF and DLL in the same folder as the AutoIT Script so that way no issues would occur.

Good luck, I hope the script/sketch is clear enough for you as a base. :)
Cheers.

Unfortunately when i run the script with the correct com port added, it just says Can't connect to Arduino on port"what ever i have set it to". as i am new to autoit, any idea why its not connecting?

Share this post


Link to post
Share on other sites

When I first started making this I was having that exact same issue, This is when I added "commg.dll" and "CommMG.au3" in the same folder as the Autoit script.
worked like a charm from there.

I've uploaded the exact folder content I got, I transferred to another PC that was never used for Arduino and it worked just fine there as well.
I really hope this helps.

Cheers

BASIC ON OFF ARDUINO.rar

Share this post


Link to post
Share on other sites
10 hours ago, RISHKARI said:

When I first started making this I was having that exact same issue, This is when I added "commg.dll" and "CommMG.au3" in the same folder as the Autoit script.
worked like a charm from there.

I've uploaded the exact folder content I got, I transferred to another PC that was never used for Arduino and it worked just fine there as well.
I really hope this helps.

Cheers

BASIC ON OFF ARDUINO.rar

That was the issue it works flawlessly now, thank you so much :)

Share this post


Link to post
Share on other sites
6 hours ago, ShmoeMo said:

That was the issue it works flawlessly now, thank you so much :)

All good. Hope it helps with your project!
 

Share this post


Link to post
Share on other sites

Hi 

I am trying the same script and have kept the commMG UDF and dll in the same folder as the auto it script and arduino code. 

But i still get the error cant connect to arduino on port -x 

I confirmed the port with both the device manager and arduino ide but i still couldnt get it to work.

Please help

Share this post


Link to post
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
Sign in to follow this  
Followers 0