def setup_gpio(): import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) pins = [4, 5, 6, 7, 12, 13, 17, 18, 19, 22, 23 ] for pin in pins: print('pin is ', pin) GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def __init__(self,dc=13,rst=24,back_light=5,spi_port=0,spi_device=1,fonts_dir=None,resolution = (320,240)): self.screen_resolution =resolution self.DC = dc self.RST = rst self.SPI_PORT = spi_port self.SPI_DEVICE = spi_device self.BACK_LIGHT = back_light GPIO.setmode(GPIO.BCM) GPIO.setup(self.BACK_LIGHT, GPIO.OUT) self.disp = TFT.ILI9341(self.DC, rst=self.RST, spi=SPI.SpiDev(self.SPI_PORT, self.SPI_DEVICE, max_speed_hz=64000000)) self.disp.begin() # Clear the display to a red background. # Can pass any tuple of red, green, blue values (from 0 to 255 each). self.font_size = 35 if fonts_dir == None: self.font = ImageFont.load_default() else: self.font = ImageFont.truetype(fonts_dir + "basic.ttf", self.font_size) self.draw = self.disp.draw()
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from PIL import Image import ST7735 as TFT import Adafruit_GPIO as GPIO import Adafruit_GPIO.SPI as SPI import qrcode from nomorepass.core import NoMorePass from uuid import getnode as get_mac import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(17, GPIO.OUT) GPIO.setup(18, GPIO.OUT) GPIO.output(17,True) isopen = False opencnt = 0 mac = get_mac() macaddr = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2)) WIDTH = 128 HEIGHT = 160 SPEED_HZ = 4000000
lcd_columns = 16 lcd_rows = 2 # Initialize the LCD using the pins above. #lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, #lcd_columns, lcd_rows, lcd_backlight,False) # Backlight pwm separately, is not supported by Adafruit lcd = Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows) # Print a two line message lcd.message('Hello\nworld!') #GPIO.setmode(GPIO.BOARD) GPIO.setup(lcd_backlight, GPIO.OUT) # set frequency p = GPIO.PWM(12, 400) # Start with duty cycle (percentage) p.start(100) # set duty cycle #p.ChangeDutyCycle(10.0) def on_disconnect(client, userdata, rc=0): #logging.debug("DisConnected result code "+str(rc)) client.loop_stop() def on_message(client, userdata, message):
SEMI=2 # Mode semi-automatic (only current hour is manual then auto again) mode=AUTO # Actual thermostat mode heating=False # Heating system status on_menu=False # If user is into configuration mode, some update should not be performed menu=0 # Current menu (0 = not in menu) wait_action=RELAY_WAIT # Counter for two subsequent actions on the relay light=DISPLAY_ON # Counter for turning off the lcd backlight (seconds) temp_list=[20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0,20.0] # Hourly (0-23) temperature sets for automatic mode weather={'temp':'--', 'hum':'--', 'wspd':'--', 'wdir':'N', 'icon':'sunny'} sensor=sensor = LM75.LM75() DC = 25 # TFT parameter RST = 23 # TFT parameter SPI_PORT = 0 # TFT parameter SPI_DEVICE = 0 # TFT parameter backlight = 18 # LCD backlight GPIO.setup(backlight, GPIO.OUT) B1 = 17 # Button 1 ******Verificare GPIO.setup(B1, GPIO.IN, pull_up_down=GPIO.PUD_UP) B2 = 22 # Button 2 ******Verificare GPIO.setup(B2, GPIO.IN, pull_up_down=GPIO.PUD_UP) B3 = 23 # Button 3 ******Verificare GPIO.setup(B3, GPIO.IN, pull_up_down=GPIO.PUD_UP) B4 = 27 # Button 4 ******Verificare GPIO.setup(B4, GPIO.IN, pull_up_down=GPIO.PUD_UP) RELAY = 24 # Relay control GPIO.setup(RELAY, GPIO.OUT) GPIO.output(RELAY,1) # initial status = heating off (relay not active) tlist=[] # Array for temp mean max_t_num = 10 # Numbero of readings for mean calculation # Creates screen image and TFT instance
import Adafruit_ILI9341 as TFT import Adafruit_GPIO as GPIO import Adafruit_GPIO.SPI as SPI #import date from datetime import time import datetime import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) TRIG = 17 ECHO = 27 GPIO.setup(TRIG,GPIO.OUT) GPIO.setup(ECHO,GPIO.IN) #-----REFERENCE STUFF----- #draw.ellipse((10, 10, 110, 80), outline=(0,255,0), fill=(0,0,255)) #draw.rectangle((10, 90, 110, 160), outline=(255,255,0), fill=(255,0,255)) #draw.line((10, 170, 110, 230), fill=(255,255,255)) #draw.polygon([(10, 275), (110, 240), (110, 310)], outline=(0,0,0), fill=(0,255,255)) #--------------------LOAD DISPLAY STUFF-------------------- DC = 18 RST = 23 SPI_PORT = 0 SPI_DEVICE = 0