Jump to content


Photo

Arduino based - Mewlon focuser

UNO Rev3 Arduino Focuser Motor MosFET Relay Python wxpython

  • Please log in to reply
3 replies to this topic

#1 Neil

Neil

    Administrator

  • Administrators
  • 1,493 posts

Posted 05 February 2014 - 07:03 PM

Here are the images of my new and fully functional Mewlon Focuser!

 

After a lot of research and planning for the further I decided to use a 100vdc 3amp N-Channel MosFET for my application as you can see in the images attached here. Why you might ask? Well the arduino outputs can only drive about 20mA which isn't enough to drive any serious equipment. 

 

  • A transistor requires biasing based upon the Hfe and may still need to be laddered or used in a Darlington pare etc...
  • Read switches would would directly but its a mechanic component prone to failure

I know that Im not driving any heavy loads now, however, I plan to extend this project to my observatory to automate it and therefore wanted a universal solution that could easily be scaled up to drive heavier motors etc...

 

The solution is broken down as follows;

  1. Arduino UNO 3 microcontroller
  2. 2x N-Channel MosFET that only need a logic signal with no biasing on the gate
  3. Python and wxpython to create a cross platform application to control the UNO3 micro-controller
  4. Arduino sketch to respond to the applications commands

91015-pic.jpg

 

Thats it, well I still obviously need a project box to mount it all in, however, it worked perfectly last night and allowed me to more precisely focus the Mewlon without disturbing it...

 

Mewlon_Focusrer_1.jpg

 

Mewlon_Focusrer_3.jpg

 

Mewlon_Focusrer_4.jpg

 

I had to used relays for the final output since my Mewlon has a polarity sensitive circuit to drive the motor.

 

I'll post the programs later for the member here to access.

 

 

 

Clear Skies

 

 

 

Neil.



#2 Neil

Neil

    Administrator

  • Administrators
  • 1,493 posts

Posted 05 February 2014 - 08:56 PM

Here is a video explaining everything etc...

 

http://youtu.be/ftFSm_zkgDo

 

Clear Skies

 

 

Neil.



#3 Neil

Neil

    Administrator

  • Administrators
  • 1,493 posts

Posted 11 February 2014 - 08:20 PM

Heres the python code for the controller program.

 

#!/usr/bin/python
 
# Author Neil Hankey
# Date 01/02/2014
 
# Mewlon focuser
 
import wx
import os
import serial
from serial.tools import list_ports
 
class ComPorts():
 
    Ports = []
    
    if os.name == 'nt':
        # windows
        for i in range(256):
            try:
                s = serial.Serial(i)
                s.close()
                Ports.append('COM' + str(i + 1))
            except serial.SerialException:
                pass
    else:
        # unix
        for port in list_ports.comports():
            Ports.append(port[0])
 
    #print Ports
    
 
 
class Focuser(wx.Frame):
    def __init__(self, parent, title):
        super(Focuser, self).__init__(parent, title=title, size=(500, 300))
 
        panel = wx.Panel(self,-1, style=wx.SUNKEN_BORDER)
 
        BoxSizer1 = wx.BoxSizer(wx.VERTICAL)
        BoxSizer2 = wx.BoxSizer(wx.HORIZONTAL)
        BoxSizer3 = wx.BoxSizer(wx.HORIZONTAL)
        BoxSizer4 = wx.BoxSizer(wx.HORIZONTAL)
        
 
        ComPort = wx.Choice(panel, -1, size = (150,40), choices = ComPorts().Ports, style = 0)
        self.Bind(wx.EVT_CHOICE, self.ReadComPort, ComPort)
        ComPort.SetSelection(0)
        
        Connect = wx.Button(panel, -1, "Connect", size = (100,40))
        self.Bind(wx.EVT_BUTTON, self.ConnectSerial, Connect)
        
        Disconnect = wx.Button(panel, -1, "Disconnect", size = (100,40))
        self.Bind(wx.EVT_BUTTON, self.DisconnectSerial, Disconnect)
 
        BoxSizer2.Add(ComPort,2, wx.EXPAND | wx.ALL, 10)
        BoxSizer2.Add(Connect,1, wx.EXPAND | wx.ALL, 10)
        BoxSizer2.Add(Disconnect,1, wx.EXPAND | wx.ALL, 10)
 
        self.f_delay = ["200","300","400","500","1000", "1500", "3000"]
 
        label1 = wx.StaticText(panel, -1, "               Delay :" , wx.Point(15, 30))
        label2 = wx.StaticText(panel, -1, "mSec" , wx.Point(15, 30))
        FocusDelay = wx.Choice(panel, -1, size = (150,40), choices = self.f_delay, style = 0)
        ComPort.SetSelection(2)
        self.Bind(wx.EVT_CHOICE, self.ReadFocusDelay, FocusDelay)
        
 
        BoxSizer3.Add(label1,1, wx.EXPAND | wx.TOP, 25)
        BoxSizer3.Add(FocusDelay,2, wx.EXPAND | wx.ALL, 10)
        BoxSizer3.Add(label2,1, wx.EXPAND | wx.TOP, 25)
        
        
        In = wx.Button(panel, -1, "Focus-IN", size = (100,40))
        self.Bind(wx.EVT_BUTTON, self.FocuserIN, In)
        
        Out = wx.Button(panel, -1, "Focus-OUT", size = (100,40))
        self.Bind(wx.EVT_BUTTON, self.FocuserOUT, Out)
 
        BoxSizer4.Add(In,1, wx.EXPAND | wx.ALL, 10)
        BoxSizer4.Add(Out,1, wx.EXPAND | wx.ALL, 10)
 
        BoxSizer1.Add(BoxSizer2,1,wx.EXPAND | wx.ALL, 10)
        BoxSizer1.Add(BoxSizer3,1,wx.EXPAND | wx.ALL, 10)
        BoxSizer1.Add(BoxSizer4,1,wx.EXPAND | wx.ALL, 10)
        
 
        self.statusBar = self.CreateStatusBar()
 
        panel.SetAutoLayout(True)
        panel.SetSizer(BoxSizer1)
        panel.Layout()
        
        self.Centre()
        self.Show()
 
    device = 0
    delay = "300"
    ser = ''
 
    def ReadComPort(self, Evt):
        Focuser.device = Evt.GetSelection()
        #print Focuser.device
 
    def ConnectSerial(self, Evt):
        # Port, Baud, Parity, Stop, Data
        Focuser.ser = serial.Serial(port = ComPorts.Ports[Focuser.device], baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS, timeout=1)
        self.statusBar.SetStatusText("Connected: " + str(ComPorts.Ports[Focuser.device]))
 
    def DisconnectSerial(self, Evt):
        Focuser.ser.close()
        self.statusBar.SetStatusText(str(ComPorts.Ports[Focuser.device]) + " :Disconnected")
 
    def ReadFocusDelay(self, Evt):
        Focuser.delay = Evt.GetSelection()
        Focuser.delay = self.f_delay[Focuser.delay]
                       
 
    def FocuserIN(self,Evt):
        try:
            Focuser.ser.write(Focuser.delay)
            Focuser.ser.write('FIN\n')# End the string with a Newline
        except serial.SerialException:
            pass
 
    def FocuserOUT(self, Evt):
        try:
            Focuser.ser.write(Focuser.delay)
            Focuser.ser.write('FOUT\n')# End the string with a Newline
        except serial.SerialException:
            pass
        
 
 
if __name__ == '__main__':
 
    #p = ComPorts()
    #print p.Ports
  
    app = wx.App()
    Focuser(None, title='Mewlon Focuser')
    app.MainLoop()
 
I'll post up the Arduino sketch next for though who are interested. If you would like to receive the actual python file just contact me and let me know.
 
Clear Skies
 
 
Neil.


#4 Neil

Neil

    Administrator

  • Administrators
  • 1,493 posts

Posted 11 February 2014 - 08:32 PM

Here is the Arduino sketch for the UNO R3 board, its quite simple really.

 

 
/*
This Arduino sketch was put together by NeilHankey in January 2014 to 
control the focuser of the Takahashi Mewlon telescope remotely.
*/
void setup() {
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  digitalWrite(3,LOW);
  digitalWrite(5,LOW);
  Serial.begin(9600,SERIAL_8N1);
}
 
void loop() {
  String Command = "";
  String Number = "";
  
  if (Serial.available() > 0) {
    
    while(Serial.available() > 0){
      char c = Serial.read();
      delay(25); //This is needed to allow the serial data to come in before the micro processes it!
      if(c != '\n' && c >= 65 && c <=90 || c >= 97 && c <= 122){
        Command += c;
      }
      else if(c != '\n' && c >= 48 && c <=57){
        Number += c;
      }
      else
        break;
      }
      Serial.print(Command);
      
      if(Command.equals("FOUT")){
        focusOUT(Number.toInt());}
        
      if(Command == "FIN"){
        focusIN(Number.toInt());}
       
        Serial.println(Command);
        Serial.println(Number);
  }
  
}
 
void focusIN(int d)
{
  digitalWrite(3,HIGH);
  delay(d);
  digitalWrite(3,LOW);
  //Serial.println("Hello");
}
 
void focusOUT(int d)
{
  digitalWrite(5,HIGH);
  delay(d);
  digitalWrite(5,LOW);
}
  
 
Again if you would like to receive the actual sketch file just let me know.
 
With this code and hardware you can pulse control any simple DC motor to enable more precise focus control. All the above has been tested with VISTA and Windows 7 which are the only Windows environments that I have access to.
 
Clear Skies
 
 
Neil.






Also tagged with one or more of these keywords: UNO Rev3, Arduino, Focuser, Motor, MosFET, Relay, Python, wxpython