Mraa and upm not working together

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?

@ric96 @Mani any advice on this one?

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

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?

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

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”.

1 Like

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

@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.

Does the official example from the UPM repository work correctly?

"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"

For the dragonboard 410c, the values that we see in examples should be changed by adding an offet of 390.
To get the correct value, you can check with midnight commander (sudo apt install mc).
Midnight commander is a very convenient file manager on the console. It works fine on the Dragonboard.
On the command line:
cd /sys/class/gpio
ls
cd gpiochip390
ls
cat ngpio
It gives 122, the other 2 chips give 4.
cat base
It gives 390

So all the old docs should be converted:
user led 1 | 21 | 411
user led 2 | 120 | 510
user led 3 | 1 | 1 + 382 OR 386 (UNTESTED)
user led 4 | 2 | 2 + 382 OR 386 (UNTESTED)

D410c | Mezz | GPIO | OLD | NEW
------±-----±-------±----±----
J8.23 | G1.1 | GPIO A | 36 | 426
J8.24 | G1.2 | GPIO B | 12 | 402
J8.25 | (NA) | GPIO C | 13 | 403
J8.26 | (NA) | GPIO D | 69 | 459
J8.27 | G2.1 | GPIO E | 115 | 505
J8.28 | G2.2 | GPIO F | 4 | 4 + 382 OR 386 (UNTESTED)
J8.29 | G3.1 | GPIO G | 24 | 414
J8.30 | G3.2 | GPIO H | 25 | 415
J8.31 | G4.1 | GPIO I | 35 | 425
J8.32 | G4.2 | GPIO J | 34 | 424
J8.33 | G5.1 | GPIO K | 28 | 418
J8.34 | G5.2 | GPIO L | 33 | 423