ShmoeMo Posted March 12, 2016 Share Posted March 12, 2016 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 Link to comment Share on other sites More sharing options...
RISHKARI Posted March 12, 2016 Share Posted March 12, 2016 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. Link to comment Share on other sites More sharing options...
ShmoeMo Posted March 12, 2016 Author Share Posted March 12, 2016 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??? Link to comment Share on other sites More sharing options...
RISHKARI Posted March 12, 2016 Share Posted March 12, 2016 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. expandcollapse popup#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. expandcollapse popupchar 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. Link to comment Share on other sites More sharing options...
ShmoeMo Posted March 12, 2016 Author Share Posted March 12, 2016 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. expandcollapse popup#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. expandcollapse popupchar 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. Link to comment Share on other sites More sharing options...
RISHKARI Posted March 12, 2016 Share Posted March 12, 2016 No worries mate, make sure to let us know if it works perfectly for you. This should help others out aswell. Cheers. Link to comment Share on other sites More sharing options...
ShmoeMo Posted March 12, 2016 Author Share Posted March 12, 2016 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 Link to comment Share on other sites More sharing options...
RISHKARI Posted March 12, 2016 Share Posted March 12, 2016 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. Link to comment Share on other sites More sharing options...
ShmoeMo Posted March 14, 2016 Author Share Posted March 14, 2016 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? Link to comment Share on other sites More sharing options...
RISHKARI Posted March 14, 2016 Share Posted March 14, 2016 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 Link to comment Share on other sites More sharing options...
ShmoeMo Posted March 15, 2016 Author Share Posted March 15, 2016 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 Link to comment Share on other sites More sharing options...
RISHKARI Posted March 15, 2016 Share Posted March 15, 2016 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! Link to comment Share on other sites More sharing options...
Satvik Posted November 26, 2016 Share Posted November 26, 2016 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 Link to comment Share on other sites More sharing options...
Soil_Person Posted June 24, 2020 Share Posted June 24, 2020 (edited) On 11/26/2016 at 4:41 PM, Satvik said: 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 You have to put your script in the same folder as the commMG.au3 and commdll files. What worked for me was putting it all in the 'include' folder on the AutoIT install location. Put all 3 files in there. Also, make sure your commMG file is the same one we are all talking about here, if these codes don't match, no dice! Here is the link for the commMG.au3 and commdll files (just to make sure) https://www.mosaiccgl.co.uk/AutoItDownloads/confirm.php?get=COMMGvv2.zip eg: C:\Program Files (x86)\AutoIt3\Include Note: I am running this on AutoIT v3.3.14.5 (I don't think this matters, but it might) Edited June 24, 2020 by Soil_Person Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now