abhi143
Posts: 133
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: 16318
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.
Memory in C++ is a leaky abstraction .

abhi143
Posts: 133
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: 39589
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

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
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

abhi143
Posts: 133
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: 39589
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

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
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

abhi143
Posts: 133
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: 39589
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Blinking LED on Raspberry Pi using Java

Mon Jan 15, 2018 5:28 pm

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Return to “Java”