def __init__(self, trigger, echo):
     self.trigPin = trigger
     self.echoPin = echo
     GPIO.output(trigger, GPIO.LOW)  # attempt to pre-set it low before enabling output
     GPIO.setup(trigger, GPIO.OUT)
     GPIO.output(trigger, GPIO.LOW)
     GPIO.setup(echo, GPIO.IN)
Beispiel #2
0
# and the counter counts either UP or DOWN depending on the quad pin.
# Commonly used for shaft/wheel encoders where 2 sensors are adjusted to be "out of phase",
# allowing rotation direction to be sensed.

# Using pins as Intcounter, or its quadencoder variant, does not preclude any ordinary use of those pins.
# Here we set them as outputs, and blink then as fast as we easily can.
# On one pair, the main pin "leads", on the other encoder the quad pin leads.
# So one encoder counts up, the other down.  (16bit unsigned)

import time

import virtGPIO as GPIO

counter2 = GPIO.Intcounter(2, GPIO.Intcounter.QUAD)
# Quad encoder oper
GPIO.setup(2,GPIO.OUT)
GPIO.setup(4,GPIO.OUT)

counter3 = GPIO.Intcounter(3, GPIO.Intcounter.QUAD)
GPIO.setup(3,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
print()
print ("Initial counter readings: "),
print ( counter2.read())
print ("We will now count one UP and one DOWN.")
print ("1000 pulses. (Quad encoder counts at both rising and falling edges) ...")
for k in range(1,2001):
    GPIO.output(4,(k&1))   # quad pin leads on first counter
    GPIO.output(2,(k&1))

    GPIO.output(3,(k&1))   # main pin leads on other
Beispiel #3
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import time

import virtGPIO as GPIO

led = 6  # put a LED on pin 6

# Note object GPIO.AVR for MCU register access is pre-defined for us in virtGPIO.py
# and pre-defined register names are in virtGPIO.py

GPIO.setup(led, GPIO.OUT)

c = 0

while True:
    c += 1
    GPIO.output(led, c & 1)  # LED blink
    print("pin 6 input by raw atmega238 access %d " %
          ((GPIO.AVR.read8(GPIO.AVR.PIND) & 0x40) > 0))
    # Guided by 328 MCU manual, we read 8-bit register "PIND" and select bit 6
    # See  <http://www.atmel.com/Images/doc8161.pdf> page 93
    # and <http://arduino.cc/en/Hacking/PinMapping168>

    time.sleep(2)

# As another example (example only),
# the lines below show the virtGPIO.py internal implementation of analogHiSpeed(),
# which changes the clock prescaler of ADC convertor in the 328.
# Refer 328 MCU manual, pages 253 and 264.
print (GPIO.baudlist)

print ("Serial baudrate used")
print (GPIO.Serial.baudrate)
print ("Serial port used")
print (GPIO.Serial.port)

GPIO.printCompileDate()   # arduino compile/upload

print ("Observe that only pin13 is initially 'assigned'. The activity LED pin...")
GPIO.readFreePins()
time.sleep(5)

led = 9
print ("We set pin %d as OUTPUT. That does not assign the pin for any special use!" % led)
GPIO.setup(led,GPIO.OUT)
time.sleep(4)

print ("Turning off the 'activity LED'. That should release pin13")
GPIO.setActivityLed(0)
time.sleep(4)

print ("Any I2C devices detected??")
i2c = GPIO.I2C()
i2c.detect()    # Displays the addresses of any I2C devices connected
print ("But starting I2C object does assign A4 and A5")
time.sleep(5)

print ("Assigning pin8 for infrared receiver")
IR = GPIO.InfraRedRx(8)
time.sleep(4)
Beispiel #5
0
#for controlling arduino
import virtGPIO as GPIO
#import the pydicom library to edit the DICOM file elements
import dicom
#import pexpect to interact with C++ camera application
import pexpect

#using the arduino.
#connect the LED in the following fashion:
#white LED - ground/resistor to GND and positive to D6 and D7
#IR LED - ground / resistor to GND and positive to D5
ir = 5
white1 = 6
white2 = 7
white3 = 8
GPIO.setup(ir, GPIO.OUT)  #IR Led
GPIO.setup(white1, GPIO.OUT)  #White1 Led
GPIO.setup(white2, GPIO.OUT)  #White2 Led
GPIO.setup(white3, GPIO.OUT)  #White3 Led

#turn off autorepeat to remove duplicate images
os.system('xset r off')

#starting the main user interface
root = Tk()
#for large HD screen use below
root.geometry('400x420+900+1')

root.title("OICO Fundus Camera")
root.wm_iconbitmap('@' + 'logo-1.xbm')
#make the GUI always in foreground