Gemalto is now part of the Thales Group, find out more.

You are here

Thales IoT Developer Community

ConceptBoard: Java GPIO lib

Tutorial, April 23, 2014 - 8:17pm, 10615 views

Using external GPIOs with JavaME - A library for Gemalto ConceptBoard and Gemalto Luna2 Terminal


The external GPIOs on the Gemalto Concept Board and the Gemalto Luna2 Terminal operate at a different logical level (5 volts) than the Cinterion Module’s GPIO pins (1.8 volts). The level conversion is performed by directional level shifters. To switch the direction, the module sends I2C commands to a co-processor, controlling the level shifter directions.

In order to transparently use the external GPIOs in JavaME code from within the Module, you can use our GPIO library. It takes care of properly setting the level shifter directions.


  • Gemalto EHSx Software Development Kit
  • Concept Board or Luna2 Terminal
  • GPIOlib

GPIOlib files

  • Hardware dependent factory to create instances of the In- and OutPort5V
  • Encapsulation of InPort class that automatically adjusts the level shifter directions
  • Encapsulation of OutPort class that automatically adjusts the level shifter directions

Create demo application

First create a new JavaME Project and import the GPIOlib-files (,,

We then create our main MIDlet (e.g.  “”).

 import gpio.GPIO5V_Factory;
import gpio.InPort5V;
import gpio.OutPort5V;

import java.util.Vector;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class Test_routine extends MIDlet {

  public Test_routine() {
    // TODO Auto-generated constructor stub

  protected void destroyApp(boolean unconditional)
      throws MIDletStateChangeException {

  protected void pauseApp() {
    // TODO Auto-generated method stub

  protected void startApp() throws MIDletStateChangeException {

The next step is to create a simple test routine.

  private void test() {
    InPort5V inPort = null;
    OutPort5V outPort = null;
    GPIO5V_Factory factory = new GPIO5V_Factory(GPIO5V_Factory.CONCEPT); 

We create a GPIO5V_Factory for either the Luna2 Terminal or the ConceptBoard. In the next step, this factory is used to instantiate InPort5V and OutPort5V objects.

 try {
      int counter = 0;
      Vector outPins = new Vector(1);
      Vector values = new Vector(1);
      outPort = factory.getOutPort5V(outPins, values);
      try {
	} catch (InterruptedException e2) {
		// TODO Auto-generated catch block
      Vector inPins = new Vector(1);
      inPort = factory.getInPort5V(inPins);
      while (counter < 4) {
        System.out.print(counter + "; OutPort: " + counter % 2);
        try {
        } catch (IOException e1) {
        try {
          System.out.println("; InPort: " + inPort.getValue());
        } catch (IOException e) {
        try {
        } catch (InterruptedException e) {
        counter = 1 + counter;
    } catch (IOException e) {

First, two vectors are defined and filled with one element each. These are the pin id and the initial value (0=low, high=1) for the OutPort to be created by the factory. In order to ensure that the I2C commands to adjust the level shifters were executed by the co-processor, we sleep for 1 second before setting up the input ports.

For the input port we only define the pin id and no initial state.

The while loop repeats four ***** following steps:

  1.  Print out the current cycle + the value the pin will be set to (counter %2)
  2. Set the output pin to the value of the counters LSB
  3. Print out the current input value of the defined input pin.
  4. Sleep
  5. Increment counter

Finally the previously used ports are released.

The last Step to launch our test routine from within the startApp() method.

 protected void startApp() throws MIDletStateChangeException {

Run demo application

Now you just have to load the compiled program to your board and start the application. You will see GPIO6 being toggled and GPIO7 being read out every two seconds.

Further information

The library and the test routine are attached to this post. For further information please refer to our Java Documentation.

Please feel free to share your experience with the GPIOlib in the developer community.

I just tried the library and works like a charm.

But I still have a question. What if we want to set a GPIO to 1 until we disable it?

Is there any AT command or piece of code to do so?

I've implemented a solution using ATCommand:

 public static void on(final int num){
		ATCommand atc = null;
		try {
			atc = new ATCommand(false);
			atc.send("at^scpin=0,"+(num-1)+",0,0 \r");
		} catch (Exception e) {
			try {
				System.out.println("GPIO"+num+" on");
			} catch (Exception e) {


You could re-write your on() method as below:

Note: I have released the GPIO resource for cleanliness in on(). You must at least release it by the time you get to destroyApp() else it will be blocked until the next time the module restarts.


We have released an updated version of the library with comments and documentation references.

We also implemented the on() example above using the library.

I do hope this helps :)


we are using GPIO pins 7 and 8 .

Its working on EHSx module with our board

and working with concept board B80 and BGS5

but not working with our board and BGS5

its resetting module.

can u plz suggest on this,

Does the code works if I'm using the EHS6 with the Starter KIT B80?

Worked with the Concept Board (EHS6). It's suposed to work also with the Starter Kit


With the B80 starter kit there is no need for this code.

It is only needed on (i) the EHSx Concept board or (ii) the EHSxT terminals where we have I2C controlled level convertors to protect the module's GPIOs from external devices/equipment.

Best regards


If you would like examples of "bare" GPIO usage then have a look at either the "Windmill" demo or "X-Nucleo" (with SensorLogic) demo and their (input) and (output) classes.

Best regards


Now updated to allow EHSx Terminals to output digital voice over the PCM/DAI interface.


Paul Mock's picture
Paul Mock