Example #1
0
#10 DOF
sensor = BMP085.BMP085()

# LUX

# Software SPI configuration:
CLK = 18
MISO = 23
MOSI = 24
CS = 25

#spi = spidev.SpiDev()
#spi.open(0, 0)

# Initialize MCP23017 device using its default 0x20 I2C address.
gpio = MCP.MCP23017()

# Initialize the LCD using the pins
lcd = LCD.Adafruit_CharLCD(lcd_rs,
                           lcd_en,
                           lcd_d4,
                           lcd_d5,
                           lcd_d6,
                           lcd_d7,
                           lcd_columns,
                           lcd_rows,
                           lcd_bl,
                           gpio=gpio)
# Initialize the MCP3008
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
Example #2
0
File: read.py Project: dfijma/p1
# Define MCP pins connected to the LCD.
lcd_rs = 1
lcd_en = 2
lcd_d4 = 3
lcd_d5 = 4
lcd_d6 = 5
lcd_d7 = 6
lcd_back = 7

# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows = 2

# get lcd via MCP i2c io extender
gpio = MCP.MCP23008(0x20, busnum=1)
lcd = LCD.Adafruit_CharLCD(lcd_rs,
                           lcd_en,
                           lcd_d4,
                           lcd_d5,
                           lcd_d6,
                           lcd_d7,
                           lcd_columns,
                           lcd_rows,
                           lcd_back,
                           gpio=gpio,
                           invert_polarity=False)

client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
client.bind(('', 37020))
Example #3
0
#!/usr/bin/python3
import time

import Adafruit_GPIO as GPIO
import Adafruit_GPIO.MCP230xx as MCP230xx

mcp = MCP230xx.MCP23017(
)  # This assumes the MCP23017 is at the default address 0x20, if not pass in an argument with the actual address in hex.

# Setup pin 1 as an output and pin 2 as an input, very similar to RPi.GPIO library.
mcp.setup(0, GPIO.OUT)
mcp.setup(1, GPIO.OUT)
mcp.setup(2, GPIO.OUT)
mcp.setup(3, GPIO.OUT)
mcp.setup(4, GPIO.OUT)
mcp.setup(5, GPIO.OUT)
mcp.setup(6, GPIO.OUT)
mcp.setup(7, GPIO.OUT)
mcp.setup(8, GPIO.OUT)
mcp.setup(9, GPIO.OUT)
mcp.setup(10, GPIO.OUT)
mcp.setup(11, GPIO.OUT)
mcp.setup(12, GPIO.OUT)

# Loop forever blinking pin 1 high and low every second.
mcp.output(0, GPIO.HIGH)
time.sleep(1.0)
mcp.output(0, GPIO.LOW)
time.sleep(5.0)
Example #4
0
 def __init__(self):
     self.buttons = mcs.MCP23008(i2c_address)
     for i in range(8):
         self.buttons.setup(i, GPIO.IN)
Example #5
0
### Define MCP pins connected to LCD
lcd_rs = 6
lcd_en = 4
lcd_d4 = 3
lcd_d5 = 2
lcd_d6 = 1
lcd_d7 = 0
lcd_backlight = None

### Define LCD type
lcd_columns = 20
lcd_rows = 4

### Initialize MCP23017 for LCD
gpiomcp = MCP.MCP23017(0x20, busnum=1)

### Initialize LCD panel parameters
lcd = LCD.Adafruit_CharLCD(lcd_rs,
                           lcd_en,
                           lcd_d4,
                           lcd_d5,
                           lcd_d6,
                           lcd_d7,
                           lcd_columns,
                           lcd_rows,
                           lcd_backlight,
                           gpio=gpiomcp)
lcd.show_cursor(False)
lcd.blink(False)
lcd.clear()
Example #6
0
##
# Maker's Digest
#
# MCP23017 GPIO Expander Example
#
# Dont forget to install the libraries! See README.md for details.
##
from time import sleep  # Import sleep from time
import Adafruit_GPIO.MCP230xx as MCP230XX  # Import Adafruit MCP23017 Library

mcp = MCP230XX.MCP23017(address=0x21)  # Instantiate mcp object
REFRESH_RATE = 30.0  # Set delay of 1/4 second
quit_pin = 9
prev_low = {
    0: False,
    1: False,
    2: False,
    3: False,
    4: False,
    5: False,
    6: False,
    7: False,
    8: False,
    9: False,
    10: False,
    11: False,
    12: False,
    13: False,
    14: False,
    15: False,
    16: False
##
# Maker's Digest
#
# MCP23017 GPIO Expander Example
#
# Dont forget to install the libraries! See README.md for details.
##
from time import sleep  # Import sleep from time
import Adafruit_GPIO.MCP230xx as MCP230XX  # Import Adafruit MCP23017 Library

mcp = MCP230XX.MCP23017()  # Instantiate mcp object
dly = .25  # Set delay of 1/4 second

# Setup Outputs.
# We loop through all 16 GPIO to set them as GPIO.OUT, which
# needs to be referenced as MCP230XX.GPIO.OUT.
#
# If you are only using one or two of the GPIO pins on the
# mcp23017, you can set them up for outputs individually as:
# mcp.setup(0, MCP230XX.GPIO.OUT)
# OR
# mcp.setup(0, MCP230XX.GPIO.IN)
#
# See Adafruit_Python_GPIO on github for more details on
# using this library.
for x in range(0, 16):
    mcp.setup(x, MCP230XX.GPIO.OUT)


# Main Program
# Loop through all 16 GPIO to set high, then low.
Example #8
0
import sys
import time

import Adafruit_GPIO.MCP230xx as MCP
import Adafruit_GPIO as GPIO

mcp = MCP.MCP23017()
mcp.setup(0, GPIO.OUT)

relayName = 0

try:

    while (True):
        mcp.output(relayName, True)
        time.sleep(1)
        mcp.output(relayName, False)
        time.sleep(1)

except KeyboardInterrupt:
    mcp.output(relayName, False)
    print "\nScript finalizado."
    sys.exit(0)
Example #9
0
        while curr < max:
            pwm.set_pwm(channel, 0, curr)
            pwm.set_pwm(channel2, 0, curr)
            curr += step
            time.sleep(t)
    else:
        curr = max
        while curr > min:
            pwm.set_pwm(channel, 0, curr)
            pwm.set_pwm(channel2, 0, curr)
            curr -= step
            time.sleep(t)


if __name__ == '__main__':
    mcp = MCP.MCP23017(
        0x24)  # MCP23017 creating an object of the class called MCP
    pwm = PWM.PCA9685()
    pwm.set_pwm_freq(500)
    min = 409
    max = 4095
    Flag = 0  #Motion not  detected
    counter = 0

    lcd_columns = 16
    lcd_rows = 2
    lcd = LCD.Adafruit_CharLCDBackpack()
    lcd.set_backlight(0)
    lcd.clear()

    detected = False
Example #10
0
        drawTarget()
        disp.image(image)
        disp.display()


def shoot():
    print('%s %s' % (posShipX+3, posShipY))
    bullets.append({'x': posShipX+3, 'y': posShipY})


def createTargets():
    pass


if __name__ == '__main__':
    mcpi2c = MCP.MCP23017(0x20, busnum=1)
    # use pin 0 as OUTPUT, 1 as INPUT pin
    mcpi2c.setup(0, MCP.GPIO.OUT)
    mcpi2c.setup(1, MCP.GPIO.IN)
    print('start')

    initDisp()
    drawShip()

    start_new_thread(input_thread, (mcpi2c,))

    while 1:
        try:
            # Quick example: DONT DO THIS:
            time.sleep(5)
        except KeyboardInterrupt:
Example #11
0
#https://www.youtube.com/watch?v=MCGeeqKfv7Q
#
import Adafruit_DHT
import BMP085
from time import sleep
import datetime
from utilities import *
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
import Adafruit_GPIO as GPIO
from Adafruit_GPIO import MCP230xx
from time import sleep

mcp = MCP230xx.MCP23017(busnum=1, address=0x20)  #io expander
mcp.setup(0, GPIO.IN)

RST = None
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

disp.begin()
disp.clear()
disp.display()
width = disp.width
height = disp.height
image = Image.new('1', (width, height))