def main():
    light = pyupm_grove.GroveLight(LIGHT_SENSOR_PIN)
    pwm = mraa.Pwm(LED_PWM_PIN)
    pwm.period_us(5000)  # Set the period as 5000 us or 5ms
    pwm.enable(True)  # enable PWM
    pwm.write(0)
    print "Light sensor bar:"
    while True:
        ambientLight = light.value()
        sys.stdout.write("Light sensor: %02d " % ambientLight)
        sys.stdout.write("[")
        # Control the intensity of the LED connected to PWM depending on the
        # intensity of the ambient light, if intensity is more, the LED will light less brightly
        tempLight = ambientLight
        if tempLight > MAX_LIGHT:
            tempLight = MAX_LIGHT  # Nromalize the value

        pwmValue = (MAX_LIGHT - tempLight) / float(MAX_LIGHT)

        pwm.write(pwmValue)

        for i in range(0, MAX_LIGHT):
            if ambientLight > i:
                sys.stdout.write("=")
            elif ambientLight == i:
                sys.stdout.write("|")
            else:
                sys.stdout.write(" ")

        #sys.stdout.write("] pwm:%f\r" %pwmValue) # un comment this line if you want to see PWM value
        sys.stdout.write("]  \r")
        sys.stdout.flush()
        time.sleep(0.1)
Ejemplo n.º 2
0
def readMeasures():

    tempSensor =  grove.GroveTemp(0)
    lightSensor = grove.GroveLight(0)
    global temperature
    global luminosity
    temperature = tempSensor.value()
    luminosity = lightSensor.value()
Ejemplo n.º 3
0
def dataDweetHandler():  # Freeboard
    light = grove.GroveLight(0)
    data = {}
    while True:
        data['alive'] = "1"
        data['network'] = dataNetwork()
        data['light'] = light.value()
        dweepy.dweet_for('InternetOfThings101x00', data)
        time.sleep(5)
Ejemplo n.º 4
0
def main():
    # Create the light sensor object using AIO pin 0
    light = grove.GroveLight(1)

    # Read the input and print both the raw value and a rough lux value,
    # waiting one second between readings
    while 1:
        print(light.name() + " raw value is %d" % light.raw_value() + \
            ", which is roughly %d" % light.value() + " lux")
        time.sleep(1)
Ejemplo n.º 5
0
    def __init__(self):
        # Grove Temperature sensor at Analog In 0, hardcoded for simplicity
        TEMP_SENSOR_PIN = 0
        # Grove Light Sensor at Analog In 1, hardcoded for simplicity
        LIGHT_SENSOR_PIN = 1

        self.temp_sensor = grove.GroveTemp(TEMP_SENSOR_PIN)
        self.light_sensor = grove.GroveLight(LIGHT_SENSOR_PIN)
        if not self.temp_sensor or not self.light_sensor:
            raise ValueError("Cannot initialize sensors")
Ejemplo n.º 6
0
def functionDataSensor():
    #netdata = psutil.net_io_counters()
    #data = netdata.packets_sent + netdata.packets_recv
    # Create the light sensor object using AIO pin 0
light = grove.GroveLight(0)

# Read the input and print both the raw value and a rough lux value,
# waiting one second between readings
while 1:
    print light.name() + " raw value is %d" % light.raw_value() + \
        ", which is roughly %d" % light.value() + " lux";
    time.sleep(1)

# Delete the light sensor object
del light
    return data
Ejemplo n.º 7
0
    def __init__(self):
        # Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
        self.piezo = ldt0028.LDT0028(0)

        # Create the light sensor object using AIO pin 1
        self.light = grove.GroveLight(1)

        #led on D5
        self.led = mraa.Gpio(5)
        self.led.dir(mraa.DIR_OUT)

        self.mic = upmMicrophone.Microphone(2)
        self.threshContext = upmMicrophone.thresholdContext()
        self.threshContext.averageReading = 0
        self.threshContext.runningAverage = 0
        self.threshContext.averagedOver = 2
Ejemplo n.º 8
0
    def __init__(self):
        self.screen = pyupm_i2clcd.Jhd1313m1(6, 0x3E, 0x62)
        self.clearScreen()

        self.light = grove.GroveLight(2)

        self.mic = upmMicrophone.Microphone(1)
        self.threshContext = upmMicrophone.thresholdContext()
        self.threshContext.averageReading = 0
        self.threshContext.runningAverage = 0
        self.threshContext.averagedOver = 2

        self.piezo = ldt0028.LDT0028(0)

        self.button = mraa.Gpio(3)
        self.button.dir(mraa.DIR_IN)

        self.buzzer = mraa.Gpio(6)
        self.buzzer.dir(mraa.DIR_OUT)
        self.buzzer.write(0)
Ejemplo n.º 9
0
#!/usr/bin/python
#
# Stefan Kloepping <*****@*****.**>
#  --  Do 26 Nov 17:27:27 2015
#
import pyupm_i2clcd as lcd
import pyupm_grove
import time

# define that Light Sensor is on A0
light = pyupm_grove.GroveLight(0)

# initiale LCD display
myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

while True:
		
	# Green
	myLcd.setColor(255, 255, 0)

	# Zero the cursor
	myLcd.setCursor(0,0)

	# Print first line with light value in Lux:
	text = str('Lux Wert: ') + str(light.value())
	myLcd.write(text)
	time.sleep(1)
Ejemplo n.º 10
0
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters

credentials = ConfigParser.ConfigParser()
credentialsfile = "credentials.config"
credentials.read(credentialsfile)
controlmode = 1
Angle = 0

# Create the button object usind D3
button = grove.GroveButton(3)
# Create the servo object using D6
gServo = servo.ES08A(6)
# Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)
myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
# Create the light sensor object using AIO pin 2
light = grove.GroveLight(2)
# Create the temperature sensor object using AIO pin 2
#temp = grove.GroveTemp(2)
# Create relay object using D5
relay = grove.GroveRelay(5)
# Initialize TH02 temperature sensor at 0x40
gTemp = temp.TH02(0, 0x40)

# Initialize servo to 0 degrees
gServo.setAngle(Angle)


def functionLight(bot, update):
    luxes = light.value()
    bot.sendMessage(update.message.chat_id,
                    text='Room Light: ' + str(luxes) + ' luxes')
Ejemplo n.º 11
0
 def getLightSensor(self, pin=2):
     if self.light is None:
         # Create the light sensor object using AI2 pin 2
         self.light = grove.GroveLight(pin)
     return self.getProxyObject(self.light)
Ejemplo n.º 12
0
import pyupm_grove
import pyupm_th02 as upmTh02

import mraa
import time
import sys

LIGHT_SENSOR_PIN= 2
light = pyupm_grove.GroveLight(LIGHT_SENSOR_PIN)


def light_sensor():
    return light.value()

class TemperatureAndHumiditySensor:
	def __init__(self,bus):
		self.th02_sensor = upmTh02.TH02(bus)
		self.temperature_celsius = 0.0
		self.temperature_fahrenheit = 0.0
		self.humidity = 0.0

	def measure_temperature_and_humidity(self):
		temperature_celsius = self.th02_sensor.getTemperature()
		self.temperature_celsius = temperature_celsius
		self.temperature_fahrenheit = \
		(temperature_celsius*9.0/5.0)+32
		self.humidity = self.th02_sensor.getHumidity()
Ejemplo n.º 13
0
#!/usr/bin/python

# ========== * IMPORT SECTION * ========== #

# UPM Modules
import pyupm_i2clcd as lcd
import pyupm_grove as g
from time import sleep

# BT Needed Modules
import spp as s

# ========= * SETTING UP GPIOS * ========= #
light = g.GroveLight(0)  # Light sensor is connected to slot A0
display = lcd.Jhd1313m1(0, 0x3E, 0x62)  # LCD goes on any I2C slot
relay = g.GroveRelay(4)  # Relay module is connected to slot D4

# ========= * PROJECT FUNCTIONS * ======== #

# ------------ LCD Functions ------------- #


# Display light sensor data
def displayLightInfo():
    display.clear()  # Clear LCD
    display.setCursor(0, 0)  # Set LCD cursor position (top left corner)
    display.write('Light:%s' % str(light.value()))  # Display light sensor data
    sleep(1)


# Display message on LCD
Ejemplo n.º 14
0
#!/usr/bin/python

import time, sys, signal, atexit, mraa, thread, threading, os
import pyupm_grove as grove
import pyupm_guvas12d as upmUV
import pyupm_grovemoisture as upmMoisture
import pyupm_stepmotor as mylib
import pyupm_servo as servo
from multiprocessing import Process

# IO Def
myIRProximity = mraa.Aio(5)  			#GP2Y0A on Analog pin 5
temp = grove.GroveTemp(0) 			#grove temperature on A0 
myMoisture = upmMoisture.GroveMoisture(1) 	#Moisture sensor on A1
light = grove.GroveLight(2) 			#Light sensor on A2
myUVSensor = upmUV.GUVAS12D(3) 			#UV sensor on A3
stepperX = mylib.StepMotor(2, 3) 		#StepMotorY object on pins 2 (dir) and 3 (step)
stepperY = mylib.StepMotor(4, 5)		#StepMotorX object on pins 4 (dir) and 5 (step)
waterpump = mraa.Gpio(10) 			#Water pump's Relay on GPIO 10
waterpump.dir(mraa.DIR_OUT)
waterpump.write(0)
gServo = servo.ES08A(6)                		#Servo object using D6
gServo.setAngle(50)
switchY = mraa.Gpio(7)    			#SwitchY for GPIO 7
switchY.dir(mraa.DIR_IN)
switchX = mraa.Gpio(8)				#SwitchX for GPIO 8
switchX.dir(mraa.DIR_IN)
EnableStepperX = mraa.Gpio(9)			#StepperMotorX Enable on GPIO 9
EnableStepperX.dir(mraa.DIR_OUT)
EnableStepperX.write(1)
EnableStepperY = mraa.Gpio(11)			#StepperMotorY Enable on GPIO 11
Ejemplo n.º 15
0
import sys

import time
import pyupm_grove as grove
import pyupm_i2clcd as lcd


def interruptHandler(signal, frame):
    sys.exit(0)


if __name__ == '__main__':
    signal.signal(signal.SIGINT, interruptHandler)

    myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)
    sensorluz = grove.GroveLight(0)
    pinSensor = mraa.Aio(1)
    pinSensor.setBit(12)

    colorR = 255
    colorG = 0
    colorB = 0
    myLcd.setColor(colorR, colorG, colorB)

    # Read the input and print, waiting 1/2 second between readings
    while True:
        valorSensor = sensorluz.value()
        valorSensor1 = pinSensor.read()
        myLcd.setCursor(0, 0)
        myLcd.write('%6d' % valorSensor)
        myLcd.setCursor(1, 0)
Ejemplo n.º 16
0
#Temperature sensor library
#import mraa
import HightTemp

#Vibration sensor library
import pyupm_ldt0028 as vibrationSensor

#Acecelerometer sensor library
import pyupm_mma7660 as accelerometerSensor

#######################################################################
#VARIABLES
#######################################################################
#Create the light sensor object using AIO pin 0
lightValue = grove.GroveLight(0)

#Create the loudness sensor object using AIO pin 1
loudnessValue = loudnessSensor.Loudness(1, 3.0)

#Create the temperature sensor object using AIO pin 2
#tempValue2 = mraa.Aio(2)

#Create the vibration sensor object using AIO pin 3
vibrationValue = vibrationSensor.LDT0028(3)
try:
    #Create the accelerometer sensor object using I2C 0
    accelerometerValue = accelerometerSensor.MMA7660(
        accelerometerSensor.MMA7660_DEFAULT_I2C_BUS,
        accelerometerSensor.MMA7660_DEFAULT_I2C_ADDR)
    print(accelerometerSensor.MMA7660_DEFAULT_I2C_BUS)
Ejemplo n.º 17
0
import pyupm_grove

import lightbulb

# This is custom user configuration
TEMP_SENSOR_A_PIN = 0
LIGHT_SENSOR_A_PIN = 3
lightbulb.sensors.register(pyupm_grove.GroveTemp(TEMP_SENSOR_A_PIN))
lightbulb.sensors.register(pyupm_grove.GroveLight(LIGHT_SENSOR_A_PIN))

# Launch Flask
lightbulb.app.run(host='0.0.0.0', debug=True)
Ejemplo n.º 18
0
#!/usr/bin/python

import pyupm_grove as g
import pyupm_i2clcd as lcd
from time import sleep

light = g.GroveLight(0)
display = lcd.Jhd1313m1(0, 0x3E, 0x62)
relay = g.GroveRelay(4)
watering = 0
already_watered = 0


def displayLight():
    if light.value() <= 20:
        display.setColor(255, 0, 0)
    elif light.value() in range(21, 29):
        display.setColor(255, 255, 0)
    elif light.value() >= 30:
        display.setColor(0, 255, 0)


def function(data):
    func = functionInUse.get(data, dummy)
    func()


def dummy():
    pass

Ejemplo n.º 19
0
 def get_actuator(self):
     return pyupm_grove.GroveLight(self.pin)
Ejemplo n.º 20
0
 def __init__(self, threshold = 10.):
     # AIO pin 2
     self.light = grove.GroveLight(2)
     self.normalLight = self.light.raw_value()
     self.state = 0
     self.threshold = threshold
Ejemplo n.º 21
0
def upm_light():
	light = upm.GroveLight(0) #Analog port A0
	upm_light = light.value()

	return upm_light
Ejemplo n.º 22
0
import sys
import time
import pyupm_grove as grove
import pyupm_grovespeaker as upmGrovespeaker
import pyupm_i2clcd as lcd
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from wit import Wit
import os

credentials = ConfigParser.ConfigParser()
credentialsfile = "credentials.config"
credentials.read(credentialsfile)

button = grove.GroveButton(8)
display = lcd.Jhd1313m1(0, 0x3E, 0x62)
light = grove.GroveLight(0)
light1 = grove.GroveLight(0)
light2 = grove.GroveLight(1)
light3 = grove.GroveLight(2)
light4 = grove.GroveLight(3)
relay = grove.GroveRelay(2)


def functionLight(bot, update):
    # luxes = light.value()
    # if luxes == 0:
    #     output_msg  = "NO hay estacionamiento"
    # else:
    #     output_msg  = "SI hay estacionamiento"
    # bot.sendMessage(update.message.chat_id, text=output_msg)
    # os.system("curl ")
Ejemplo n.º 23
0
def getLight():
	global LIGHT_SENSOR_PIN
	light = pyupm_grove.GroveLight(LIGHT_SENSOR_PIN)
	return str(light.value())