예제 #1
0
def platform_detect():
    """Detect if running on the Raspberry Pi or Beaglebone Black and return the
    platform type.  Will return RASPBERRY_PI, BEAGLEBONE_BLACK, or UNKNOWN."""
    # Handle Raspberry Pi
    pi = pi_version()
    if pi is not None:
        return RASPBERRY_PI

    # Handle Beaglebone Black
    # TODO: Check the Beaglebone Black /proc/cpuinfo value instead of reading
    # the platform.
    plat = platform.platform()
    if plat.lower().find('armv7l-with-debian') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv7l-with-ubuntu') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv7l-with-glibc2.4') > -1:
        return BEAGLEBONE_BLACK

    # Handle Minnowboard
    # Assumption is that mraa is installed
    try:
        import mraa
        if mraa.getPlatformName() == 'MinnowBoard MAX' or mraa.getPlatformName(
        ) == 'MinnowBoard Compatible':
            return MINNOWBOARD
    except ImportError:
        pass

    # Couldn't figure out the platform, just return unknown.
    return UNKNOWN
예제 #2
0
def platform_detect():
    """Detect if running on the Raspberry Pi or Beaglebone Black and return the
    platform type.  Will return RASPBERRY_PI, BEAGLEBONE_BLACK, or UNKNOWN."""
    # Handle Raspberry Pi
    pi = pi_version()
    if pi is not None:
        return RASPBERRY_PI

    # Handle Beaglebone Black
    # TODO: Check the Beaglebone Black /proc/cpuinfo value instead of reading
    # the platform.
    plat = platform.platform()
    if plat.lower().find('armv7l-with-debian') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv7l-with-ubuntu') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv7l-with-glibc2.4') > -1:
        return BEAGLEBONE_BLACK
        
    # Handle Minnowboard
    # Assumption is that mraa is installed
    try: 
        import mraa 
        if mraa.getPlatformName()=='MinnowBoard MAX':
            return MINNOWBOARD
        elif mraa.getPlatformName()=='Intel Edison':
            return EDISON
    except ImportError:
        pass
    
    # Couldn't figure out the platform, just return unknown.
    return UNKNOWN
예제 #3
0
def platform_detect():
    """
    Method detects if platform is a supported platform
    """
    # Check if platform is Raspberry Pi
    pi = pi_version()
    if pi is not None:
        return RASPBERRY_PI

    # Check if platform is BeagleBone
    # Adafruit source mentions checking the /proc/cpuinfo rather than
    # the platform
    plat = platform.platform()
    if plat.lower().find('armv71-with-debian') > -1:
        return BEAGLEBONE_BLACK
    elif plat.lower().find('armv71-with-ubuntu') > -1:
        return BEAGLEBONE_BLACK  # Um... Isn't Ubuntu Debian?
    elif plat.lower().find('armv71-with-glibc2.4') > -1:
        return BEAGLEBONE_BLACK

    try:
        import mraa
        if mraa.getPlatformName()=='MinnowBoard MAX':
            return MINNOWBOARD
    except ImportError:
        pass
예제 #4
0
    def _detect_platform(self):
        """
        Detect if device is running on the Raspberry Pi, Beaglebone
        Black or MinnowBoard and return the platform type.
        """

        # Detect Raspberry Pi
        from robophery.utils.rpi import detect_pi_version
        pi = detect_pi_version()
        if pi is not None:
            return self.RASPBERRYPI_PLATFORM

        # Detect Beaglebone Black
        plat = platform.platform()
        if plat.lower().find('armv7l-with-debian') > -1:
            return self.BEAGLEBONE_PLATFORM
        elif plat.lower().find('armv7l-with-ubuntu') > -1:
            return self.BEAGLEBONE_PLATFORM
        elif plat.lower().find('armv7l-with-glibc2.4') > -1:
            return self.BEAGLEBONE_PLATFORM

        # Detect Minnowboard
        try:
            import mraa
            if mraa.getPlatformName() == 'MinnowBoard MAX':
                return self.MINNOWBOARD_PLATFORM
        except ImportError:
            pass

        # Detect NodeMCU
        try:
            import pyb
            return self.NODEMCU_PLATFORM
        except ImportError:
            pass

        # Could not detect the platform, returning generic linux.
        return self.LINUX_PLATFORM
예제 #5
0
def platform_detect():
    """Detect if running on the Raspberry Pi or Beaglebone Black and return the
    platform type.  Will return RASPBERRY_PI, BEAGLEBONE_BLACK, or UNKNOWN."""
    # Handle Raspberry Pi
    pi = pi_version()
    if pi is not None:
        return RASPBERRY_PI

    # Handle Beaglebone Black
    # TODO: Check the Beaglebone Black /proc/cpuinfo value instead of reading
    # the platform.

    # regex stuff here

    # Handle Minnowboard
    # Assumption is that mraa is installed
    try:
        import mraa

        if mraa.getPlatformName() == "MinnowBoard MAX":
            return MINNOWBOARD
    except ImportError:
        pass

    # Handle wiringX compatible device
    # Assumption is that wiringX is installed
    try:
        from wiringX import gpio as wxgpio

        if wxgpio.setup() != 0:
            return WIRINGX
    except ImportError:
        pass

    # Couldn't figure out the platform, just return unknown.
    return UNKNOWN
예제 #6
0
#!/usr/bin/env python

# Author: Costin Constantin <*****@*****.**>
# Copyright (c) 2015 Intel Corporation.
#
# SPDX-License-Identifier: MIT

from __future__ import print_function

import mraa as m
import unittest as u


@u.skipIf(m.getPlatformName() == "Unknown platform",
          "Not valid platform loaded")
class PlatformChecks(u.TestCase):
    pass


@u.skipUnless(m.getPlatformName() == "Intel Edison", "Only for edison Board")
class PlatformChecksEdison(u.TestCase):
    def test_mraa_check_platform_no_of_pins(self):
        pinCount = m.getPinCount()
        self.assertEqual(pinCount, 20,
                         "Wrong number. of pins. Check platform ...")

    def test_mraa_check_platform_ADC_max_resolution(self):
        self.p_ADC_mres = m.adcRawBits()
        print("Platform ADC max. resolution is: " + str(self.p_ADC_mres) +
              " bits")
        self.assertEqual(self.p_ADC_mres, 12,

    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)
예제 #8
0
# 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.

from __future__ import print_function

import mraa as m
import unittest as u

@u.skipIf(m.getPlatformName() == "Unknown platform", "Not valid platform loaded")
class PlatformChecks(u.TestCase):
  def test_mraa_check_platform_no_of_pins(self):
    pinCount = m.getPinCount()
    self.assertEqual(pinCount, 20, "Wrong number. of pins. Check platform ...")

  def test_mraa_check_platform_ADC_max_resolution(self):
    self.p_ADC_mres = m.adcRawBits()
    print("Platform ADC max. resolution is: " + str(self.p_ADC_mres) + " bits")
    self.assertEqual(self.p_ADC_mres, 12, "Wrong ADC max. resolution. Check platform ...")

  def test_mraa_check_platform_ADC_resolution(self):
    self.p_ADC_res = m.adcSupportedBits()
    print("Platform ADC resolution is: " + str(self.p_ADC_res) + " bits")
    self.assertEqual(self.p_ADC_res, 10, "Wrong ADC suported resolution. Check platform ...")
__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)
예제 #10
0
 def version(self):
     print (mraa.getVersion())
     print (mraa.getPlatformName())
     print (mraa.getPlatformType())
예제 #11
0
#
# 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.

from __future__ import print_function

import mraa as m
import unittest as u


@u.skipIf(m.getPlatformName() == "Unknown platform",
          "Not valid platform loaded")
class PlatformChecks(u.TestCase):
    def test_mraa_check_platform_no_of_pins(self):
        pinCount = m.getPinCount()
        self.assertEqual(pinCount, 20,
                         "Wrong number. of pins. Check platform ...")

    def test_mraa_check_platform_ADC_max_resolution(self):
        self.p_ADC_mres = m.adcRawBits()
        print("Platform ADC max. resolution is: " + str(self.p_ADC_mres) +
              " bits")
        self.assertEqual(self.p_ADC_mres, 12,
                         "Wrong ADC max. resolution. Check platform ...")

    def test_mraa_check_platform_ADC_resolution(self):
예제 #12
0
 def test_mraa_platform_name(self):
   self.p_name = m.getPlatformName()
   print "Platform name is: " + self.p_name
   self.assertIsNotNone(self.p_name)
예제 #13
0
import mraa
import time

print(mraa.getPlatformName())

x = mraa.Gpio(69)
x.dir(mraa.DIR_OUT)

while True:
	x.write(1)
	time.sleep(1)
	x.write(0)
	time.sleep(1)
예제 #14
0
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)

>>> import mraa
>>> import pyupm_htu21d
>>> import pyupm_mq135
>>> import pyupm_gas