Thursday, June 11, 2015

Day 17

The last few days, Tim and I have been doing our best to figure out to control the motors using the Arduino board connected to the rep-rap board. Our starting point was the example code in the Arduino software to move the MotorKnob of a stepper. The example code was only for one stepper, and after some research we figured out ways of plugging in all 3 motors to the Arduino board which will be used to move the X, Y and Z axises in the platform for the HDPrime.

We were able to move the motors using the Arduino board. However there were a few limitations in moving the motors. First, Arduino code used a loop function called 'void loop()' which was needed to move the motor. This would continuously move the motor until there was no power in the Board or a different code was uploaded to the board. Second of, every time we need to change the amount of movement in the motor, we need to go through the Arduino code and change the value of the amount of movement. The method was not practical, so we needed an interface to interact with the Arduino board in order to input the values we needed.

After a briefly brainstorming, we decided to use RaspberryPi as an interface to send signals to the Arduino board. When we were learning Arduino code previously, when I barely stumbled upon a relationship between Arduino and RaspberryPi, so I knew it as a possibility. I had previous knowledge of RaspberryPi and Perl language beforehand, so Tim and I decided to give it a chance. Next day, we  had thorough research of RaspberryPi and Arduino in internet. This was challenging, because we used Perl language and had to initialize the connection between Arduino and RaspberryPi from the scratch. Initializing the connection between the boards was exhausting, because we found different instructions on each website we looked into. It was something that nobody had tried before. After spending quite some time on it, we came to a better understanding. We realized that we can actually send the values of the amount we need the motors to move, from the RaspberryPi to the Arduino board. So, through the code that we wrote, and is already uploaded, in the Arduino board, it will receive these values and then move the motors. However, the values Arduino receives from the RaspberryPi are in the ASCII format. Hence, after Dr McColgan's advice, we started calibrating the movement of the motors with ASCII and decimal values that the Arduino receives.

While doing so, we came across another issue. The motor did not receive enough power to provide the toque that is needed to move a pulley/belt which makes the platform move. So we are in process of searching suitable power sources to provide enough power to move the 3 motors.

Following is the code that was uploaded to Arduino board to test the connection between the RaspberryPi and the Arduino board.

/*
  Mega multple serial test

 Receives from the main serial port, sends to the others. 
 Receives from serial port 1, sends to the main serial (Serial 0).

 This example works only on the Arduino Mega

 The circuit: 
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:

 created 30 Dec. 2008
 modified 20 May 2012
 by Tom Igoe & Jed Roach

 This example code is in the public domain.

 */


void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    byte inByte = Serial1.read();
    Serial1.print("I received p1: ");
    Serial1.println(inByte, DEC); 
  }
  
  // read from port 0, send to port 1:
  if (Serial.available()) {
    byte inByte = Serial.read();
    Serial.print("I received p2: ");
    Serial.println(inByte);
  }

}

It WORKS! we received the transmitted data...

Following is the Perl code that we used to set the connection in RaspberryPi with the Arduino Board. We used this code to send data values to the Arduino.

#!/usr/bin/perl
# MoveMotor.pl

use Device::SerialPort;

my $port = Device::SerialPort->new("/dev/ttyACM0");

$port->baudrate(9600);
$port->databits(8);
$port->parity("none");
$port->stopbits(1);
$port->handshake("xoff");
$port->write_settings;
$port->dtr_active(0);

#$port->write('include <Stepper.h>');
#$port->write('define STEPS 100');

#my $motorX = $port->write('Stepper stepperX(STEPS, 10,11,12,13));
#my $motorY = $port->write('Stepper stepperY(STEPS, 6,7,8,9));
#my $motorZ = $port->write('Stepper stepperZ(STEPS, 2,3,4,5));

#my $sx = 30;
#my $sy = 30;
#my $sz = 30;

#while (1) {
#    $port->write('$sx');
#    $port->write('$sy');
#    $port->write('$sz');
#    print($port->receive(), "\n");
#    sleep(1);
#}

while (1) {
    
    print "Move in X Direction: ";
    my $x = <STDIN>;
    chomp($x);
    print "Sending $x...\n";

    print "Move in Y Direction: ";
    my $y = <STDIN>;
    chomp($y);
    print "Sending $y...\n";

    print "Move in Z Direction: ";
    my $z = <STDIN>;
    chomp($z);
    print "Sending $z...\n\n\n";

    $port->write("$x");
    $port->write("$y");
    $port->write("$z");
}
$port->close();

Perl language: '#' lines are comments that are not effected to overall program execution.
They were several approaches we used.

Following is the Arduino code that we used to move the motors. This is the code that reads data from RaspberryPi and hence moves the motors.

#include <Stepper.h>

#define STEPS 200

Stepper stepperX(STEPS, 10,11,12,13);
Stepper stepperY(STEPS, 6,7,8,9);
Stepper stepperZ(STEPS, 2,3,4,5);

void setup()
{
  Serial.begin(9600);
  // set the speed of the motor to 30 RPMs
  stepperX.setSpeed(30);
  stepperY.setSpeed(30);
  stepperZ.setSpeed(60);
}

//int mx = 10;
//int my = 20;
//int mz = 50;

/* void loop() {
 MoveX();
 MoveY();
 MoveZ();
 delay(12);
}
*/

void loop() {
  if (Serial.available()) {  
   int mx = Serial.read();
   Serial.print("I received mx: ");
   Serial.println (mx);
   stepperX.step(mx);
  }

  if (Serial.available()) {  
   int my = Serial.read();
   Serial.print("I received my: ");
   Serial.println (my);
   stepperY.step(my);
  }

  if (Serial.available()) {  
   int mz = Serial.read();
   Serial.print("I received mz: ");
   Serial.println (mz);
   stepperZ.step(mz);
  }
}
Arduino Board connected to the reprap which is in link with the motors

Our attempt to move the Printrbot print bed
using the motors connected to the Arduino,
RaspberryPi and the reprap

RaspberryPi in Action

Day- 19
June 11th 2015
These past few days have been used in an attempt to create a final configuration of our printrbot to be used for the HDPrime.  Our final product is not as beautiful as we had imagined but it does move in all three directions and functions as we had anticipated.  the pictures below don't even come close to revealing how many zip-ties we used in the re design.  Once the end of the final week started closing in on us we decided to put the coding on the side burner and come up with a physical product.  After sawing off some wooden parts we re-mounted the X-axis bed atop our structure.  The printrboard still lies outside our structure and with all the wires remaining uncovered, plans for modeling a new stage to be made in the fall have been made.
A frontal view of our reconfigured printrbot

side view: the bed that was originally mounted above the SD card is now placed atop our Y-axis arm allowing the bed to move in all three directions and not just one

Wednesday, June 3, 2015

Day 13-
June 3rd

These past few days have been dedicated to understanding Arduino coding along with the Mega chip and it's sistering rep-rap board. So far we have been able to make all our motors move in a random fashion after we decimated our original 3d printrbot shown in pieces below.  But not in the way we expected it to, originally, the plan was to mount the rep-rap board atop the mega Arduino board, but after running multiple tests we gave up and attempted to wire the boards together in a more crude fashion, by closely examining the board we wired the two boards together so that it would allow us to utilize the two boards together and Dr. McColgan confirmed that we could use the setup for our final product.  So far the code we are using for our motors is one that Cham and I found on the example section on the Arduino website, our adapted code is as follows.
/*
 * MotorKnob
 *
 * A stepper motor follows the turns of a potentiometer
 * (or other sensor) on analog input 0.
 *
 * This example code is in the public domain.
 */

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepperX(STEPS, 10,11,12,13);
Stepper stepperY(STEPS, 6,7,8,9);
Stepper stepperZ(STEPS, 2,3,4,5);
// the previous reading from the analog input
int previous = 0;

void setup()
{
  Serial.begin(9600);
  // set the speed of the motor to 30 RPMs
  stepperX.setSpeed(30);
  stepperY.setSpeed(30);
  stepperZ.setSpeed(30);
}

void loop()
{
  // get the sensor value
  int val = analogRead(0);
  Serial.print(val); Serial.print(" "); Serial.println(previous);
  // move a number of steps equal to the change in the
  // sensor reading
  stepperX.step(20);
  stepperY.step(-20);
  stepperZ.step(30);
  

  // remember the previous value of the sensor
  previous = val;
}


The wiring setup for the motors in our printer
Our beautiful 3d printer- Dismantled.