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?


#5

I struggled into the same issue in ucsd-coursera, course 2 while trying to setting up for the alarm_clock program.
Following on above suggestion: running python as sudo, resolves the error “invalid GPIO pin” specified. However the other error, several times reported on, returns: “no module pyupm_i2clcd”.

All prior suggestions, in several posts, I have entertained, but finally I had to resort to finding the 2 relevant pyupm files in /usr/lib/aarch64-linux-gnu/python2.7, and just copying them to the working directory containing the clock.py file.

In the py program:
import pyupm.i2clcd

Any suggestions on how to avoid such a brute force?

thanks and greetings, Frank


#6

MRAA (v1.9.0) and UPM (v1.6.0) packages have been upgraded in Debian buster. Please try to upgrade these packages using following cmd:

sudo apt upgrade python-upm

With updated packaged you don’t need to set PYTHONPATH. Following cmds worked fine for me:

>>> import mraa
>>> import upm
>>> from upm import pyupm_lcd

Note: In latest upstream version “pyupm_i2clcd” module has been renamed to “pyupm_lcd”.


#7

Thanks, and so far so good! Newest version upm 1.6.0. installed.
I followed your instructions and changed pyupm_i2clcd into pyupm_lcd. It works in command << mode and no missing library is found.

However the program runs into an error:
line… in
lcd = pyupm_lcd.Jhd1313m1(0, 0x3E, 0x62)
AttributeError: ‘module’ object has no attribute ‘Jhd1313m1’

Triggered by new upm 1.60, I found a solution for this in its documentation, with a new module:
from upm import pyupm_jhd1313m1
and consequently initialization of Grove LCD device in the python file:
lcd = pyupm.jhd1313m1.Jhd1313m1(0, 0x3E, 0x62)

This appears to work fine.

Thanks,
greetings Frank


#8

@fwaltena Nice to hear that upm v1.6.0 worked fine for you.

@Mani I think we need to update 96boards docs as per latest UPM and MRAA packages.


#9

Does the official example from the UPM repository work correctly?