Sign in to follow this  
Followers 0
crazycrash

Arduino and AutoIt?

10 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

:graduated: It worked like a charm with 3 servos!!!

THANKS A LOT!!!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Glad you have it working :graduated: . Real thanks goes to Martin and his UDF - his helped me to work it out Initially.

Edited by reaper7

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

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