Ejemplo n.º 1
0
    def __init__(self):
        """ Initializes the class. """

        self.Helpers = Helpers("LEDs", False)
        self.Helpers.logger.info("LEDs Helper Class initialization complete.")

        self.Helpers.logger.info("Using MRAA version " +
                                 str(mraa.getVersion()))
Ejemplo n.º 2
0
import cv2
import numpy
import socket
import zbar
import Image
import time
import mraa

## LED
led = mraa.Gpio(2)
led.dir(mraa.DIR_OUT)
led.write(0)

## OpenCV e mraa Version
OpenCV_version = str(cv2.__version__)
mraa_version = str(mraa.getVersion())

## Config Comunicacao
TCP_IP = ''
TCP_PORT = 5052
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.bind((TCP_IP, TCP_PORT))
serverSocket.listen(True)

## Hello!
print "Intel Edison"
print "OpenCV Version: " + OpenCV_version
print "mraa Version: " + mraa_version
print "QR Code Decoder"

## Config captura

    def turn_off(self):
        self.gpio.write(0)
        print("I've turned off the LED connected to GPIO Pin #{0}.".format(self.gpio.getPin()))


class NumberInLeds:
    def __init__(self):
        self.leds = []
        for i in range(1, 10):
            led = Led(i)
            self.leds.append(led)

    def print_number(self, number):
        print("==== Turning on {0} LEDs ====".format(number))
        for j in range(0, number):
            self.leds[j].turn_on()
        for k in range(number, 9):
            self.leds[k].turn_off()

if __name__ == "__main__":
    print ("Mraa library version: {0}".format(mraa.getVersion()))
    print ("Mraa detected platform name: {0}".format(mraa.getPlatformName()))

    number_in_leds = NumberInLeds()
    # Count from 0 to 9
    for i in range(0, 10):
        number_in_leds.print_number(i)
        time.sleep(3)
__author__ = 'Gaston C. Hillar'


import mraa
import time


if __name__ == "__main__":
    print ("Mraa library version: {0}".format(mraa.getVersion()))
    print ("Mraa detected platform name: {0}".format(mraa.getPlatformName()))

    # Configure GPIO pins #1 to 9 to be output pins
    output = []
    for i in range(1, 10):
        gpio = mraa.Gpio(i)
        gpio.dir(mraa.DIR_OUT)
        output.append(gpio)

    # Count from 1 to 9
    for i in range(1, 10):
        print("==== Turning on {0} LEDs ====".format(i))
        for j in range(0, i):
            output[j].write(1)
            print("I've turned on the LED connected to GPIO Pin #{0}.".format(j + 1))
        time.sleep(3)
Ejemplo n.º 5
0
import mraa
import time

print "About to test mraa"
print mraa.getVersion()

# initialise gpio 23
gpio_pin = mraa.Gpio(12)

# set gpio 23 to output
gpio_pin.dir(mraa.DIR_OUT)

# toggle both gpio's
while True:
    gpio_pin.write(1)
    print "On"

    time.sleep(1)

    gpio_pin.write(0)
    print "Off"

    time.sleep(1)
Ejemplo n.º 6
0
#!/usr/bin/env python

# Author: Ron Evans (@deadprogram)
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import mraa

print (mraa.getVersion())

mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
import mraa as m
import random as rand
import time

# Excuse the super boring example, I was out of fun devices to play with, this
# will write and read the same data back to itself, a few 100 times, just short
# MISO & MOSI on your board


print (m.getVersion())
while True:
    try:
        x = m.Aio(0)
        print (x.read())
        print ("%.5f" % x.readFloat())
    except:
        print ("Are you sure you have an ADC?")
	time.sleep(1)
	# fo = open("reading.txt", "w")
	# fo.write(x.read())
	# fo.close()
Ejemplo n.º 8
0
import time
import mraa

###### Programe Begins ####
print (mraa.getVersion())  #Print mraa version for reference

# Initiate Digital Pin 8 with direction in
Button = mraa.Gpio(8)
Button.dir(mraa.DIR_IN)

while 1:
        # Read voltage at Digital Pin
        value = Button.read()
        if value == 1:
                print "Button State: ON"
        else:
                print "Button State: OFF"
        time.sleep(.25)
Ejemplo n.º 9
0
 def test_mraa_version(self):
     self.version = m.getVersion()
     print("Version is: " + self.version)
     self.assertIsNotNone(self.version)
Ejemplo n.º 10
0
 def test_mraa_version(self):
   version = m.getVersion()
   print("Version is: " + version)
   self.assertIsNotNone(version)
   self.assertNotEqual(version, "", "MRAA version is an empty string")
Ejemplo n.º 11
0
 def version(self):
     print (mraa.getVersion())
Ejemplo n.º 12
0
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import time
import tornado.ioloop
import tornado.web
from tornado import gen

from tornado.websocket import websocket_connect
from controller.base import WebRequest, WebSocket
from tornado.escape import json_encode, json_decode

from setting import settings

import mraa
print "mraa version: %s" % mraa.getVersion()


class MainHandler(WebRequest):
    def get(self):
        self.render('./template/index.html')


WS_URL = "ws://www.hotpoor.org:8036/ws?aim_id=LITEOSDEMO"
HEADIMG = "http://wx.qlogo.cn/mmopen/viasnlibZqap4GwK7ua20icUVLcTas3GFia5lLleaYmTsgnO1Aj3icibMwY9UlSoeD1Smur9yUIPNSTbOWfuUYQvjm8TuXzgY7Wia54/0"
NICKNAME = "Helen小布熊"


u=mraa.Uart(0)
u.setBaudRate(115200)
u.setMode(8, mraa.UART_PARITY_NONE, 1)
Ejemplo n.º 13
0
 def test_mraa_version(self):
     version = m.getVersion()
     print("Version is: " + version)
     self.assertIsNotNone(version)
     self.assertNotEqual(version, "", "MRAA version is an empty string")
Ejemplo n.º 14
0
 def test_mraa_version(self):
   self.version = m.getVersion()
   print "Version is: " + self.version
   self.assertIsNotNone(self.version)
Ejemplo n.º 15
0
#!/usr/bin/env python

import mraa
import time

print('MRAA Version: %s' % mraa.getVersion())

analogPin0 = mraa.Aio(0)
analogValue = analogPin0.read()
analogValueFloat = analogPin0.readFloat()

while True:
    analogValue = analogPin0.read()
    analogValueFloat = analogPin0.readFloat()
    print(analogValue)
    print('%.5f' % analogValueFloat)
    time.sleep(1)
Ejemplo n.º 16
0
import time


class Counter:
    count = 0


def isrUpdate(args):
    if l.read():
        c.count += 1
    if r.read():
        c.count -= 1
    print(c.count)


print("MRAA Version: %s" % mraa.getVersion())

l = mraa.Gpio(6)
r = mraa.Gpio(7)
c = Counter()

l.dir(mraa.DIR_IN)
l.mode(mraa.MODE_PULLUP)
r.dir(mraa.DIR_IN)
r.mode(mraa.MODE_PULLUP)

l.isr(mraa.EDGE_BOTH, isrUpdate, isrUpdate)
r.isr(mraa.EDGE_BOTH, isrUpdate, isrUpdate)

time.sleep(1000)
Ejemplo n.º 17
0
import mraa

print(mraa.getVersion())

touch = mraa.Gpio(33)
touch.dir(mraa.DIR_IN)

pastTouch = False
while True:
    currTouch = touch.read()
    if currTouch != pastTouch:
        if currTouch:
            print('pressed')
        else:
            print('released')
        pastTouch = currTouch
Ejemplo n.º 18
0
 def version(self):
     print (mraa.getVersion())
     print (mraa.getPlatformName())
     print (mraa.getPlatformType())
    def do_POST(self):
        print 'HTTP post received'
        leng = int(self.headers.getheader('content-length', 0))
        body = self.rfile.read(leng)
        print self.request_version, self.command
        print self.headers
        print body
        print "=========Above content are for debugging purpose======="

        self.send_response(200)
        reply ="POST request received"
        self.send_header("Content-Length", str(len(reply)))
        self.end_headers()
        self.wfile.write(reply)

        print "start parsing the content"
        body_content = str(body).split("||")
        print body_content

        if body_content[0]=='getBPM':
            print (mraa.getVersion())
            if have_potentiomemter:
                x = mraa.Aio(0)
                print "x.read() = ", x.read()
                BPMvalue = 50.0+(float(x.read())/1023.0)*150.0
                print "BPMvalue=", BPMvalue
                send_http_post(serverIP, "bpm="+str(int(BPMvalue)))
                print "bpm value sent"

        elif body_content[0] == "r":
            print "debugging::about to play the song"
            print body_content
            starttime = datetime.datetime.strptime(body_content[1], "%Y-%m-%d %H:%M:%S.%f") 

            bpm = float(body_content[2])
            spb = 60/bpm
            song = json.loads(body_content[3])

            currenttime = datetime.datetime.now()
            start_in_scs = (starttime - currenttime).total_seconds()
            time.sleep(start_in_scs)
            robot_play(song, spb)
            print "Thank you for listening"            

        elif body_content[0] == "u":
            starttime = datetime.datetime.strptime(body_content[1], "%Y-%m-%d %H:%M:%S.%f") 
            currenttime = datetime.datetime.now()
            start_in_scs = (starttime - currenttime).total_seconds()
            time.sleep(start_in_scs)
            user_play()

        elif body_content[0] == "h":
            starttime = datetime.datetime.strptime(body_content[1], "%Y-%m-%d %H:%M:%S.%f") 
            currenttime = datetime.datetime.now()
            start_in_scs = (starttime - currenttime).total_seconds()
            time.sleep(start_in_scs)
            if have_heartbeat_sensor:
                heartbeat_mode(20)

        elif body_content[0] == "s":
            if have_simon_game:
                starttime = datetime.datetime.strptime(body_content[1], "%Y-%m-%d %H:%M:%S.%f") 
                currenttime = datetime.datetime.now()
                start_in_scs = (starttime - currenttime).total_seconds()
                time.sleep(start_in_scs)
                simon_game()
Ejemplo n.º 20
0
toto = i2c.write(data)
toto = i2c.writeByte(0xE3)
print 'toto value : ' + str(toto_1) + ' 2 ' + str(toto_2)

time.sleep(1.3)
d = 3
temp=[]
u = i2c.read(d)

print 'nb requested : ' + str(d) + ' nb read : ' + str(u_1) + str(u_2)


LowLevel mraa
=============
mraa.getVersion()
'v0.9.4-4-g8e8ed7d'
mraa.getI2cBusCount ()
9
mraa.getPlatformName ()
'Intel Edison'
mraa.getPlatformVersion ()
'arduino'
mraa.getI2cBusId (6)   
6
mraa.getI2cBusId (1)
-1
i2c = mraa.I2c(6)
mraa.getDefaultI2cBus()
i2c.address(0x60)