abhi143
Posts: 109
Joined: Mon Oct 30, 2017 4:17 am

Blinking LED on Raspberry Pi using Java

Mon Jan 01, 2018 2:22 pm

I want to blink led on Raspberry Pi using Java. I am following this link http://www.admfactory.com/blinking-led- ... sing-java/ There is information about the Pi4J library. I understand I have to install Pi4J library.

I think only Pi4J library is not enough to to write and compile java program. there will be java IDE to write and compile program. I don't find any information about java IDE in link. Can someone tell me which one java IDE is being use in the given link ?

Heater
Posts: 8612
Joined: Tue Jul 17, 2012 3:02 pm

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 01, 2018 2:42 pm

You don't need an IDE to write and compile a Java program. Or any other language for that matter. Any old editor will do.

abhi143
Posts: 109
Joined: Mon Oct 30, 2017 4:17 am

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 01, 2018 4:42 pm

Heater wrote:
Mon Jan 01, 2018 2:42 pm
You don't need an IDE to write and compile a Java program. Or any other language for that matter. Any old editor will do.
I have written and save java program using nano editor now how to run program on Pi.

User avatar
DougieLawson
Posts: 31211
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 01, 2018 5:03 pm

nano /home/pi/java/programname.java

Code: Select all

public class programname
{
  public static void main(String[] args)
  {
    System.out.println("Hello Java World");
  }
}
cd ~/java
javac programname.java
java programname
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

abhi143
Posts: 109
Joined: Mon Oct 30, 2017 4:17 am

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 01, 2018 5:38 pm

I am getting some errors I think Pi4J library has not installed correctly
I was running following command
$ curl -s get.pi4j.com | sudo bash

pi@raspberrypi:~ $ javac led.java
led.java:1: error: package com.pi4j.io.gpio does not exist
import com.pi4j.io.gpio.GpioController;
^
led.java:2: error: package com.pi4j.io does not exist
import com.pi4j.io.GpioFactory;
^
led.java:3: error: package com.pi4j.io.gpio does not exist
import com.pi4j.io.gpio.GpioPinDigitalOutput;
^
led.java:4: error: package com.pi4j.io.gpio does not exist
import com.pi4j.io.gpio.RaspiPin;
^
led.java:10: error: cannot find symbol
final GpioController gpio = GpioFactory.getInstance();
^
symbol: class GpioController
location: class led
led.java:10: error: cannot find symbol
final GpioController gpio = GpioFactory.getInstance();
^
symbol: variable GpioFactory
location: class led
led.java:12: error: cannot find symbol

User avatar
DougieLawson
Posts: 31211
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 01, 2018 6:05 pm

Take a look at /opt/pi4j/examples/build which shows you how to build a pi4j Java program.

javac -classpath .:classes:/opt/pi4j/lib/'*' -d . /home/pi/java/pi4jprogram.java

Then you run it with
WIRINGPI_GPIOMEM=1 java -classpath /opt/pi4j/lib/pi4j-core.jar:. pi4jprogram
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

abhi143
Posts: 109
Joined: Mon Oct 30, 2017 4:17 am

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 15, 2018 3:03 pm

DougieLawson wrote:
Mon Jan 01, 2018 6:05 pm
Take a look at /opt/pi4j/examples/build which shows you how to build a pi4j Java program.

javac -classpath .:classes:/opt/pi4j/lib/'*' -d . /home/pi/java/pi4jprogram.java

Then you run it with
WIRINGPI_GPIOMEM=1 java -classpath /opt/pi4j/lib/pi4j-core.jar:. pi4jprogram
What is meaning of this error
pi@raspberrypi:~ $ sudo nano BlinkingLed.java
pi@raspberrypi:~ $ sudo javac BlinkingLed.java -classpath .:/opt/pi4j/lib/'*'
pi@raspberrypi:~ $ sudo javac BlinkingLed.java -classpath .:/opt/pi4j/lib/'*'
pi@raspberrypi:~ $ sudo java -cp .:/opt/pi4j/lib/'*' BlinkingLed
Unable to determine hardware version. I see: Hardware : BCM2835
,
- expecting BCM2708 or BCM2709.
If this is a genuine Raspberry Pi then please report this
to projects@drogon.net. If this is not a Raspberry Pi then you
are on your own as wiringPi is designed to support the
Raspberry Pi ONLY.

User avatar
DougieLawson
Posts: 31211
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 15, 2018 5:28 pm

Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

Return to “Java”

Who is online

Users browsing this forum: No registered users and 4 guests