diff --git a/Software/Arduino/libraries/readme.txt b/Software/Arduino/libraries/readme.txt new file mode 100644 index 0000000..a8f1390 --- /dev/null +++ b/Software/Arduino/libraries/readme.txt @@ -0,0 +1 @@ +For information on installing libraries, see: http://arduino.cc/en/Guide/Libraries diff --git a/Software/Arduino/sketch_jun04a/sketch_jun04a.ino b/Software/Arduino/sketch_jun04a/sketch_jun04a.ino new file mode 100644 index 0000000..cb4fa60 --- /dev/null +++ b/Software/Arduino/sketch_jun04a/sketch_jun04a.ino @@ -0,0 +1,77 @@ +/* +Author: F. Lionetto +Created on: June 4th, 2014 + +The sketch inizializes the position of the two stepper motors. + +Coordinate system: +- x axis across the strips, forward direction is toward the window, backward direction is toward the door (stepper motor 1); +- y axis along the strips; +- z axis toward the strips, forward direction is down, backward direction is up (stepper motor 2). + +The x micro switch is connected to pin 22. +The z micro switch is connected to pin 23. + +Distances in microns. +*/ + +#include +#include +#include "utility/Adafruit_PWMServoDriver.h" + +// Stepper motor properties. +const int stepsPerRevolution = 200; +const int singleStep = 5; + +// Create the motor shield object with the default I2C address. +Adafruit_MotorShield AFMS = Adafruit_MotorShield(); + +// Connect a stepper motor with 200 steps per revolution (1.8 degree) to motor port #1 (M1 and M2). +Adafruit_StepperMotor *myMotorX = AFMS.getStepper(stepsPerRevolution, 1); +Adafruit_StepperMotor *myMotorZ = AFMS.getStepper(stepsPerRevolution, 2); + +// Micro switch properties. +const int switchXPin = 22; +const int switchZPin = 23; +int switchXState = 0; +int switchZState = 0; + +void setup() { + Serial.begin(9600); + Serial.println("This is a test!"); + + AFMS.begin(); + + myMotorX->setSpeed(50); + myMotorZ->setSpeed(50); + + pinMode(switchXPin,INPUT); + pinMode(switchZPin,INPUT); + + Serial.println("Inizializing position along x..."); + + while (switchXState == LOW) { + switchXState = digitalRead(switchXPin); + if (switchXState == LOW) { + // The stepper motor is not at the origin of the coordinate system. + myMotorX->step(1,FORWARD,DOUBLE); + } + } + + Serial.println("Position along x successfully initialized."); + + Serial.println("Inizializing position along z..."); + + while (switchZState == LOW) { + switchZState = digitalRead(switchZPin); + if (switchZState == LOW) { + // The stepper motor is not at the origin of the coordinate system. + myMotorZ->step(1,BACKWARD,DOUBLE); + } + } + + Serial.println("Position along z successfully initialized."); +} + +void loop() { +} diff --git a/Software/Arduino/sketch_jun17a/sketch_jun17a.ino b/Software/Arduino/sketch_jun17a/sketch_jun17a.ino new file mode 100644 index 0000000..e991af8 --- /dev/null +++ b/Software/Arduino/sketch_jun17a/sketch_jun17a.ino @@ -0,0 +1,132 @@ +/* +Author: F. Lionetto +Created on: June 4th, 2014 + +The sketch inizializes the position of the two stepper motors, move the laser 5 cm (10000 steps) away from the x micro switch, move the laser 2.5 cm (5000) away from the z micro switch, and then perform a scan for finding the focal length. + +Scan for finding the focal length: +- at a given z position, move one step backward along x, wait, move one step backward along x, wait, and so on (enough times to go across two strips); +- go back to the initial position along x; +- move one step forward along z; +- repeat from the beginning (enough times to be sure to find the focal length, but not that many to touch the silicon sensor); +- again and again. +In the current configuration, scan of 1 mm along x and 1 mm along z. + +Coordinate system: +- x axis across the strips, forward direction is toward the window, backward direction is toward the door (stepper motor 1); +- y axis along the strips; +- z axis toward the strips, forward direction is down, backward direction is up (stepper motor 2). + +The x micro switch is connected to pin 22. +The z micro switch is connected to pin 23. + +Distances in microns. +*/ + +#include +#include +#include "utility/Adafruit_PWMServoDriver.h" + +// Stepper motor properties. +const int stepsPerRevolution = 200; +const int singleStep = 5; + +// Create the motor shield object with the default I2C address. +Adafruit_MotorShield AFMS = Adafruit_MotorShield(); + +// Connect a stepper motor with 200 steps per revolution (1.8 degree) to motor port #1 (M1 and M2). +Adafruit_StepperMotor *myMotorX = AFMS.getStepper(stepsPerRevolution, 1); +Adafruit_StepperMotor *myMotorZ = AFMS.getStepper(stepsPerRevolution, 2); + +// Micro switch properties. +const int switchXPin = 22; +const int switchZPin = 23; +int switchXState = 0; +int switchZState = 0; + +// Scan properties. +// Total number of steps we need along x. +const int totStepsX = 200; +// Total number of steps we need along y. +const int totStepsZ = 200; +int stepsX = 0; +int stepsZ = 0; + +void setup() { + Serial.begin(9600); + Serial.println("This is a test!"); + + AFMS.begin(); + + myMotorX->setSpeed(50); + myMotorZ->setSpeed(50); + + pinMode(switchXPin,INPUT); + pinMode(switchZPin,INPUT); + + Serial.println("Inizializing position along x..."); + + while (switchXState == LOW) { + switchXState = digitalRead(switchXPin); + if (switchXState == LOW) { + // The stepper motor is not at the origin of the coordinate system. + myMotorX->step(1,FORWARD,DOUBLE); + } + } + + Serial.println("Position along x successfully initialized."); + + Serial.println("Inizializing position along z..."); + + while (switchZState == LOW) { + switchZState = digitalRead(switchZPin); + if (switchZState == LOW) { + // The stepper motor is not at the origin of the coordinate system. + myMotorZ->step(1,BACKWARD,DOUBLE); + } + } + + Serial.println("Position along z successfully initialized."); + + Serial.println("Moving the laser 5 cm (10000 steps) away from the x micro switch..."); + + myMotorX->step(10000,BACKWARD,DOUBLE); + + Serial.println("Laser moved 5 cm (10000 steps) away from the x micro switch."); + + Serial.println("Moving the laser 2.5 cm (5000 steps) away from the z micro switch..."); + + myMotorZ->step(5000,FORWARD,DOUBLE); + + Serial.println("Laser moved 2.5 cm (5000 steps) away from the z micro switch."); + + myMotorX->setSpeed(5); + myMotorZ->setSpeed(5); + + myMotorX->release(); + myMotorZ->release(); +} + +void loop() { +// Scan for finding the focal length. + if(stepsZ < totStepsZ) { + Serial.print("Data acquisition at z = "); + Serial.println(stepsZ); + if (stepsX < totStepsX) { + myMotorX->step(1,BACKWARD,DOUBLE); + myMotorX->release(); + stepsX = stepsX + 1; + } + else if (stepsX == totStepsX) { + myMotorX->step(totStepsX,FORWARD,DOUBLE); + myMotorX->release(); + stepsX = 0; + myMotorZ->step(1,FORWARD,DOUBLE); + myMotorZ->release(); + stepsZ = stepsZ + 1; + } + } + else { + Serial.println("Scan for finding the focal length completed."); + } +} diff --git a/Software/Arduino/sketch_jun23a/sketch_jun23a.ino b/Software/Arduino/sketch_jun23a/sketch_jun23a.ino new file mode 100644 index 0000000..c3db030 --- /dev/null +++ b/Software/Arduino/sketch_jun23a/sketch_jun23a.ino @@ -0,0 +1,187 @@ +/* +Author: F. Lionetto +Created on: June 23rd, 2014 + +The sketch inizializes the position of the two stepper motors, move the laser 4.25 cm (8500 steps) away from the x micro switch, move the laser 2.5 cm (5000 steps) away from the z micro switch, and then waits for commands sent through the USB port. + +Coordinate system: +- x axis across the strips, forward direction is toward the window, backward direction is toward the door (stepper motor 1); +- y axis along the strips; +- z axis toward the strips, forward direction is down, backward direction is up (stepper motor 2). + +The x micro switch is connected to pin 22. +The z micro switch is connected to pin 23. + +The stepper motors have two different speeds, one for non-precise and one for precise positioning, respectively. + +ASCII printable characters: ++ ---> 43; +0 ---> 48; +1 ---> 49; +2 ---> 50. + +The only allowed commands (checked before and after being sent through the USB port) are: ++10 ---> move one step forward along x; ++20 ---> move one step backward along x ++01 ---> move one step forward along z; ++02 ---> move one step backward along z. + +Distances in microns. +*/ + +#include +#include +#include "utility/Adafruit_PWMServoDriver.h" + +// Stepper motor properties. +const int stepsPerRevolution = 200; +const int singleStep = 5; +const int speedFast = 50; +const int speedSlow = 5; + +// Create the motor shield object with the default I2C address. +Adafruit_MotorShield AFMS = Adafruit_MotorShield(); + +// Connect a stepper motor with 200 steps per revolution (1.8 degree) to motor port #1 (M1 and M2). +Adafruit_StepperMotor *myMotorX = AFMS.getStepper(stepsPerRevolution, 1); +Adafruit_StepperMotor *myMotorZ = AFMS.getStepper(stepsPerRevolution, 2); + +// Micro switch properties. +const int switchXPin = 22; +const int switchZPin = 23; +int switchXState = 0; +int switchZState = 0; + +// Scan properties. +// Maximum distance from the x micro switch (!!!) +// const int maxStepsX = 16000; +// Maximum distance from the z micro switch (!!!) +// const int maxStepsZ = 5400; +// Move the laser 4.25 cm (8500 steps) away from the x micro switch +const int stepsFromXSwitch = 8500; +// Move the laser 2.5 cm (5000) away from the z micro switch +const int stepsFromZSwitch = 5000; +// Total number of steps we need along x. +// const int totStepsX = 200; +// Total number of steps we need along y. +// const int totStepsZ = 200; +// int stepsX = 0; +// int stepsZ = 0; +// Byte read from the USB port. +byte byteUSB; +// 1 if the byte read from the USB port is +. +boolean commandReceived = false; +// 1 if the byte read from the USB port is the first after +. +boolean xCommandReceived = false; +// 1 if the byte read from the USB port is the second after +. +boolean zCommandReceived = false; +int moveX = 0; +int moveZ = 0; + +void stepAction(int moveX, int moveZ) { + if (moveX == 1) { + myMotorX->step(1,FORWARD,DOUBLE); + Serial.println("Moving forward along x..."); + } + else if (moveX == 2) { + myMotorX->step(1,BACKWARD,DOUBLE); + Serial.println("Moving backward along x..."); + } + if (moveZ == 1) { + myMotorZ->step(1,FORWARD,DOUBLE); + Serial.println("Moving forward along z..."); + } + else if (moveZ == 2) { + myMotorZ->step(1,BACKWARD,DOUBLE); + Serial.println("Moving backward along z..."); + } +} + +void setup() { + Serial.begin(9600); + Serial.println("This is a test!"); + + AFMS.begin(); + + myMotorX->setSpeed(speedFast); + myMotorZ->setSpeed(speedFast); + + pinMode(switchXPin,INPUT); + pinMode(switchZPin,INPUT); + + Serial.println("Inizializing position along x..."); + + while (switchXState == LOW) { + switchXState = digitalRead(switchXPin); + if (switchXState == LOW) { + // The stepper motor is not at the origin of the coordinate system. + myMotorX->step(1,FORWARD,DOUBLE); + } + } + + Serial.println("Position along x successfully initialized."); + + Serial.println("Inizializing position along z..."); + + while (switchZState == LOW) { + switchZState = digitalRead(switchZPin); + if (switchZState == LOW) { + // The stepper motor is not at the origin of the coordinate system. + myMotorZ->step(1,BACKWARD,DOUBLE); + } + } + + Serial.println("Position along z successfully initialized."); + + Serial.println("Moving the laser 4.25 cm (8500 steps) away from the x micro switch..."); + + myMotorX->step(stepsFromXSwitch,BACKWARD,DOUBLE); + + Serial.println("Laser moved 4.25 cm (8500 steps) away from the x micro switch."); + + Serial.println("Moving the laser 2.5 cm (5000 steps) away from the z micro switch..."); + + myMotorZ->step(stepsFromZSwitch,FORWARD,DOUBLE); + + Serial.println("Laser moved 2.5 cm (5000 steps) away from the z micro switch."); + + myMotorX->setSpeed(speedSlow); + myMotorZ->setSpeed(speedSlow); + + // myMotorX->release(); + // myMotorZ->release(); +} + +void loop() { + if (Serial.available()) { + byteUSB = Serial.read(); + Serial.println(byteUSB); + if ((byteUSB != 43) && (byteUSB !=48) && (byteUSB != 49) && (byteUSB != 50)) { + Serial.println("Invalid command received."); + } + else if ((commandReceived == false) && (byteUSB == 43)) { + commandReceived = true; + Serial.println("Valid command received."); + xCommandReceived = false; + zCommandReceived = false; + moveX = 0; + moveZ = 0; + } + else if ((commandReceived == true) && (xCommandReceived == false)) { + moveX = byteUSB - 48; + Serial.println(moveX); + xCommandReceived = true; + Serial.println("Command for x direction received."); + } + else if ((commandReceived == true) && (zCommandReceived == false)) { + moveZ = byteUSB - 48; + Serial.println(moveZ); + zCommandReceived = true; + Serial.println("Command for z direction received."); + } + } + else if ((commandReceived == true) && (xCommandReceived == true) && (zCommandReceived == true)) { + stepAction(moveX,moveZ); + commandReceived = false; + } +}