[Blackpool] Light Box / Rotating Camera Base

Anthony Pollitt apollitt at fastmail.fm
Sat Nov 4 10:00:51 UTC 2017


Hello Chaps!

I haven't managed to get myself away yet (I'm leaving Thursday) but I do
have a few things to arrange before I go and so can't make it down to the
Makerspace today.

So, I need to pass on a few brief details about the Pi/Arduino setup of the
rotating camera base:
(Note the script name might not be quite right, I'm going from memory -
just have a look in the folder).

I'm back from my trip on Dec. 6th and so I hope to see you all on the 9th
if we're meeting. If you have any questions in the meantime, fell free to
drop me an email.

All the best,

Anthony.


Pi info:
    login: pi
    password: raspberry1
    network: wired/DHCP
    hostname: anthonynode1
    To perform a camera run:
        ssh to anthonynode1
        cd /home/pi/3dscan
        ./anth3dScanDir.ux [folderName] #This script runs crudely loops 30
times. Sends the number of degrees to the arduino to run the stepper motor,
waits for a serial response to confirm movement complete and then takes the
photo.
        You should be able to see the photos as they're taking by visiting
the samba share \\anthonynode1\home\pi\3dscan\[folderName].
        The current setup doesn't actually use the number of degrees as
this needs to be calibrated in the arduino code - currently it just rotates
the stepper by an arbitrary value. This should be self explanatory when
looking at the bash script/arduino code.

Arduino code:

/* BLUG_3dScannerStepper_v5.ino
 * Anthony Pollitt : 28/10/2017
 *
 * This sketch is to control a stepper motor and controller (28BYJ-48) based
 *   on input from a serial connection (expected to be a Raspberry Pi.
 *   It receives an integer (+CR) from the serial connection and runs the
 *   stepper motor to acheive that number of degrees of motion.
 *
 * DO NOT USE SERIAL DEBUG STATEMENTS AS THE SERIAL OUTPUT IS USED TO
INFORM THE PI
 *   THAT MOVEMENT IS COMPLETE.
 *
 * NOTE THE ORDER OF THE STEPPER PINS.
 *
 * To do:
 *   1, Calibrate
 */

#include <AccelStepper.h>
#define HALFSTEP 8

// Motor pin definitions
#define motorPin1  2     // IN1 on the ULN2003 driver 1
#define motorPin2  3     // IN2 on the ULN2003 driver 1
#define motorPin3  4     // IN3 on the ULN2003 driver 1
#define motorPin4  5     // IN4 on the ULN2003 driver 1

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper
with 28BYJ-48
AccelStepper stepper1(4,2,4,3,5); //(HALFSTEP, motorPin1, motorPin3,
motorPin2, motorPin4);

char *vChar;
uint16_t vInt;
uint16_t vForcedInt;

// read a line of data from serial to a buffer, max bytes allowed = "limit".
// max bytes is 255 because of uint8_t. For larger input, use uint16_t
uint16_t readInt (char *buffer, uint16_t limit)
{
   char c;
   uint16_t ptr = 0;

   while (1) {

       if (Serial.available()) {

           c = Serial.read();

           if ((c == 0x0D) || (c == 0x0A)) { // cr == end of line
               *(buffer + ptr) = 0; // mark end of line
               break; // return char count
           }

           if (c == 0x08) { // backspace

               if (ptr) { // if not at the beginning

                   *(buffer + --ptr) = 0; // null backspaced char
                   //Serial.print ( (char) 0x08); // erase backspaced char
                   //Serial.print ( (char) 0x20); // print a space to erase
                   //Serial.print ( (char) 0x08); // back up to account for
space

               } else {
                   //Serial.print ( (char) 0x07); // ascii bel (beep) if
terminal supports it
               }

           } else { // not a backspace, handle it

               if (ptr < (limit - 1)) { // if not at the end of the line

                   //Serial.print ( (char) c); // echo char
                   *(buffer + ptr++) = c; // put char into buffer

               } else { // at end of line, can't add any more
                   //Serial.print ( (char) 0x07); // ascii bel (beep) if
terminal supports it
               }
           }
       }
   }

   return ptr; // returns how many chars were received
}

void setup() {
  Serial.begin(9600);
}

void loop() {

  vChar = "";

  //First wait to receive an integer (num. degrees from the serial link)
followed by CR to initiate a move
  vInt = readInt(vChar, 360);
  //Serial.print("Int received: "); Serial.println(vInt);

  stepper1.setSpeed(300);

  //(1) Need to calibrate/translate num degrees to stepper value here...
  //stepper1.moveTo(vInt * 2048 / 90);
  //For now, just move by an arbitrary amount
  vForcedInt = vForcedInt + 1000;
  stepper1.moveTo(vForcedInt);

  //Serial.print("Moving to: "); Serial.println(vInt * 2048 / 90);
Serial.println(vForcedInt);
  stepper1.run();

  while (stepper1.distanceToGo() != 0) {
    stepper1.run();
  }

  //Movement complete - pass on the message
  Serial.println("OK");

}


More information about the Blackpool mailing list