Esempio n. 1
0
    def __init__(self,
                 bus=1,
                 device=0,
                 speed=1000000,
                 pin_rst=def_pin_rst,
                 pin_ce=0,
                 pin_irq=def_pin_irq,
                 pin_mode=def_pin_mode):
        self.pin_rst = pin_rst
        self.pin_ce = pin_ce
        self.pin_irq = pin_irq

        self.spi = SPIClass()
        self.spi.open(bus, device)
        self.spi.mode = 0
        self.spi.msh = speed

        if pin_mode is not None:
            GPIO.setmode(pin_mode)
        if pin_rst != 0:
            GPIO.setup(pin_rst, GPIO.OUT)
            GPIO.output(pin_rst, 1)
        GPIO.setup(pin_irq, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(pin_irq,
                              GPIO.FALLING,
                              callback=self.irq_callback)
        if pin_ce != 0:
            GPIO.setup(pin_ce, GPIO.OUT)
            GPIO.output(pin_ce, 1)
        self.init()
Esempio n. 2
0
def test_basic_distance_bcm():
    """Test that float returned with default, positive and negative temps"""
    GPIO.setmode(GPIO.BCM)
    x = Measurement
    basic_reading = x.basic_distance(TRIG_PIN, ECHO_PIN)
    basic_reading2 = x.basic_distance(TRIG_PIN, ECHO_PIN, celsius=10)
    basic_reading3 = x.basic_distance(TRIG_PIN, ECHO_PIN, celsius=0)
    basic_reading4 = x.basic_distance(TRIG_PIN, ECHO_PIN, celsius=-100)
    assert type(basic_reading) == float
    assert type(basic_reading2) == float
    assert type(basic_reading3) == float
    assert type(basic_reading4) == float
    GPIO.cleanup((TRIG_PIN, ECHO_PIN))
Esempio n. 3
0
 def __init__(self):
     self.ce_pin = "P9_15"
     self.irq_pin = "P9_16"
     self.channel = 76
     self.data_rate = NRF24.BR_1MBPS
     self.data_rate_bits = 1000
     self.p_variant = False  # False for RF24L01 and true for RF24L01P
     self.payload_size = 5  # *< Fixed size of payloads
     self.ack_payload_available = False  # *< Whether there is an ack payload waiting
     self.dynamic_payloads_enabled = False  # *< Whether dynamic payloads are enabled.
     self.ack_payload_length = 5  # *< Dynamic size of pending ack payload.
     self.pipe0_reading_address = None  # *< Last address set on pipe 0 for reading.
     self.spidev = None
     self.using_adafruit_bbio_gpio = GPIO.__name__ == "Adafruit_BBIO.GPIO"
     GPIO.setmode(GPIO.BCM)
Esempio n. 4
0
def get_distance():
    GPIO.setmode(GPIO.BCM)
    GPIO.output("P9_23", GPIO.HIGH)
    time.sleep(0.00001)
    GPIO.output("P9_23", GPIO.LOW)
    start = time.time()

    while GPIO.input("P9_25") == 0:
        start = time.time()

    while GPIO.input("P9_25") == 1:
        stop = time.time()

    elapsed = stop - start
    distance = (elapsed * 34300) / 2

    return distance
Esempio n. 5
0
#!/usr/bin/env python
from BBB_WINDMBED import BBB_WINDMBED

import Adafruit_BBIO.GPIO as GPIO
import time
from datetime import datetime

//GPIO.setmode(GPIO.BCM)

#The address should be changed to match the address of the
# sensor. (Common implementations are in README.md)
sensor = BBB_WINDMBED(address=0x52, bus=0)

print "did the sensor thing")

//def handle_interrupt(channel):
    time.sleep(0.003)
//    global sensor
//    if reason == 0x01:
//        print "Just testing 0x01"
//        sensor.raise_noise_floor()
//    elif reason == 0x04:
//        print "Just testing 0x04"
//        sensor.set_mask_disturber(True)
//    elif reason == 0x07:
        now = datetime.now().strftime('%H:%M:%S - %Y/%m/%d')
        distance = sensor.get_distance()
        print "Just testing 0x07"
//        print "It was " + str(distance) + "km away. (%s)" % now
//        print ""
Esempio n. 6
0
#!/usr/bin/env python3
import Adafruit_BBIO.GPIO as GPIO  # import GPIO
from hx711 import HX711  # import the class HX711

try:
    GPIO.setmode(GPIO.BCM)  # set GPIO pin mode to BCM numbering
    # Create an object hx which represents your real hx711 chip
    # Required input parameters are only 'dout_pin' and 'pd_sck_pin'
    hx = HX711(dout_pin=21, pd_sck_pin=20)
    # measure tare and save the value as offset for current channel
    # and gain selected. That means channel A and gain 128
    err = hx.zero()
    # check if successful
    if err:
        raise ValueError('Tare is unsuccessful.')

    reading = hx.get_raw_data_mean()
    if reading:  # always check if you get correct value or only False
        # now the value is close to 0
        print('Data subtracted by offset but still not converted to units:',
              reading)
    else:
        print('invalid data', reading)

    # In order to calculate the conversion ratio to some units, in my case I want grams,
    # you must have known weight.
    input('Put known weight on the scale and then press Enter')
    reading = hx.get_data_mean()
    if reading:
        print('Mean value from HX711 subtracted by offset:', reading)
        known_weight_grams = input(
Esempio n. 7
0
 def init_gpio(self):
     '''Initialize GPIO configuration.'''
     LOG.debug('initializting GPIO configuration')
     GPIO.setmode(GPIO.BCM)
     for pin in [self.pin_red, self.pin_green, self.pin_blue]:
         GPIO.setup(pin, GPIO.OUT, initial=0)
  return p.communicate()[0] # Script pipes back lastId, returned to main


# Called once per day (6:30am by default).
# Invokes weather forecast and sudoku-gfx scripts.
def daily():
  GPIO.output(ledPin, GPIO.HIGH)
  subprocess.call(["python", "forecast.py"])
  subprocess.call(["python", "sudoku-gfx.py"])
  GPIO.output(ledPin, GPIO.LOW)


# Initialization

# Use Broadcom pin numbers (not Raspberry Pi pin numbers) for GPIO
GPIO.setmode(GPIO.BCM)

# Enable LED and button (w/pull-up on latter)
GPIO.setup(ledPin, GPIO.OUT)
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# LED on while working
GPIO.output(ledPin, GPIO.HIGH)

# Processor load is heavy at startup; wait a moment to avoid
# stalling during greeting.
time.sleep(30)

# Show IP address (if network is available)
try:
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#########Author - Sudarshan ###########
#######File Name - Motor_Test_beaglebone.py (tested for beagle bone Black)#########

import Adafruit_BBIO.GPIO as GPIO
from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

Motor1A = P8_7
Motor1B = P8_8
Motor1E = P8_9
Motor2A = P8_10
Motor2B = P8_11
Motor2E = P8_12

GPIO.setup(Motor1A, GPIO.OUT)
GPIO.setup(Motor1B, GPIO.OUT)
GPIO.setup(Motor1E, GPIO.OUT)
GPIO.setup(Motor2A, GPIO.OUT)
GPIO.setup(Motor2B, GPIO.OUT)
GPIO.setup(Motor2E, GPIO.OUT)

left = GPIO.PWM(Motor1E, 100)
right = GPIO.PWM(Motor2E, 100)
left.start(25)
right.start(25)

print "Turning motor on"
GPIO.output(Motor1A, GPIO.LOW)
GPIO.output(Motor1B, GPIO.HIGH)
Esempio n. 10
0
    return p.communicate()[0]  # Script pipes back lastId, returned to main


# Called once per day (6:30am by default).
# Invokes weather forecast and sudoku-gfx scripts.
def daily():
    GPIO.output(ledPin, GPIO.HIGH)
    subprocess.call(["python", "forecast.py"])
    subprocess.call(["python", "sudoku-gfx.py"])
    GPIO.output(ledPin, GPIO.LOW)


# Initialization

# Use Broadcom pin numbers (not Raspberry Pi pin numbers) for GPIO
GPIO.setmode(GPIO.BCM)

# Enable LED and button (w/pull-up on latter)
GPIO.setup(ledPin, GPIO.OUT)
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# LED on while working
GPIO.output(ledPin, GPIO.HIGH)

# Processor load is heavy at startup; wait a moment to avoid
# stalling during greeting.
time.sleep(30)

# Show IP address (if network is available)
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)