Jump to content

Arduino and AutoIt?


Recommended Posts

I have recently started a new DIY project which aims to automatically water my plants by measuring the moist in the soil and automatically water my plant if its to dry using the Arduino electronics prototyping platform. In the end it will become a fully automatic greenhouse. Website of Arduino: Arduino Website

Now I really love AutoIt and I am hoping to somehow be able to control and read Arduino using AutoIt. The problem is that I have no Idea how to access a library or how to write one so it can be accessed. (There is a guide of how to write a library for Arduino here: Arduino Library Tutorial) Also there is a Library called Firmata which can be found here: Firmata and the Library commands here: Firmata Library. A simple script for Arduino can be found here: Analog Input. If I could control Arduino with AutoIt like that I could do everything I want to do with this cool toy =)

Is there somebody here that has the time and knowledge and could explain to me how to use this Firmata protocol in AutoIt? (Sadly I have no Idea about languages other than autoit and VBA)

I would really apreciate it!

Cheers,

Adrian

Edited by crazycrash
Link to comment
Share on other sites

  • 1 month later...

I would like to refresh this topic as I have just discovered these great open source USB control boards.

Does anyone know how to communicate with these boards with autoit?

Thanks in advance

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

  • 6 months later...

Hey guys! i just bought one of these. Havent tried anything yet really but methinks:

http://www.autoitscript.com/forum/index.ph...st&p=341916

to talk to it. will keep in touch.

----edit

just fired it up. works! im recieving some code alternating. "+Ru"

-----edit.

when i type text into the field provided. i see the rx light up!

Edited by ghetek
Link to comment
Share on other sites

  • 1 year later...

Does anybody succes on moving servomotors with an arduino and autoit?

Something like:

Case = $button1
    moveservo90()

Func moveservo90()
digitalwrite($pin,90)
Endfunc

I've seen examples about lightning leds with arduino, autoit and the CommMG UDF of Martin, but nothing about moving servomotors.

In the arduino oficial in the examples:

Servo myservo;  // create servo object to control a servo

{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

how can we do this two things on autoit (creae the servo object and the attach func)??

Greets from Barcelona

Link to comment
Share on other sites

  • 6 months later...

Hi Guys, my first post :) just started with AutoIt and the Arduino.

Just got this working myself today, so will post what worked for me ;)

Using the CommMG UDF from Martin.

Autoit

_CommSendByte($VariableName)  // Eg. Sending a value between 0 and 20

Arduino Sketch

#include <Servo.h> 
 
Servo ServoAngleServo;  // create servo object to control a servo 
int ServoAngleValue;    // variable to store the servo position 
 
void setup() 
{ 
  Serial.begin(9600);  
  ServoAngleServo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  if (Serial.available())               // wait for serial input
  {
    int ServoAngleValue = Serial.read();  // read the incoming byte: 
    if(ServoAngleValue >=0 and ServoAngleValue <= 180)
    { 
      ServoAngleValue = map(ServoAngleValue, 0, 20, 0, 180); //Convert my value (0-20) into servo range (0-180)  
      ServoAngleServo.write(ServoAngleValue);  
      delay(15);      // waits 15ms for the servo to reach the position
    }     
   } 
 }

Hope that helps.

Edited by reaper7
Link to comment
Share on other sites

  • 2 months later...

Hi Guys, my first post :graduated: just started with AutoIt and the Arduino.

Just got this working myself today, so will post what worked for me ;)

Using the CommMG UDF from Martin.

Autoit

_CommSendByte($VariableName)  // Eg. Sending a value between 0 and 20

Arduino Sketch

#include <Servo.h>
 
Servo ServoAngleServo;  // create servo object to control a servo
int ServoAngleValue;    // variable to store the servo position
 
void setup()
{
  Serial.begin(9600);  
  ServoAngleServo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  if (Serial.available())              // wait for serial input
  {
    int ServoAngleValue = Serial.read();  // read the incoming byte:
    if(ServoAngleValue >=0 and ServoAngleValue <= 180)
    {
      ServoAngleValue = map(ServoAngleValue, 0, 20, 0, 180); //Convert my value (0-20) into servo range (0-180)  
      ServoAngleServo.write(ServoAngleValue);  
      delay(15);      // waits 15ms for the servo to reach the position
    }   
   }
}

Hope that helps.

Thanks for sharing it with us reaper7.

Is there a way to control more servos with your example?

I have 3 servomotors and it would be great to be able to move them doing something like:

_CommSendByte($VariableName)  // Eg. Sending a value between 0 and 20 to move servo connected to digital pin 8

_CommSendByte($VariableName)  // Eg. Sending a value between 30 and 50 to move servo connected to digital pin 9

_CommSendByte($VariableName)  // Eg. Sending a value between 60 and 80 to move servo connected to digital pin 7
?

I can feed the servos with an external source, but I don't know how to create a .pde and autoit code to control them :)

Thanks for any help.

Edited by adolfito121
Link to comment
Share on other sites

Thanks for sharing it with us reaper7.

Is there a way to control more servos with your example?

I have 3 servomotors and it would be great to be able to move them doing something like:

_CommSendByte($VariableName)  // Eg. Sending a value between 0 and 20 to move servo connected to digital pin 8

_CommSendByte($VariableName)  // Eg. Sending a value between 30 and 50 to move servo connected to digital pin 9

_CommSendByte($VariableName)  // Eg. Sending a value between 60 and 80 to move servo connected to digital pin 7
?

I can feed the servos with an external source, but I don't know how to create a .pde and autoit code to control them :graduated:

Thanks for any help.

Hi adolfito,

Sure no problem you can use this to get you up and running. I've included code for 2 servos bit its simple to add more to it.

Code for Autoit

#include 'CommMG.au3'
;Internal for the Serial UDF
Global $sportSetError = ''
 
;COM Vars
Global $CMPort = 1 ; Port
Global $CmBoBaud = 9600 ; Baud
Global $CmboDataBits = 8 ; Data Bits
Global $CmBoParity = "none" ; Parity
Global $CmBoStop = 1 ; Stop
Global $setflow = 2 ; Flow
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
_CommSetRTS(0)
_CommSetDTR(0)
 
If @error Then
ConsoleWrite("Error in Com Port!" & @CR)
Exit
EndIf
 
while 1
(Your code to create the values to send to servo 1 and 2)
_CommSendString(stringformat("A%03d",int($Servo1)))
_CommSendString(stringformat("B%03d",int($Servo2)))
WEnd

This (stringformat("A%03d",int($Servo1))) part is sending the following Axxx (where x is a value between 000 and 999) the value xxx is whats contained in $Servo1.

This is then read into the Arduino as follows

And Code for Arduino

#include <Servo.h>
Servo Servo1;  // create servo called Servo1
Servo Servo2;  // create servo called Servo2
char Address;  //Variable to store Incoming Packets ID
int val = 0;
int data = 0;
void setup()
{
  Serial.begin(9600);
  Servo1.attach(8);  // attaches the servo1 on pin 8 to the servo object
  Servo2.attach(9);  // attaches the servo2 on pin 9 to the servo object
}
void loop()
{
  while (Serial.available() > 0)
  {
    Address = Serial.read();
    if (Address == 'A') Read_Servo1();  // If ID = A goto Servo1
    if (Address == 'B') Read_Servo2();  // If ID = B goto Servo2
  }
}
 
void Read_Servo1()
{
  delay(2); int data100 = Serial.read()- '0';  // Read in first bit od data
  delay(2); int data10 = Serial.read()- '0';  // Read in second bit od data
  delay(2); int data1 = Serial.read()- '0';  // Read in third bit od data
  data = 100*data100 + 10*data10 + data1; // Left shift each byte, add add together to get our value 000
  val = map(data, 0, 200, 10, 180);  // Asign our range of 0 - 200 to the servos range of  0 - 180
  Servo1.write(val);  //Write the value to Serial
  delay(10);      // waits 10ms for the servo to reach the position
}
void Read_Servo2()
{
  delay(2); int data100 = Serial.read()- '0';
  delay(2); int data10 = Serial.read()- '0';
  delay(2); int data1 = Serial.read()- '0';
  data = 100*data100 + 10*data10 + data1;
  val = map(data, 0, 250, 10, 180);
  Servo2.write(val);
  delay(10);      // waits 10ms for the servo to reach the position
}

You need to change your range to suit the range of values you are sending your servo.

Eg I'm sending a range of 0 to 200 to my servo so the above converts 1-200 into the range of travel of my servo 0deg to 180deg.

So for you first servo you could have [val = map(data, 0, 20, 0, 90);] This would convert your range of 0-20 into the servo movement of 0deg to 90deg.

Also I'm sending and reviving numbers in the range of 1-999 ie: 3 characters long, you could change the above code easily to send in the range of 0-99 2 characters long very easily.

Hope that helps.

Edited by reaper7
Link to comment
Share on other sites

  • 4 years later...
On 17/10/2011 at 0:57 PM, reaper7 said:

And Code for Arduino

 

#include <Servo.h>
Servo Servo1;  // create servo called Servo1
Servo Servo2;  // create servo called Servo2
char Address;  //Variable to store Incoming Packets ID
int val = 0;
int data = 0;
void setup()
{
  Serial.begin(9600);
  Servo1.attach(8);  // attaches the servo1 on pin 8 to the servo object
  Servo2.attach(9);  // attaches the servo2 on pin 9 to the servo object
}
void loop()
{
  while (Serial.available() > 0)
  {
    Address = Serial.read();
    if (Address == 'A') Read_Servo1();  // If ID = A goto Servo1
    if (Address == 'B') Read_Servo2();  // If ID = B goto Servo2
  }
}
 
void Read_Servo1()
{
  delay(2); int data100 = Serial.read()- '0';  // Read in first bit od data
  delay(2); int data10 = Serial.read()- '0';  // Read in second bit od data
  delay(2); int data1 = Serial.read()- '0';  // Read in third bit od data
  data = 100*data100 + 10*data10 + data1; // Left shift each byte, add add together to get our value 000
  val = map(data, 0, 200, 10, 180);  // Asign our range of 0 - 200 to the servos range of  0 - 180
  Servo1.write(val);  //Write the value to Serial
  delay(10);      // waits 10ms for the servo to reach the position
}
void Read_Servo2()
{
  delay(2); int data100 = Serial.read()- '0';
  delay(2); int data10 = Serial.read()- '0';
  delay(2); int data1 = Serial.read()- '0';
  data = 100*data100 + 10*data10 + data1;
  val = map(data, 0, 250, 10, 180);
  Servo2.write(val);
  delay(10);      // waits 10ms for the servo to reach the position
}

 

I just wanted to optimize a little the Arduino code

#include <Servo.h>
Servo Servo1;  // create servo called Servo1
Servo Servo2;  // create servo called Servo2
char Address;  //Variable to store Incoming Packets ID

void setup()
{
	Serial.begin(9600);
	Servo1.attach(8);  // attaches the servo1 on pin 8 to the servo object
	Servo2.attach(9);  // attaches the servo2 on pin 9 to the servo object
}//end setup

void loop()
{
	while (Serial.available() > 0)
	{
		Address = Serial.read();
		Read_Servo(Address);  //goto Read_Servo
	}//end while
}//end loop
 
void Read_Servo(char Address)
{
	int val = 0;
	int data = 0;
	delay(2); int data100 = Serial.read()- '0';  // Read in first bit od data
	delay(2); int data10 = Serial.read()- '0';  // Read in second bit od data
	delay(2); int data1 = Serial.read()- '0';  // Read in third bit od data
	data = 100*data100 + 10*data10 + data1; // Left shift each byte, add add together to get our value 000
	val = map(data, 0, 200, 10, 180);  // Asign our range of 0 - 200 to the servos range of  0 - 180
  
	if (Address == 'A') //If ID = A use Servo1
		Servo1.write(val);  //Write the value to Serial
	if (Address == 'B') //If ID = B use Servo2
		Servo2.write(val);  //Write the value to Serial

	delay(10);      // waits 10ms for the servo to reach the position
}//end Read_Servo

 

Edited by b1nar10
correct a comment
Link to comment
Share on other sites

  • 3 years later...

Hi everyone, 

I was having trouble with this thread, as the codes above do not include any usable inputs to try this out straight away. I've adapted the above 'AutoIT' and 'Arduino' codes by reaper7  to include a GUI to move 1 servo between 0-180 degrees. This GUI is simple, type a number between 0 and 180, then press 'Move Servo'. The servo will then move to the desired location.

IMPORTANT:  I'm assuming you are using a 180 degree servo here. If you are using a 90 degree servo, this may overextended your servo and damage it. Adjust to code in the Arduino code to suit your servo's rotational limits (3rd last line of Arduino code).

For a 180 degree servo: val = map(data, 0,180, 0, 170)

For a 90 degree servo: val = map(data, 0,180, 0, 90)

On a trouble shooting note: At first I was having trouble getting AutoIT to even recognise the Arduino port. To fix this 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    

 

AutoIT Code: 

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

Global $CMPort = 7
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)

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("AutoIT -->Arduino Servo Mover", 407, 115, 358, 304)
Global $ServoValueInputBox = GUICtrlCreateInput("90", 232, 16, 137, 32);Defualt value is 90 (ie: 90- degrees)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
Global $ServoLabel = GUICtrlCreateLabel("Servo Value (0-180)",40, 16, 170, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
Global $MoveServoButton = GUICtrlCreateButton("Move Servo", 40, 56, 331, 49)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    $Servo1 = GUICtrlRead($ServoValueInputBox)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MoveServoButton
            GUICtrlRead($ServoValueInputBox)
            _CommSendString(stringformat("A%03d",int($Servo1)))
    EndSwitch
WEnd

Arduino Code:

#include <Servo.h>
Servo Servo1;  // create servo called Servo1
Servo Servo2;  // create servo called Servo2
char Address;  //Variable to store Incoming Packets ID
int val = 0;
int data = 0;
void setup()
{
  Serial.begin(9600);
  Servo1.attach(8);  // attaches the servo1 on pin 8 to the servo object
}
void loop()
{
  while (Serial.available() > 0)
  {
    Address = Serial.read();
    if (Address == 'A') Read_Servo1();  // If ID = A goto Servo1
  }
}
 
void Read_Servo1()
{
  delay(2); int data100 = Serial.read()- '0';  // Read in first bit od data
  delay(2); int data10 = Serial.read()- '0';  // Read in second bit od data
  delay(2); int data1 = Serial.read()- '0';  // Read in third bit od data
  data = 100*data100 + 10*data10 + data1; // Left shift each byte, add add together to get our value 000
  val = map(data, 0,180, 0, 170);  // Asign our range of 0 - 180 to the servos range of  0 - 170
  Servo1.write(val);  //Write the value to Serial
  delay(10);      // waits 10ms for the servo to reach the position
}

Enjoy, Soil_Person

Edited by Soil_Person
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...