Tuesday, January 2, 2018

USB Motorized Focus Adjuster Project


USB Motorized Focus Adjuster
Project Objective:
  • Install motorized focus control for my 8" SCT telescope
  • Adjust motorized focus in person with push buttons
  • Utilize USB to control telescope's focus remotely with a DC motor.
  • The pulse duration should be adjustable.
  • USB should be the only source of power

Background:
  • After adding a motorized filter wheel, the USB focuses is the only missing puzzle in order to control my entire astro-photography imaging equipment remotely.  It is difficult to find right focuser that can fit my 8" SCT telescope from the market without breaking my bank.  Therefore, I decide to build my own motorized focus adjuster.


Hardware List:
  • One Arduino Nano
  • One USB cable for Arduino Nano
  • One pieces two wire phone line
  • One project enclosure box
  • One L293D h-bridge motor driver ic.
  • One 12V/5RPM DC motor
  • Two pieces pulley, 57105K14 from McMaster-CARR.
  • One pieces timing belt, 1679K11 from McMaster-CARR.
  • Two pieces push switches.  
  • Three pieces of 470 ohm resisters.
  • One sheet metal (simple book stand)
  • Option: I find a better timing pulley set from eBay.  
1:4 Timing Pulley Set
Step 1: Setup the pulley system
  • Locate the location for the driver motor and the SCT shaft on the sheet metal.
  • Cut and drill the sheet metal for the 12v motor screw and opening area.
  • Cut and drill the sheet metal for the SCT's shaft and three screw holes.
  • Modify one pulley, and make it fit-able to the SCT shaft with 12.5mm OD 
  • Assembly the focuser on SCT
Engaged Configuration

Disengaged Configuration

Top view of the design



Step 2: Building PCB board
  • Require material:
    • Arduino Nano
    • USB cable
    • L293D
    • Two small capactors
    • Wires and heat shrink tube
    • Phone wire
    • One 470 ohm resistor




Prototyping-1


Prototyping-2



Protected with heat shrink tube


Step 3: Handheld Controller
  • Require material:
    • Two momentary switches 
    • Three 470 ohm resistors
    • Small project box
Wiring the switches
Simple controller schematics. 
Note: A1 need to be pulled up by another 470 ohm resister


Assembled hand held controller



Step 4: Build the Arduino Nano firmware 

// #########################################
// # USB Motorized Focus Adjuster Project  #
// # ------------------------------------- #
// # Author: Samson Yang                   #
// # Date: 01/JAN/2018                     #
// # Version: 1.3                          #
// #                                       #
// # Warring:                              #
// #   High torque motor may damage your   # 
// # telescope. Please use this design with#
// # caution and at your own risk!!        #
// #                                       #
// # Note:                                 #
// #  Enter 0: reset position              #
// #  Enter 1: rotate CW                   #
// #  Enter 2: rotate CCW                  #
// #  Enter 50~10001 update pules time     #
// #  Hand held controler has fix pules    #
// #  Rotation speed is ~1RPM              # 
// #  Rotation resolution is ~15' with 50ms#
// #  Current design has ~ 1000ms backlash # 
// #########################################

// Pins assignment and set deafult value
const int Pin_P = 9;
const int Pin_N = 8;
int pulse_time = 1000;  //unit: ms
long int total_time = 0;

void setup() {
  Serial.begin(9600);
  pinMode(Pin_P, OUTPUT);
  pinMode(Pin_N, OUTPUT);
  Serial.println("USB Focuser is initialized!");
  Serial.println("Version 1.3, 01/JAN/2018");
}

void loop() {   
  //Check 1st button on hanld held controler. 
  //Check 2nd button on hanld held controler. 
  int sensorValue = analogRead(A1);  
  if ((sensorValue >450)*(sensorValue <700)) MCP(Pin_N, 100); //Its typical value is ~510
  if ((sensorValue >300)*(sensorValue <400)) MCP(Pin_P, 100); //Its typical value is ~340

  //Waiting for input from serial port
  while (Serial.available() > 0) {
    int data = Serial.parseInt();
    if (data==0) {total_time=0;Serial.println("Total_time is reset!");} //reset total time
    if (data==1) MCP(Pin_N, pulse_time); //rotate CW
    if (data==2) MCP(Pin_P, pulse_time); //rotate CCW    
    if ((data>49) * (data<10001)) {
      pulse_time=data; //update pulse time
      Serial.println("########################################");
      Serial.print("       New pulse time is ");Serial.print(pulse_time);Serial.println("ms");
      Serial.println("########################################");
     }
  }
}

//Control Motor by Pulse
void MCP(int PIN_NO, int Pulse_Length) {
  //When pin 8 = high, shaft rotate CW
  //When pin 9 = high, shaft rotate CCW
  if (PIN_NO == 8) {total_time=total_time+Pulse_Length;Serial.print("//  CW with ");Serial.print(Pulse_Length);Serial.print("ms.  Adjusting... ");}
  if (PIN_NO == 9) {total_time=total_time-Pulse_Length;Serial.print("** CCW with ");Serial.print(Pulse_Length);Serial.print("ms.  Adjusting... ");}
  digitalWrite(PIN_NO, HIGH);   
  delay(Pulse_Length);                       
  digitalWrite(PIN_NO, LOW);  
  Serial.print("Done! New position is: ");Serial.print(total_time);Serial.println("ms");
}

Demonstration:
  Click on the YouTube link. 




Enjoy it! 


Sunday, March 5, 2017

Arduino to Arduino Communication via Tx/Rx

Arduino to Arduino Communication via Tx/Rx

3/5/2017

Scope: 
  Experience using Tx/Rx to communicate a slave Arduino from the Master Arduino

Setup: 

  • Connect Vcc to Vcc
  • Connect GND to GND
  • Connect Tx to Rx
  • Connect Rx to Tx





Demo:



Master Arduino Code:

/*Master Arduino Code
 * 3/5/17
 Scope: Experience COM communication between Arduino
 Approach: Send a command via Tx/Rx from one Arduino to another Arduino.
 */

void setup() {
  // initialize serial:
  Serial.begin(9600);
  pinMode(9, OUTPUT);
}

void loop() {
  //Turn on LED for 1 sec
  digitalWrite(9, HIGH);
  delay(500);
  digitalWrite(9, LOW);

  //Send instruction via COM
  Serial.print("9 5 200");

  //Wait until above instruction is completed
  delay(3000);
}


Slave Arduino Code:

/* Slave Arduino Code
By Samson Yang 3/5/2017
This is a simple demo of how to use Arduino control another Arduino 'via' Tx/Rx.
*/

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // make the pins outputs:
  pinMode(9, OUTPUT);
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    int Pin = Serial.parseInt();
    int Count = Serial.parseInt();
    int delay_time = Serial.parseInt();      
    if((Pin==9)){LED_Blinking(Pin,Count,delay_time);}
  }    
}

//Control LED blinking on pin 9
void LED_Blinking(int Pin,int Count,int delay_time){  
  //Blank LED
  for (int i = 0;i<Count;i++){
    digitalWrite(Pin, HIGH);delay(delay_time/2);digitalWrite(Pin, LOW);delay(delay_time/2);
  }
}





Saturday, March 4, 2017

Use PC to Control or Read via Arduino

Use PC to Control or Read via Arduino

3/4/2017

Object: 
  Experience PC communicate with Arduino via COM.  Use command code to control LED on the Arduino, and read photo sensor value from Arduino too.  Interrupt the process as needed with a command code.

Arduino Setup:

  • Connect D9 ~ D13 with LED.
  • Connect Photo resistor to A1
  • Connect Vcc and GND




Demo 1 (control LED):

  • Below example shows control of control LED at pin 9, blanking 5 times with 200ms cycle time.
  • Command code: 9 5 200



Demo 2 (Read photo sensor value):

  • Read the photo sensor value from A1 10 time with 200ms cycle time.
  • Command code: 1 10 200





Arduino Code:

/*
By Samson Yang 3/4/2017
This is a simple demo of how to use PC to control or read Arduino 'via' Arduino.

Arduino Setup:
Connect LED with current resistor (say 500ohm) to pint 8, and repeat the same with pin 9, to 13.
Connect 10K ohm resistor to photo sensor, and connect A1 to photo sensor.

Operation instruction:
Control LED 9, blanking 20 time with 200ms cycle time
9 20 200

Read the photo sensor value from A1 25 time with 500ms cycle time.
1 25 500

Enter 999 to interrupt the process if needed.
*/


void setup() {
  // initialize serial:
  Serial.begin(9600);
  // make the pins outputs:
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  Serial.println();
  Serial.print("Enter your command code:");
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    // look for the next valid integer in the incoming serial stream:
    int Pin = Serial.parseInt();
    int Count = Serial.parseInt();
    int delay_time = Serial.parseInt();
    if((Pin>7)*(Pin<14)|(Pin==1)){
      Serial.print("Pin=");Serial.print(Pin, DEC);
      Serial.print(", Count=");Serial.print(Count, DEC);
      Serial.print(", Time=");Serial.println(delay_time, DEC);Serial.println();
      if((Pin>7)*(Pin<14)){LED_Blinking(Pin,Count,delay_time);}
      if(Pin==1){Photo_Reading(Pin,Count,delay_time);}
    }
  }
}

//Control LED blinking on pin 8 ~ 13
void LED_Blinking(int Pin,int Count,int delay_time){
  //Serial.println("Control LED blinking:");
  for (int i = 0;i<Count;i++){
    //Check for Interuption command, 999
    if(Serial.available() > 0){if(Serial.parseInt()==999){Serial.println("Interuptted");Count=-1;}}
    //Blainking LED
    digitalWrite(Pin, HIGH);delay(delay_time/2);digitalWrite(Pin, LOW);delay(delay_time/2);
  }
}

//Reading photo sensor value from A1
void Photo_Reading(int Pin,int Count,int delay_time){
  Serial.println("Reading photo sensor value:");
  for (int i = 0;i<Count;i++){
    //Check for Interuption command, 999
    if(Serial.available() > 0){if(Serial.parseInt()==999){Serial.println("Interuptted");Count=-1;}}
    //Read and send out the photo sensor value
    Serial.print("Photo Sensor=");Serial.println(analogRead(A1), DEC);delay(delay_time);        
  }
}