summaryrefslogtreecommitdiff
path: root/gpiotest/writer.py
blob: 7a2db2f7e1a51f0f5524e8b6c52164e133231931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
This is a simple GPIO manipulation program. It works together
with Sensor board mezzanine and arduino program. The program writes
value 1 (HIGH) to GPIO_A which should be connected to arduino
digital pin 4. Than it reads value from GPIO_B which should be connected
to arduino digital pin 5.
"""

import mraa
import unittest
from time import sleep

class GpioTestCase(unittest.TestCase):
    def setUp(self):
        # GPIO_A on 96boards
        self.output = mraa.Gpio(23)
        self.output.dir(mraa.DIR_OUT)

        # GPIO_B on 96boards
        self.input = mraa.Gpio(24)
        self.input.dir(mraa.DIR_IN)

    def test_gpio_initial_value(self):
        print "Initial input value: %s" % self.input.read()
        self.assertEqual(self.input.read(), 0)

    def test_gpio_write_high(self):
        self.output.write(1)
        sleep(10)
        print "First read input value (expecting 1): %s" % self.input.read()
        self.assertEqual(self.input.read(), 1)

    def test_gpio_write_low(self):
        self.output.write(0)
        sleep(10)
        print "Second read input value (expecting 0): %s" % self.input.read()
        self.assertEqual(self.input.read(), 0)


if __name__ == '__main__':
    print (mraa.getVersion())
    unittest.main(verbosity=2, buffer=True)