示例#1
0
def main():
    I2C_BUS = upmGrovemd.GROVEMD_I2C_BUS
    I2C_ADDR = upmGrovemd.GROVEMD_DEFAULT_I2C_ADDR
    myLcd = lcd.Jhd1313m1(3, 0x3E, 0x62)

    # Instantiate an I2C Grove Motor Driver on I2C bus 0
    myMotorDriver = upmGrovemd.GroveMD(I2C_BUS, I2C_ADDR)
    myLcd.setCursor(0, 0)
    # set direction to CW and set speed to 50%
    print("Spin M1 and M2 at half speed for 3 seconds")
    myLcd.setColor(0, 100, 0)
    myLcd.write('Going Forward')
    myMotorDriver.setMotorDirections(upmGrovemd.GroveMD.DIR_CCW,
                                     upmGrovemd.GroveMD.DIR_CW)
    myMotorDriver.setMotorSpeeds(122, 122)

    time.sleep(3)
    # counter clockwise

    myLcd.setColor(53, 39, 249)
    myLcd.clear()
    myLcd.write('Rotating')
    print("Reversing M1 and M2 for 3 seconds")
    myMotorDriver.setMotorDirections(upmGrovemd.GroveMD.DIR_CW,
                                     upmGrovemd.GroveMD.DIR_CW)
    time.sleep(5)
    myLcd.clear()
    myLcd.setColor(255, 0, 0)

    myLcd.write('Halt')
    print("Stopping motors")
    myMotorDriver.setMotorSpeeds(0, 0)
示例#2
0
 def __init__(self, address=0x3E):
     self._bus = mraa.I2c(0)
     self._addr = address
     self._bus.address(self._addr)
     if self._bus.writeByte(0):
         print("Check if the LCD {} inserted, then try again".format(
             self.name))
         sys.exit(1)
     self.jhd = upmjhd.Jhd1313m1(0, address, address)
def main():

    # LCD address is 0x3E and RGB control adddress is 0x62
    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
    myLcd.setColor(255, 0, 0)

    myLcd.setCursor(0, 0)
    myLcd.write("Powering off")
    myLcd.setCursor(1, 0)
    myLcd.write("Please wait")
示例#4
0
def main():
    # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

    myLcd.setCursor(0, 0)
    # RGB Blue
    #myLcd.setColor(53, 39, 249)

    # RGB Red
    myLcd.setColor(255, 0, 0)

    myLcd.write('Hello, Mars.')
    myLcd.setCursor(1, 2)
    myLcd.write('Hello, Mars (again).')
示例#5
0
文件: display.py 项目: Mathhrp/soe
def main():
    # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

    myLcd.setCursor(0, 0)
    # RGB Blue
    #myLcd.setColor(53, 39, 249)

    # RGB Red
    myLcd.setColor(255, 0, 0)
    firebase = firebase.FirebaseApplication(
        'https://sistema-op-embarcado.firebaseio.com/', None)
    result = firebase.post('/users', 'Teste', {'print': 'pretty'},
                           {'X_FANCY_HEADER': 'VERY FANCY'})
    myLcd.write('Hello World')
    myLcd.setCursor(1, 2)
    myLcd.write('Hello World')
示例#6
0
    def __init__(self, commander, sensor_room, sensor_name, sensor_id, \
        temp_sensor_pin, temp_sensor_only=False):
        '''Init method for Sensor object.

        Note: 'has_passed_threshold' is a flag for tracking when sensor has passed 
        uppoer or lower threshold (to help track whether to evaluate calling 
        closeValve()).

        :param MissionControl commander: MissionControl object instance that 
            started the sensor.
        :param str sensor_room: Room name where physical sensor HW module is located.
        :param str sensor_name: Name of individual sensor HW module in the room.
        :param int temp_sensor_pin: AIO pin that temp sensor is on (typically 0).
        :param bool temp_sensor_only: Optional param to indicate that the module only
            has a temperature sensor (typically for demo purposes).

        :return: Sensor object
        '''

        self.commander = commander
        self.sensor_room = sensor_room
        self.sensor_name = sensor_name
        self.sensor_id = sensor_id
        self.temp_sensor_pin = temp_sensor_pin
        self.temp_sensor_only = temp_sensor_only
        self.latest_temp_c = None
        self.latest_temp_f = None
        self.has_passed_threshold = False
        self.valve_open = False

        self.temp = grove.GroveTemp(
            self.temp_sensor_pin)  # Create temp sensor obj

        if not self.temp_sensor_only:
            # Instantiate a Stepper motor on a ULN200XA Darlington Motor Driver
            # This was tested with the Grove Geared Step Motor with Driver
            # Instantiate a ULN2003XA stepper object
            # Note: The other numbers are pins it's connected to on the board
            self.stepperMotor = upmULN200XA.ULN200XA(STEPPER_STEPS, 8, 9, 10,
                                                     11)
            atexit.register(self.exitHandler)  # Register exit handlers
            signal.signal(signal.SIGINT, self.SIGINTHandler)
            self.stepperMotor.setSpeed(STEPPER_SPEED)

            # Set up the LCD
            self.lcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
示例#7
0
def main():
    #POT connected to AIO pin 0
    knob = grove.GroveRotary(0)
    #Temperature sensor connected to AIO pin 1
    temp = grove.GroveTemp(1)
    # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
    # Loop indefinitely
    while True:
        # Read values
        abs = knob.abs_value()
        print("Abs values: " + str(abs))
        sleep(1)
        if abs < 100:
            myLcd.clear()
            # Set background color to Blue
            myLcd.setColor(0, 0, 255)  #RGB
            # Zero the cursor
            myLcd.setCursor(0, 0)
            # Print the IP address for wlan0
            ip = get_ip_address('wlan0')
            myLcd.write("IP " + ip)
            sleep(1)
        elif abs > 100 and abs < 500:
            #Getting grove temperature value
            print(temp.name())
            for i in range(0, 10):
                celsius = temp.value()
                fahrenheit = celsius * 9.0 / 5.0 + 32.0
                print("%d degrees Celsius, or %d degrees Fahrenheit" \
                         % (celsius, fahrenheit))
                sleep(1)
            myLcd.clear()
            myLcd.setColor(255, 0, 0)  #RGB
            myLcd.setCursor(0, 0)
            myLcd.write("Temp " + str(fahrenheit) + " F")
        else:
            #Printing a big thank you!
            myLcd.clear()
            myLcd.setColor(0, 255, 0)  #RGB
            myLcd.setCursor(0, 0)
            myLcd.write("Thanks element14")
            myLcd.setCursor(1, 0)
            myLcd.write("and Intel")
            sleep(1)
示例#8
0
def publish_message():
    '''
    Description: 
       This function publish text written to LCD display to the google cloud Pub/Sub.
    Args: 
       None
    Returns:
       None
    Raise:
       Throw an exception on failure
   '''
    try:

        myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

        myLcd.setCursor(0, 0)

        myLcd.setColor(255, 0, 0)

        textHigh = "Welcome"
        textLow = "Google iot"

        myLcd.write(textHigh)
        myLcd.setCursor(1, 2)
        myLcd.write("text")

        args.message = textHigh + " " + textLow

        cloudApisObj.publish_message_to_subpub(
            args.project_id, args.registry_id, args.device_id,
            args.message_type, args.base_url, args.cloud_region,
            args.algorithm, args.private_key_file, args.message_data_type,
            args.message)

        time.sleep(2)

    except Exception, e:
        print e
示例#9
0
def main():
    # Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

    myLcd.setCursor(0, 0)  # Set LCD cursory to write out the top line
    myLcd.setColor(0, 0, 255)  # By default, set LCD color to blue
    myLcd.write("Current temp:")  # Write out label for temperature

    # Create the temperature sensor object using AIO pin 0
    temp = grove.GroveTemp(0)
    # print(temp.name())

    # Read the temperature ten times, printing both the Celsius and
    # equivalent Fahrenheit temperature, waiting one second between readings
    for i in range(0, 30):
        celsius = temp.value()
        fahrenheit = celsius * 9.0 / 5.0 + 32.0
        # print("%d degrees Celsius, or %d degrees Fahrenheit" \
        #     % (celsius, fahrenheit))
        tempString = "%s C / %s F" % (celsius, fahrenheit)

        # Update LCD output
        myLcd.setCursor(1, 0)  # Move cursor to next line
        if celsius >= 25:  # If it gets above 24 C, turn screen red
            myLcd.setColor(255, 0, 0)
            myLcd.write(tempString)
        elif (celsius == 24):
            myLcd.setColor(0, 255, 0)
            myLcd.write(tempString)
        else:  # TODO: Is there a getColor method?
            myLcd.setColor(0, 0, 255)
            myLcd.write(tempString)

        time.sleep(1)

    # Delete the temperature sensor object
    del temp
示例#10
0
    def __init__(self):
        # self.video = cv2.VideoCapture('http://192.168.1.175:8080/?action=stream.mjpg')
        self.video = cv2.VideoCapture(1)

        self.w = self.video.get(3)  # CV_CAP_PROP_FRAME_WIDTH
        self.h = self.video.get(4)  # CV_CAP_PROP_FRAME_HEIGHT
        self.rangeLeft = int(1 * (self.w / 6))
        self.rangeRight = int(5 * (self.w / 6))
        self.midLine = int(3 * (self.w / 6))

        # get the first frame ready when web server starts requesting
        (_, self.rawImage) = self.video.read()
        (ret, jpeg) = cv2.imencode('.jpg', self.rawImage)
        self.frameDetections = jpeg.tobytes()

        self.contours = []

        # initialize the variable used to indicate if the thread shouldbe stopped
        self.stopped = False

        # Create MQTT client
        self.client = mqtt.Client()
        self.client.on_connect = on_connect
        # Connect to MQTT broker
        self.client.connect('broker.hivemq.com', 1883, 60)

        # authenticate Twitter app
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        # create Tweepy API
        self.api = tweepy.API(auth)

        # open connection to Firmata
        mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")
        time.sleep(0.1)
        # create LCD instance
        self.myLcd = lcd.Jhd1313m1(512, 0x3E, 0x62)
示例#11
0
'''
Curso IoT 2017 - IFSP Piracicaba
Professor: Gustavo Voltani von Atzingen
alterações: Giovana Tangerino
'''
from wiringx86 import GPIOGalileo as GPIO
from upm import pyupm_jhd1313m1 as lcd

#pinos GPIO
pino_led_red = 8  #D8
pino_led_green = 7  #D7
pino_led_blue = 6  #D6

# numeracao dos pinos conectados aos sensores de acordo com a bibliteca usada
pinos = GPIO(debug=False)
tela = lcd.Jhd1313m1(0, 0x3E, 0x62)

pinos.pinMode(pino_led_red, pinos.OUTPUT)
pinos.pinMode(pino_led_green, pinos.OUTPUT)
pinos.pinMode(pino_led_blue, pinos.OUTPUT)


def escreve_lcd(texto_linha1, texto_linha2):
    tela.clear()
    tela.setCursor(0, 0)
    tela.write(texto_linha1)
    tela.setCursor(1, 0)
    tela.write(texto_linha2)


def escreve_lcd_cor(texto_linha1, texto_linha2, cor):
示例#12
0
import serial
import json
import time
import uuid
import random
from datetime import datetime
from upm import pyupm_jhd1313m1

ard = serial.Serial('/dev/ttyS2', 9600,timeout=1)
lcd = pyupm_jhd1313m1.Jhd1313m1(0, 0x3e, 0x62)

def showAngle(angle):
	lcd.clear()
	lcd.setCursor(0, 0)
	#lcd.write(humid)
	#lcd.setCursor(1, 0)
	lcd.write("Dig_val:" + angle + " Deg")
	lcd.setColor(255, 180, 180)

def report_val(temp_val):
    '''
    Write out temperature to a random json file
    '''
    #v = fake_fan_sensor()
    fname = str(uuid.uuid4()) + ".json"
    d = {
        'metric': {
            'name': 'Furnace Temperature',
            'source': 'sensor_1',
            'kind': 'gauge',
            'unit': 'Farenheit',
示例#13
0
def io_setup():
    """
    io_setup: I/O setup for GPIO and Grove sensors
    Red, Green, Blue LEDs are initialized with PWM pins, period = PWM_PER us
    Rotary encoder, sound, temperature, and light sensors
    JHD1313M1 I2C display driver

    @return device_list: (list) list of all created mraa/upm objects
    Example usage: io_setup()
    """
    
    global red_led, green_led, blue_led
    global rotary_enc, sound_sensor, temp_sensor, light_sensor
    global lcd, buzzer

    devices = {}


    red_led = mraa.Pwm(RED_PIN)
    green_led = mraa.Pwm(GREEN_PIN)
    blue_led = mraa.Pwm(BLUE_PIN)

    # PWM_PER = 500 us == 2 kHz freq.
    red_led.period_us(PWM_PER)
    green_led.period_us(PWM_PER)
    blue_led.period_us(PWM_PER)

    # enable PWM and turn off LEDs
    red_led.enable(True)
    red_led.write(0)
    green_led.enable(True)
    green_led.write(0)
    blue_led.enable(True)
    blue_led.write(0)

    devices["redLED"] = red_led
    devices["greenLED"] = green_led
    devices["blueLED"] = blue_led

    # I2C addresses: 0x3E (LCD_ADDRESS), 0x62 (RGB_ADDRESS)
    lcd = groveLCD.Jhd1313m1(0, 0x3E, 0x62)
    lcd.clear()
    lcd.backlightOn()
    lcd.setColor(255, 255, 255)
    devices["lcd"] = lcd

    rotary_enc = grove.GroveRotary(ROT_PIN)
    sound_sensor = mraa.Aio(SOUND_PIN)
    temp_sensor = grove.GroveTemp(TEMP_PIN)
    light_sensor = grove.GroveLight(LIGHT_PIN)

    devices["rot"] = rotary_enc
    devices["sound"] = sound_sensor
    devices["temp"] = temp_sensor
    devices["light"] = light_sensor

    buzzer = groveBuzzer.Buzzer(BUZZ_PIN)
    buzzer.stopSound()
    buzzer.setVolume(0.125)
    devices["buzz"] = buzzer

    return devices
示例#14
0
import os
import time
import requests

from upm import pyupm_jhd1313m1 as lcd

lcd_refer = lcd.Jhd1313m1(0, 0x3E, 0x62)
sleep_seconds = 1
file_path = 'file.txt'
firebase_url = 'projeto-embarcado.firebaseio.com'


def get_modified_time():
    return os.stat(file_path).st_mtime


def get_file_text_content():
    file_o = open(file_path)
    return file_o.read()


def send_to_firebase(txt):
    url = "https://{}/messages.json".format(firebase_url)
    print("Sending {} to {}".format(txt, url))
    r = requests.post(url, json={'txt': txt})
    print("Response:", r.status_code, r.content)


def write_lcd(txt):
    print('Writing {} on LCD...'.format(txt))
    lcd_refer.setCursor(0, 0)
示例#15
0
#Reto 1
#Trabajar con LCD I2C y TH02

#importa bibliotecas
#Biblioteca Sensor temperatura y humedad
from upm import pyupm_th02 as tyhupm
#Biblioteca del LCD RGB
from upm import pyupm_jhd1313m1 as lcd
import time

#Se inicializa el sensor pirolico en el puerto 2
tyh = tyhupm.TH02(bus=0, addr=64)
#Direcciones del LCD segun el fabricante
mylcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
#Limpia display
mylcd.clear()
#Asigna color de led al LCD
mylcd.setColor(0, 113, 197)

while True:
    humedad = tyh.getHumidity()
    temperatura = tyh.getTemperature()
    #Se pone el curso en (0,0)
    mylcd.setCursor(0, 0)
    mylcd.write("T: " + str(temperatura))
    mylcd.setCursor(1, 0)
    mylcd.write("H: " + str(humedad))
    time.sleep(2)
示例#16
0
文件: colors.py 项目: ivoayala/Edison
import sys
import mraa, upm, time
from upm import pyupm_jhd1313m1
from upm import pyupm_th02

argument1=sys.argv[1]
argument2=sys.argv[2]
argument3=sys.argv[3]
arguments=sys.argv[1:]


display = pyupm_jhd1313m1.Jhd1313m1(0,0x3E, 0x62)
display.setColor(int(argument1),int(argument2),int(argument3))

#sensores = pyupm_th02.TH02(6,0x40)

Switch = 0
Temperature = 0
Humidity = 0

#while True:

#    Temperature = round(sensores.getTemperature(),2)
#    Humidity = round(sensores.getHumidity(),2)
#    status = sensores.getStatus()
#    name = sensores.name()
    
    
#    print 'La temperatura es: '  + str(Temperature)
#    print 'La humedad es: ' + str(Humidity) 
   # print 'Status es :' + str(status)
示例#17
0
# -*- coding: latin-1 -*-
from db_sqlite import *
from sensores import *
from datetime import datetime
import threading
from time import gmtime, strftime, sleep
from upm import pyupm_jhd1313m1 as LCD
lcd = LCD.Jhd1313m1(0, 0x3E, 0x62)
hoje_1 = strftime("%w,%d,%m,%Y,%H,%M,%S", gmtime())
celsius = leitura_temperatura()
old_celsius = 0
old_valorpsi1 = 0
old_horarios_txt = 0
horarios_txt = 0
valorpsi2 = 0
texto2 = celsius
valorph = 0
old_valorph = 0

#================= funcao ler horarios ==================================================
def ver_horario():
	#hoje_1 = strftime("%w,%d,%m,%Y,%H,%M,%S", gmtime())
	hoje_2 = hoje_1.split(',')
	date_now = datetime.today()
	semana = hoje_2[0]
	ano = date_now.year
	mes = date_now.month
	dia = date_now.day
	hora = date_now.hour
	minuto = date_now.minute
	segundo = date_now.second
temptPin=0
tempt=mraa.Aio(temptPin)
temptValue=0

soundPin=1
sound=mraa.Aio(soundPin)
soundSensorValue=0

lightPin=2
light=mraa.Aio(lightPin)
lightValue=0

buttonPin=mraa.Gpio(2)
buttonPin.dir(mraa.DIR_IN)

lcdDisplay=lcd.Jhd1313m1(0, 0x3E , 0x62)    #LCD initialization

while True:
    buttonState=buttonPin.read()
    if buttonPin.read()!=lastButtonState:
        if (buttonPin.read()==1):
            buttonCounter=buttonCounter+1
    lastButtonState=buttonPin.read()
    time.sleep(5)
    
    if buttonCounter==1: 
        lightValue=float(light.read())
        print "Isik Degeri= "+str(lightValue)
        lcdDisplay.clear()
        lcdDisplay.setCursor(0,0)
        lcdDisplay.write("Isik Degeri="+str(lightValue))