diff --git a/gertboard_example1.jpg b/gertboard_example1.jpg new file mode 100644 index 0000000..c55b7db Binary files /dev/null and b/gertboard_example1.jpg differ diff --git a/gertboard_pump_code.py b/gertboard_pump_code.py new file mode 100644 index 0000000..ca7a479 --- /dev/null +++ b/gertboard_pump_code.py @@ -0,0 +1,78 @@ +#!/usr/bin/python2.7 +from __future__ import print_function +import wiringpi +import pygame, sys, os +from pygame.locals import * +from time import sleep + +class motor_handler(): + def __init__(self): + wiringpi.wiringPiSetupGpio() # initialise wiringpi GPIO + wiringpi.pinMode(18,2) + wiringpi.pinMode(17,1) + wiringpi.digitalWrite(17,0) + wiringpi.pwmWrite(18,0) + def motor_loop(self, stepSize,motorHold): + wiringpi.pwmWrite(18,stepSize) # pwmWrite(pinNum,StepSize) + sleep(motorHold) + wiringpi.pwmWrite(18,0) + def reset_motor(self): + wiringpi.pwmWrite(18,0) + wiringpi.digitalWrite(18, 0) # ports 17 & 18 off + wiringpi.digitalWrite(17, 0) + wiringpi.pinMode(17,0) # set ports back to input mode + wiringpi.pinMode(18,0) + +# Displays pump # every time the pump is run. +class info_text_handler(): + def __init__(self): + self.trialNumber = 0 + self.fontObj = pygame.font.Font(None,24) + def trial_increment(self): + self.trialNumber += 1 + def render_text(self, colorName, winSurface): + msg = 'Trial ' + str(self.trialNumber) + msgSurface = self.fontObj.render(msg, False, colorName) + msgRect = msgSurface.get_rect() + msgRect.bottomright = (200,100) + winSurface.blit(msgSurface, msgRect) + def trial_reset(self): + self.trialNumber = 0 + +def main(): + pygame.init() + pygame.mouse.set_visible(0) + + fpsClock = pygame.time.Clock() + winSurface = pygame.display.set_mode((400,200)) + pygame.display.set_caption('Gertboard Pump') + + red = pygame.Color(255,0,0) + black = pygame.Color(0,0,0) + winSurface.fill(black) + + infotext = info_text_handler() + motor = motor_handler() + + while True: + for event in pygame.event.get(): + if event.type == QUIT: + motor.reset_motor() + pygame.quit() + sys.exit() + elif event.type == KEYDOWN: + if event.key == K_w: # press "w" to run the pump + winSurface.fill(black) + infotext.trial_increment() # increment the trial number + infotext.render_text(red, winSurface) + pygame.display.update() + motor.motor_loop(800,1) # motor.motor_loop(size of the step, seconds to run the motor) + if event.key == K_ESCAPE or event.key == K_q: # ESC to quit program + motor.reset_motor() + pygame.event.post(pygame.event.Event(QUIT)) + + pygame.display.update() + msSince = fpsClock.tick(30) + +# calls the 'main' function when this script is executed +if __name__ == '__main__': main() diff --git a/ps pump equipment list and notes.txt b/ps pump equipment list and notes.txt index 9797860..8d3fd31 100644 --- a/ps pump equipment list and notes.txt +++ b/ps pump equipment list and notes.txt @@ -47,17 +47,30 @@ Connect your DC power adapter to the motor shield Vs / Gnd pins, and connect the | Gnd -The physical assembly was done using odd metal pieces I had laying around. I'm not particularly proud of it, but it works fine (it doesn't really need a physical assembly to be functional). - - +The physical assembly was done using odd metal pieces I had laying around. I'm not particularly proud of it, but it works fine (it doesn't really need a physical assembly to be functional). See pictures for reference. ---------------------------------------------------------------- -----------------RASPBERRY PI/GERTBOARD VERSION----------------- ---------------------------------------------------------------- -A gertboard is overkill for this, but again, I already had it sitting around. :) I used a raspberry pi model B, with a pre-assembled gertboard to drive the motor. If you go the gertboard route, their manual is valuable: [ ]. - - +A gertboard is overkill for this, but again, I already had it sitting around. :) I used a raspberry pi model B, with a pre-assembled gertboard to drive the motor. If you go the gertboard route, their manual is valuable: [ http://www.element14.com/community/docs/DOC-51727/l/assembled-gertboard-user-manual-with-schematics ]. + +0. Connect your Gertboard to your Raspberry Pi. +1. Add one jumper wire between Gertboard pins (see pictures for reference): GP17 <-> MOTB +2. Add another jumper wire between Gertboard pins: GP18 <-> MOTA +3. Connect pump motor (+) to screw terminal MOTA and pump motor (-) to screw terminal MOTB. +4. Connect the positive lead from your 12VDC adapter to screw terminal MOT+ and neutral to screw terminal ground. +5a. Install wiringPi either w/apt-get from the command line: +>> sudo apt-get update +>> sudo apt-get install python-dev python-pip +>>sudo pip install wiringpi +5b. Or install wiringPi from the git repository: +>> sudo apt-get install git-core +>> git clone git://git.drogon.net/wiringPi +>> cd wiringPi +>> ./build +6. Play with the other Gertboard examples (including motor ones) if you are so inclined: +>> get http://raspi.tv/download/GB_Python.zip ---------------------------------------------------------------- --------------------------GENERAL NOTES-------------------------