Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Issues with GPIO connection Kura/Eclipse(I have issues using or programming gpio connections on my raspberry pi)
Issues with GPIO connection Kura/Eclipse [message #1785534] Mon, 16 April 2018 12:23 Go to next message
Nino Klajnšek is currently offline Nino KlajnšekFriend
Messages: 7
Registered: April 2018
Junior Member
I'm using the newest kura release (3.1.1. i think) and been following a few tutorials. I've finished the getting started "hello osgi" "eclipse.github documentation" and successfully installed the bundle on my rpi. That means i get the message that the bundle started, so that is working fine, let's move on to the GPIO part.

I've downloaded a configuration bundle demo from eclipse marketplace (https://marketplace.eclipse.org/content/gpio-example-eclipse-kura) entered the PIN that the LED is installed on and it works. I also used python to turn the led on which works fine. So the problem is with the Eclipse IDE or my understanding of it.

As said i've followed the tutorial multiple times for Eclipse installation configuration. A few problems I came about when I was "debugging" myself.

-The new version of user-workspace-archives doesn't containt the jdk.dio which is used in every single tutorial and seems easy enough. I've tried to add the jdk myself but couldn't get it to work. I tried most of the combinations, adding it to the manifest.mf build and to the target definition platform and so on. I came to the "import unresolved: jdk.dio etc.."

-After I gave up on jdk.dio, I found out Kura added their own library KuraGpio in gpio.emulator i think it is. Which gives me a nullpointer when trying to obtain gpioService to get aquire the pins.

I can't really find a new or working tutorial which i can understand and build upon. I'm getting kinda hopeless, so if anyone can help I would be greatful.

PS: I didn't paste any code or errors since most if it is following the tutorial and when debugging myself found that the basics work, but I can do so if needed.

Edit: I actually got it to publish with adding bundle-classpath to my manifest file. But now Kura just crashes when i try to retrieve a pin (either pi4j or dio), error something along: "dio/pi4j not found as a library. But the bundle is active it just doesn't work (it doesn't get past the gpio variables, so the logger doesn't "log")

[Updated on: Tue, 17 April 2018 15:40]

Report message to a moderator

Re: Issues with GPIO connection Kura/Eclipse [message #1785701 is a reply to message #1785534] Wed, 18 April 2018 14:45 Go to previous messageGo to next message
Pierantonio Merlino is currently offline Pierantonio MerlinoFriend
Messages: 39
Registered: March 2016
Member
Hi.

I'm a bit confused... What are you trying to do?

If you want to use the GPIOs under Eclipse IDE, there is the org.eclipse.kura.emulator.gpio that provides some emulated gpios. So, running the emulator from Eclipse you can get a GPIOService that provides your application some fake pins.

You can test your application using the emulator and then deploy it on a real device.
You don't need to modify your application to run in to the device, since it'll get the GPIOService provided by Kura, instead of the emulated one.

Best,
Pierantonio
Re: Issues with GPIO connection Kura/Eclipse [message #1785709 is a reply to message #1785701] Wed, 18 April 2018 16:42 Go to previous messageGo to next message
Nino Klajnšek is currently offline Nino KlajnšekFriend
Messages: 7
Registered: April 2018
Junior Member
Thanks for the reply!

I have windows and trying to minimize programs on my computer decided not to go the docker emulator route.

So i'm testing my app on the rpi. As said when I use GPIOService or try to get the instance (set and unset methods) I get a nullpointer. So GPIOService is always NULL.

I think I don't get the abstraction of kura yet. Basically running the simple hello_osgi (that only outputs into logger) work and I modified it to call GPIOService to get the pin to test my LED before I start actually doing my project.

package org.eclipse.kura.example.hello_world;

import org.eclipse.kura.gpio.GPIOService;
import org.eclipse.kura.gpio.KuraGPIOPin;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloWorld {

    private static final Logger s_logger = LoggerFactory.getLogger(HelloWorld.class);

    private static final String APP_ID = "org.eclipse.kura.example.hello_osgi";
    private GPIOService gpioService;

    public void setGPIOService(GPIOService gpioService) {
        this.gpioService = gpioService;
    }

    public void unsetGPIOService(GPIOService gpioService) {
        gpioService = null;
    }

    protected void activate(ComponentContext componentContext) {
        KuraGPIOPin pin = gpioService.getPinByTerminal(1);
        s_logger.info("Bundle " + APP_ID + " has started!");

    }

    protected void deactivate(ComponentContext componentContext) {

        s_logger.info("Bundle " + APP_ID + " has stopped!");

    }

}


So i added the code. I expected Kura to give access to gpioService inside of a simple activate method or does it have to be a configurable plugin? This is the part that I don't understand.

Re: Issues with GPIO connection Kura/Eclipse [message #1785710 is a reply to message #1785701] Wed, 18 April 2018 16:42 Go to previous messageGo to next message
Nino Klajnšek is currently offline Nino KlajnšekFriend
Messages: 7
Registered: April 2018
Junior Member
Thanks for the reply!

I have windows and trying to minimize programs on my computer decided not to go the docker emulator route.

So i'm testing my app on the rpi. As said when I use GPIOService or try to get the instance (set and unset methods) I get a nullpointer. So GPIOService is always NULL.

I think I don't get the abstraction of kura yet. Basically running the simple hello_osgi (that only outputs into logger) work and I modified it to call GPIOService to get the pin to test my LED before I start actually doing my project.

package org.eclipse.kura.example.hello_world;

import org.eclipse.kura.gpio.GPIOService;
import org.eclipse.kura.gpio.KuraGPIOPin;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloWorld {

    private static final Logger s_logger = LoggerFactory.getLogger(HelloWorld.class);

    private static final String APP_ID = "org.eclipse.kura.example.hello_osgi";
    private GPIOService gpioService;

    public void setGPIOService(GPIOService gpioService) {
        this.gpioService = gpioService;
    }

    public void unsetGPIOService(GPIOService gpioService) {
        gpioService = null;
    }

    protected void activate(ComponentContext componentContext) {
        KuraGPIOPin pin = gpioService.getPinByTerminal(1);
        s_logger.info("Bundle " + APP_ID + " has started!");

    }

    protected void deactivate(ComponentContext componentContext) {

        s_logger.info("Bundle " + APP_ID + " has stopped!");

    }

}


So i added the code. I expected Kura to give access to gpioService inside of a simple activate method or does it have to be a configurable plugin? This is the part that I don't understand.

Re: Issues with GPIO connection Kura/Eclipse [message #1785738 is a reply to message #1785710] Thu, 19 April 2018 08:18 Go to previous messageGo to next message
Pierantonio Merlino is currently offline Pierantonio MerlinoFriend
Messages: 39
Registered: March 2016
Member
Hi,

have you added the GPIOService dependency on the component definition file? You should have something like this [1].

Best,
Pierantonio

[1] https://github.com/eclipse/kura/blob/release-3.1.0/kura/examples/org.eclipse.kura.example.gpio/OSGI-INF/gpio.xml
Re: Issues with GPIO connection Kura/Eclipse [message #1785748 is a reply to message #1785738] Thu, 19 April 2018 10:40 Go to previous messageGo to next message
Nino Klajnšek is currently offline Nino KlajnšekFriend
Messages: 7
Registered: April 2018
Junior Member
Hi,
Thanks, that actually got me further. But i'm still stuck.
package org.eclipse.kura.example.hello_world;

import java.io.IOException;

import org.eclipse.kura.gpio.GPIOService;
import org.eclipse.kura.gpio.KuraGPIODeviceException;
import org.eclipse.kura.gpio.KuraGPIODirection;
import org.eclipse.kura.gpio.KuraGPIOMode;
import org.eclipse.kura.gpio.KuraGPIOPin;
import org.eclipse.kura.gpio.KuraGPIOTrigger;
import org.eclipse.kura.gpio.KuraUnavailableDeviceException;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloWorld {

    private static final Logger s_logger = LoggerFactory.getLogger(HelloWorld.class);

    private static final String APP_ID = "org.eclipse.kura.example.hello_osgi";
    private GPIOService gpioService;

    public void setGPIOService(GPIOService gpioService) {
        this.gpioService = gpioService;
    }

    public void unsetGPIOService(GPIOService gpioService) {
        gpioService = null;
    }

    protected void activate(ComponentContext componentContext) {
        KuraGPIOPin pin = gpioService.getPinByTerminal(5);
        KuraGPIOPin customInputPin = gpioService.getPinByTerminal(5, KuraGPIODirection.INPUT,
                KuraGPIOMode.INPUT_PULL_UP, KuraGPIOTrigger.BOTH_LEVELS);
        try {
            pin.open();
            customInputPin.open();
        } catch (KuraGPIODeviceException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } catch (KuraUnavailableDeviceException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }

        s_logger.info("     " + "Bundle " + APP_ID + " has started!");

    }

    protected void deactivate(ComponentContext componentContext) {

        s_logger.info("Bundle " + APP_ID + " has stopped!");

    }

}

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="org.eclipse.kura.example.hello_world" enabled="true"
    immediate="true">
   <implementation class="org.eclipse.kura.example.hello_world.HelloWorld"/>
   
   <reference name="GPIOService" 
              cardinality="1..1" 
              policy="static"
              bind="setGPIOService"
              unbind="unsetGPIOService"
              interface="org.eclipse.kura.gpio.GPIOService"/>
</scr:component>



I cannot post the error because it's on my other PC but no Pin is availible.Even if i itirate trough all availible pins all are "empty" so there are non availible.
Re: Issues with GPIO connection Kura/Eclipse [message #1785924 is a reply to message #1785748] Mon, 23 April 2018 07:47 Go to previous messageGo to next message
Pierantonio Merlino is currently offline Pierantonio MerlinoFriend
Messages: 39
Registered: March 2016
Member
Hi,

could you please post the error messages?
Which device are you using?
Finally, are you sure that the pin 5 is available on your device?
Re: Issues with GPIO connection Kura/Eclipse [message #1785926 is a reply to message #1785924] Mon, 23 April 2018 08:22 Go to previous messageGo to next message
Nino Klajnšek is currently offline Nino KlajnšekFriend
Messages: 7
Registered: April 2018
Junior Member
Thanks for taking the time to reply!

I've actually done alot of stuff trying to debug/fix my problem and I didn't log any of it because most of it was redundant.

Basically to access the GPIOService go to OSGI-INF -> your_component.xml and under services add GPIOService as Referenced services. (That's for anyone with the same issue)

I've had my LED on GPIO18 (GPIO_GEN1) and it didn't work. "Device 18 is unavailible", even tho it is availible trough simple python script. I've tried to test my bundle on exported "echo 18 > export" gpio (under sys/classes/gpio) and unexported both with same (negative) result. Then I moved my LED to the bottom pin number: 21 (pysical pin number: 40) and it actually works.
I'm not sure why I didn't try moving the pins around more sooner but I did now and it works.

If you have any info why gpio18 would be unavailible that would be great I might need it in my project. But atleast I know everything is good with my kura and rpi.

Thanks for the help and any future anwser!
Re: Issues with GPIO connection Kura/Eclipse [message #1785934 is a reply to message #1785926] Mon, 23 April 2018 10:13 Go to previous messageGo to next message
Pierantonio Merlino is currently offline Pierantonio MerlinoFriend
Messages: 39
Registered: March 2016
Member
It's quite strange that the gpio18 doesn't work... I'll take a try with that gpio.
Thank you for the feedback!

FYI, here [1] is the jdk.dio property file used by Kura to get the default gpios available on the RPi. Finally, if you are interested in Kura Wires, the last Kura release supports also a Driver for GPIOs [2].

[1] https://github.com/eclipse/kura/blob/develop/kura/distrib/src/main/resources/raspberry-pi-2/jdk.dio.properties
[2] https://marketplace.eclipse.org/content/gpio-driver-eclipse-kura
Re: Issues with GPIO connection Kura/Eclipse [message #1786128 is a reply to message #1785934] Wed, 25 April 2018 21:24 Go to previous messageGo to next message
Nino Klajnšek is currently offline Nino KlajnšekFriend
Messages: 7
Registered: April 2018
Junior Member
Yeah, I'm looking at any way to complete my "solution". But I'm used to java and everything new complicates things alot for me.
I know this next question shouldn't be asked here but since you were already so kind.

How do I come to a place where I can solve some issue that come up in Kura. The Documentation is outdated (it doesn't use pi4j, it doesn't use dio anymore but some kind of extract of them). So I can turn on/off the LED, but can't find (like really Can't find) any documentation on how to read sensors with the new org.kura.gpio. How should I even approach adding DHT22, LED and PIR sensor. I can read it simply with python, but can't seem to do it with java in Kura. I'm just lost, i feel like i exhausted every single source i found.

Thanks, you've helped alot!
Re: Issues with GPIO connection Kura/Eclipse [message #1786296 is a reply to message #1786128] Mon, 30 April 2018 08:43 Go to previous message
Ahmed Gharssellaoui is currently offline Ahmed GharssellaouiFriend
Messages: 31
Registered: February 2018
Member
Hi Nino,

I went through some problems too when I started with Kura due the outdated documentation of GPIOs.
Well, like you said you need to use the Kura.api to access the GPIO.
If you can manage using the GPIOs then you can started testing some sensors, at that point it's not so related to Kura, if you know embedded programming you will be able to manage it.
Kura support I2C communication too which will be essential for you since kura (basically the RPI) don't have an analog input to directly communicate with the sensors like DHT22, PIR ...
So you will have to go through I2C or serial communication maybe.

Regards
Ahmed Gharssellaoui
Previous Topic:Issue with kura installation on Raspberry Pi 2
Next Topic:MQTT message not writing to asset
Goto Forum:
  


Current Time: Tue Apr 23 12:39:34 GMT 2024

Powered by FUDForum. Page generated in 0.03958 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top