Nikhita GanglaCathy Wicks
Published © GPL3+

Mini AC Unit with PocketBeagle® & Mikro Click Boards™

Make a mini AC unit to keep you cool! Add MikroElektronika DC Motor & Weather Click Boards to a BeagleBoard. org® PocketBeagle®.

BeginnerFull instructions provided2 hours1,317

Things used in this project

Hardware components

PocketBeagle
BeagleBoard.org PocketBeagle
×1
MikroElektronika Weather Click
×1
MikroElektronika DC Motor Click
×1
Snap Circuits 6SCM1 Motor
×1
Snap Circuits 6SCM1F Fan
×1
Battery, 1.2 V
Battery, 1.2 V
×6
Hook Up Wire Kit, 22 AWG
Hook Up Wire Kit, 22 AWG
×1

Story

Read more

Code

TempSensor directory

Python
Drag and drop zip folder into /var/lib/cloud9 directory, and then unzip
No preview (download only).

DC Motor Driver

Python
Drag and drop into /var/lib/cloud9 directory
"""
--------------------------------------------------------------------------
MikroElectronica DC Motor Click Driver
--------------------------------------------------------------------------
License:   
Copyright 2019, Octavo Systems, LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this 
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------
Software API:

  Change direction and speed of motor on MikroElectronica DC Motor Click 
  
--------------------------------------------------------------------------

"""


import os
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM1


# set direction constants for select2
FORWARD  = 0
REVERSE  = 1

# set direction constants for select1
MODE0    = 0
MODE1    = 1

# set minimum and mazimum thresholds for PWM
PWM_MIN  = 0
PWM_MAX  = 100


class DC_Motor():
    
    def __init__(self):
        self.select1 = MODE0
        self.select2 = FORWARD
        self.PWM     = PWM_MIN
        
        # Pin configuration
        os.system("config-pin P1_2 gpio")       # nsleep
        os.system("config-pin P1_4 gpio")       # select1
        os.system("config-pin P1_6 gpio")       # select2
        os.system("config-pin P2_1 pwm")        # pwm       
        os.system("config-pin P2_3 gpio")       # fault
 
        # initialize GPIO
        # Set up pins as inputs or outputs
        GPIO.setup("P1_2", GPIO.OUT)            # P1.2 is output
        GPIO.setup("P1_4", GPIO.OUT)            # P1.4 is output
        GPIO.setup("P1_6", GPIO.OUT)            # P1.6 is output
        GPIO.setup("P2_3", GPIO.IN)             # P2.3 is input
        
        # set GPIO output pins to default values
        GPIO.output("P1_2", 1)
        GPIO.output("P1_4", MODE0)
        GPIO.output("P1_6", FORWARD)
        
        # initialize PWM
        # Set up and start given PWM channel
        PWM1.start("P2_1", PWM_MIN)
        
    # End def
  
    # set direction of turning
    def set_direction(self, direction):
        # See datasheet for table  

        if select1 == MODE0:
            self.select2 = direction
            GPIO.output("P1_6", direction)
        else:
            self.select2 = ((~direction) & 0x1)
            GPIO.output("P1_6", ((~direction) & 0x1))
            
    # End def       
    
    
      # set speed of turning    
    def set_speed(self, speed):
        
        # only allow speeds between 0 and 100
        if ((speed >= PWM_MIN) and (speed <= PWM_MAX)):
           
            # new speed is only set when different from current speed
            if ((self.PWM == 0) and (speed > 0)): 
                self.PWM = speed    
                PWM1.start("P2_1", speed)
                
            elif ((self.PWM > 0) and (speed == 0)):
                self.PWM = 0
                PWM1.stop("P2_1")
            
            
        else:
            print("ERROR in speed")
        
    # End def
    
    
    def get_speed(self):
        return self.PWM
        
    # End def
              
        
    def cleanup(self):
        PWM1.cleanup()
        
    # End def  

Credits

Nikhita Gangla

Nikhita Gangla

2 projects • 1 follower
Cathy Wicks

Cathy Wicks

19 projects • 22 followers
Beagleboard.org fan

Comments