Note that there are some explanatory texts on larger screens.

plurals
  1. PORaspberry pi flashing LED issue - Python vs Java
    primarykey
    data
    text
    <p>i am trying to make an LED light flash on the raspberry pi using some code i found online ( i know - not the best but it was a tutorial site)</p> <p>When i run the following python code the led light flashes;</p> <pre><code>import RPi.GPIO as GPIO import time pinNum = 4 GPIO.setmode(GPIO.BCM) #numbering scheme that corresponds to breakout board and pin layout GPIO.setup(pinNum,GPIO.OUT) #replace pinNum with whatever pin you used, this sets up that pin as an output #set LED to flash forever while True: GPIO.output(pinNum,GPIO.HIGH) time.sleep(0.5) GPIO.output(pinNum,GPIO.LOW) time.sleep(0.5) </code></pre> <p>When i run the following Java code which is supposed to do the same - all i get to the console are the print statements which i have added - no flashing light</p> <pre><code>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 ControlGpioExample { public static void main(String[] args) throws InterruptedException { final GpioController gpio = GpioFactory.getInstance(); final GpioPinDigitalOutput ledPin = gpio.provisionDigitalOutputPin(RaspiPin .GPIO_04, "MyLED", PinState.LOW); System.out.println("Started"); try { while(true) { System.out.println(ledPin==null); System.out.println("Looping pin now"); ledPin.high(); System.out.println("Set high called"); Thread.sleep(2000); ledPin.low(); System.out.println("Set low called"); Thread.sleep(2000); } } catch(Exception ex) { gpio.shutdown(); ex.printStackTrace(); } } } </code></pre> <p>Does anyone know why this might be? I think logically the should be doing the same thing - both are using the same GPIO pin number from the pi too</p> <p>Thanks for your help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload