Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » LED not blinking on Raspberry pi(LED not blinking on Raspberry pi using pi4j library)
icon5.gif  LED not blinking on Raspberry pi [message #1729028] Sat, 09 April 2016 18:01 Go to next message
Sindhu Priya is currently offline Sindhu PriyaFriend
Messages: 3
Registered: April 2016
Junior Member
We are referring to hello_osgi example at kura and writing a simple code to blink an LED. The code runs fine on raspberry pi when executed directly. But if we push it using kura, in log file it is showing expected results but the LED is not blinking.

Below is the snippet of the code we are using:

package iiit.wsl.led;

import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class Led {
	
	 private static final Logger s_logger = LoggerFactory.getLogger(Led.class);

	    private static final String APP_ID = "org.eclipse.kura.example.LED";
	    private GpioController gpio;
	    private GpioPinDigitalOutput pin;

	    protected void activate(ComponentContext componentContext) {

	    s_logger.info("<--Pi4J--> GPIO Control Example ... started.");
	         
	         // create gpio controller
	         final GpioController gpio = GpioFactory.getInstance();
	         
	         // provision gpio pin #01 as an output pin and turn on
	         final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_18, "MyLED", PinState.HIGH);

	         // set shutdown state for this pin
	         pin.setShutdownOptions(true, PinState.LOW);

	         s_logger.info("--> GPIO state should be: ON");

	         try {
				Thread.sleep(5000);
			
	         
	         // turn off gpio pin #01
	         pin.low();
	         s_logger.info("--> GPIO state should be: OFF");

	         Thread.sleep(5000);

	         // toggle the current state of gpio pin #01 (should turn on)
	         pin.toggle();
	         s_logger.info("--> GPIO state should be: ON");

	         Thread.sleep(5000);

	         // toggle the current state of gpio pin #01  (should turn off)
	         pin.toggle();
	         s_logger.info("--> GPIO state should be: OFF");
	         
	         Thread.sleep(5000);

	         // turn on gpio pin #01 for 1 second and then off
	         System.out.println("--> GPIO state should be: ON for only 1 second");
	         pin.pulse(1000, true); // set second argument to 'true' use a blocking call
	         
	         // stop all GPIO activity/threads by shutting down the GPIO controller
	         // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
	         gpio.shutdown();
	        
	       
	    } catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    } 

	    protected void deactivate(ComponentContext componentContext) {

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

	    }

}




What mistake are we doing?
  • Attachment: Led.java
    (Size: 2.51KB, Downloaded 211 times)
Re: LED not blinking on Raspberry pi [message #1729953 is a reply to message #1729028] Wed, 20 April 2016 13:24 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

I would first make sure that all bundles and components are satisfied within the OSGi framework. To do this, connect to the OSGi console and issue the 'ss' and 'ls' commands. All of your bundles and components should be active.

Is there a requirement that you use Pi4J? Kura comes with the jdk.dio library that would allow you to access the GPIO pins. This would likely be a lot easier for development.

Thanks,
--Dave
Re: LED not blinking on Raspberry pi [message #1780732 is a reply to message #1729028] Fri, 26 January 2018 11:51 Go to previous messageGo to next message
LI Yi is currently offline LI YiFriend
Messages: 37
Registered: June 2017
Member
Hi , I have met the same problem . Any advices on this problem?
Re: LED not blinking on Raspberry pi [message #1782767 is a reply to message #1729953] Thu, 01 March 2018 08:08 Go to previous message
Ahmed Gharssellaoui is currently offline Ahmed GharssellaouiFriend
Messages: 31
Registered: February 2018
Member
Hello Dave,
I just started with eclipse Kura, I am currently using 3.1.1 version
I have tried using the jdk.dio library in kura as it was described in the documentation but I couldn't find it.
What dependency should I add to include it ? Knowing I couldn't find jdk.dio
Previous Topic:Eclipse kura Installaton
Next Topic:how to resolve jdk.dio-CloseDeviceException
Goto Forum:
  


Current Time: Tue Apr 23 10:14:49 GMT 2024

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

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

Back to the top