Mraa and upm not working together

mezzanine

#1

I’m studying mezzanine programs and ucsd-coursera. In course 2 you have the clock.py program. Using python I’m having problems with mraa and upm working together.
My application finds both libraries: mraa and pyupm_i2clcd library.

I’ using this PATH
PYTHONPATH = $PYTHONPATH:/usr/lib/aarch64-linux-gnu/python2.7/site-packages

The buzzer line of the program is
buzzer = mraa.Gpio(27)

When it runs is returning and error saying:
File “clock.py”, line 10
buzzer = mraa.Gpio(27)

File “/usr/lib/python2.7/dist-packages/mraa.py” , line 675 in init
this = _mraa.new_Gpio(pin,owner,raw)
ValueError: Invalid GPIO pin specified

Can somebody help me with this?
Or al least tell me where can I read something about this please?


#2

@ric96 @Mani any advice on this one?


#3

Hi @gezamboni,

Python interface in MRAA is broke in some ways. Anyhow, as a quick workaround you might want to execute the script with “sudo” permissions for accessing GPIO (this is not MRAA python issue).

Please see: https://github.com/96boards/documentation/tree/master/consumer/guides/mraa/gpio

Thanks,
Mani


#4

Hi Mani,
Thank you very much for your reply.
I really think that this problem has to do with mraa being a low level library anf upm a high level library. That’s why I wrote a mraa and upm issue.
To explain the problem I’ll divide this issue in:
1.- Using mraa lib
2.- Using upm lib
3.- Using both libraries together

1.- Using mraa lib
If I write a program, as you asked for, using only mraa library as it is in your example at

either in C, C++ or python I don’t have any problem it works perfectly well. The program read or write to any Gpio pin you are using

2.- Using upm lib
If I write a program using only upm library as it is in the
Example Project - Temperature and Humidity Display
at

In this example you have a file “humid_temp.py” that calls pyupm_i2clcd.
I created a Makefile with the following:

include /usr/share/arduino/Arduino.mk
run: upload
python humid_temp.py

To run the program, you have to write the PYTHONPATH variable as writen below:

$ PYTHONPATH=$PYTHONPATH:/usr/lib/aarch64-linux-gnu/python2.7/site-packages
$ make run

and again it is working fine

3.- Using both libraries together
The problem really appears when using mraa and upm simultaneously as it is in the Alarm_Clock example of COURSERA - course 2

Here you have two files that work together
- ReadButton.ino
- clock.py

In the clock.py file you are calling the libraries below
import serial, pyupm_i2clcd, time, mraa

and here you meet the problem I am finding

To find the module pyupm_i2clcd I need to write the PYTHONPATH below to make the pyupm_i2clcd available.

$ PYTHONPATH=$PYTHONPATH:/usr/lib/aarch64-linux-gnu/python2.7/site-packages

If I don’t do it the program returns the error “module pyupm_i2clcd missing”

When I enter the PYTHONPATH and if I execute the script with “sudo” permissions for accessing GPIO happens that the program is returning the error below:

PROGRAM LINE

 The buzzer line of the program is
 buzzer = mraa.Gpio(27)

ERROR FOUND

 When it runs IT is returning and error saying:
    File “clock.py”, line 10
    buzzer = mraa.Gpio(27)

    File “/usr/lib/python2.7/dist-packages/mraa.py” , line 675 in init
    this = _mraa.new_Gpio(pin,owner,raw)
    ValueError: Invalid GPIO pin specified

so how can in Python Programming use mraa and upm together.
I understand that the first one is a low level package (so you need sudo permissions to run) and the second one you need the PYTHONPATH to be found.

What can I do to solve this situation?