4 Replies Latest reply: Mar 28, 2013 10:24 AM by Andy Tael-Oracle RSS

    Q:PeripheralTypeNotSupportedException on GPIO18

    Andy Tael-Oracle
      Hello,
      I have just started to tinker around with Oracle Java ME 3.3 on my Raspberry PI and having lot's of fun and an issue that I don't understand or how to solve.

      I am trying to turn on and off some LEDs just to learn about the DAAPI etc. My code looks like this (yes I know it can be written better but I am learning about the DAAPI for now):
      package rpiblinky;
      
      import com.oracle.deviceaccess.PeripheralManager;
      import com.oracle.deviceaccess.PeripheralNotAvailableException;
      import com.oracle.deviceaccess.PeripheralNotFoundException;
      import com.oracle.deviceaccess.PeripheralTypeNotSupportedException;
      import com.oracle.deviceaccess.gpio.GPIOPin;
      import java.io.IOException;
      import javax.microedition.midlet.*;
      
      /**
       * @author atael
       */
      public class IMlet extends MIDlet {
      
          private static final String LED1_NAME = "GPIO23";
          private static final String LED2_NAME = "GPIO24";
          private static final String LED3_NAME = "GPIO25";
          private static final String LED4_NAME = "GPIO18";
          private LED led1;
          private LED led2;
          private LED led3;
          private LED led4;
          boolean isStarted = false;
      
          public void startApp() {
              isStarted = true;
              System.out.println("*********************************");
              System.out.println("*   LED GPIO Sample (RPI Blinky)*");
              System.out.println("*********************************");
      
              led1 = new LED(LED1_NAME);
              led2 = new LED(LED2_NAME);
              led3 = new LED(LED3_NAME);
              led4 = new LED(LED4_NAME);
              try {
                  led1.open();
                  led2.open();
                  led3.open();
                  led4.open();
                  while (true) {
                      led1.changeValue();
                      Thread.sleep(50);
                      led2.changeValue();
                      Thread.sleep(50);
                      led3.changeValue();
                      Thread.sleep(50);
                      led3.changeValue();
                      Thread.sleep(50);
                      led2.changeValue();
                      Thread.sleep(50);
                      led1.changeValue();
                      Thread.sleep(50);
                  }
              } catch (IOException ex) {
                  ex.printStackTrace();
              } catch (PeripheralTypeNotSupportedException ex) {
                  ex.printStackTrace();
              } catch (PeripheralNotFoundException ex) {
                  ex.printStackTrace();
              } catch (PeripheralNotAvailableException ex) {
                  ex.printStackTrace();
              } catch (InterruptedException ex) {
                  ex.printStackTrace();
              }
      
          }
      
          public void pauseApp() {
          }
      
          public void destroyApp(boolean unconditional) {
              try {
                  isStarted = false;
                  led1.close();
                  led2.close();
                  led3.close();
                  led4.close();
              } catch (IOException ex) {
                  ex.printStackTrace();
              } catch (PeripheralNotAvailableException ex) {
                  ex.printStackTrace();
              }
          }
      
          public class LED {
      
              private String name;
              private GPIOPin led;
      
              LED(String name) {
                  this.name = name;
              }
      
              public void open() throws IOException, PeripheralTypeNotSupportedException,
                      PeripheralNotFoundException, PeripheralNotAvailableException {
                  led = (GPIOPin) PeripheralManager.open(name, GPIOPin.class, null);
              }
      
              public void changeValue() {
                  try {
                      boolean prevState = led.getValue();
                      led.setValue(!prevState);
                  } catch (IOException ex) {
                      ex.printStackTrace();
                  } catch (PeripheralNotAvailableException ex) {
                      ex.printStackTrace();
                  }
              }
      
              public void close() throws IOException, PeripheralNotAvailableException {
                  if (led != null) {
                      led.setValue(false);
                      led.close();
                  }
              }
          }
      }
      But when I run the application I get the following exception thrown:
      *********************************
      *   LED GPIO Sample (RPI Blinky)*
      *********************************
      [INFO] [UNKNOWN] gpio.c line 636: Try to open pin 23 on port 0 with direction 1
      [INFO] [UNKNOWN] gpio.c line 727: GPIO pin 23 open successfully done
      [INFO] [UNKNOWN] gpio.c line 636: Try to open pin 24 on port 0 with direction 1
      [INFO] [UNKNOWN] gpio.c line 727: GPIO pin 24 open successfully done
      [INFO] [UNKNOWN] gpio.c line 636: Try to open pin 25 on port 0 with direction 1
      [INFO] [UNKNOWN] gpio.c line 727: GPIO pin 25 open successfully done
      [AMS-TRACE] MIDlet:RPIBlinky status=2
      com.oracle.deviceaccess.PeripheralTypeNotSupportedException
       - com.oracle.deviceaccess.gpio.impl.GPIOPinImpl.openPinWithId0(), bci=0
       - com.oracle.deviceaccess.gpio.impl.GPIOPinImpl.open(), bci=57
       - com.oracle.deviceaccess.gpio.impl.GPIOManager.createPin(), bci=37
       - com.oracle.deviceaccess.gpio.impl.GPIOManager.openPin(), bci=12
       - com.oracle.deviceaccess.gpio.impl.GPIOManager.open(), bci=17
       - com.oracle.deviceaccess.impl.PeripheralManagerImpl.open(), bci=66
       - com.oracle.deviceaccess.PeripheralManager.open(), bci=4
       - rpiblinky.IMlet$LED.open(IMlet.java:105)
       - rpiblinky.IMlet.startApp(IMlet.java:44)
       - javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
       - com.sun.midp.midlet.MIDletPeer.startApp(), bci=5
       - com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=229
       - com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=38
       - com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=5
       - com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=121
       - com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
      [AMS-TRACE] MIDlet:RPIBlinky status=1
      But if I remove the GPIO18 (led4) from my code it executes just fine. Why wouldn't this work for me? GPIO18,GPIO23,GPIO24 and GPIO25 looks the same in the documentation:
      direction=GPIOPinConfig.DIR_OUTPUT_ONLY
      mode=GPIOPinConfig.MODE_OUPUT_PUSH_PULL
      trigger = ignored
      initValue=false
      I don't know where to start looking, what am I doing wrong here?

      Thanks
      Andy

      Edited by: A Tael on Mar 15, 2013 4:02 PM