RPi with an Oscilloscope and Java Embedded: Ready for Benchmarking (Part 6)

Well, the best laid plans of Raspberry Pi, Java Embedded and all that. There's some type of device access issue on the Raspberry Pi when trying to NIO memory map /dev/mem. So, I'm going to have take some time to debug that.

Instead let's go back to what we know works. Using pure Java Embedded API's we can use the file handle to get to the GPIO pins for access. So, let's roll back and start there again and incrementally move toward trying to match what we should be able to do with NIO.

Here's the code that we will roll back to. You can try this at home to see what type of speed you can get on your oscilloscope. I'll report what I have also.

/*
 * Example Code
 */

/*
 * Java Embedded Raspberry Pi Servo app
 */
package jerpitest;

import java.io.FileWriter;
import java.io.File;

/**
 *
 * @author hinkmond
 */
public class GPIOMaxRate {
    
    static final String GPIO_OUT = "out";
    static final String GPIO_ON = "1";
    static final String GPIO_OFF = "0";
    
    static String[] GpioChannels =  { "24" };

    /**
     * @param args the command line arguments
     */
    @SuppressWarnings("UseSpecificCatch")
    public static void main(String[] args) {
        FileWriter[] commandChannels;
        
        try {
            
            /*** Init GPIO port for output ***/
            
            // Open file handles to GPIO port unexport and export controls
            FileWriter unexportFile = 
                    new FileWriter("/sys/class/gpio/unexport");
            FileWriter exportFile = 
                    new FileWriter("/sys/class/gpio/export");

            // Loop through all ports if more than 1
            for (String gpioChannel : GpioChannels) {
                System.out.println(gpioChannel);
    
                // Reset the port, if needed
                File exportFileCheck = 
				new File("/sys/class/gpio/gpio"+gpioChannel);
                if (exportFileCheck.exists()) {
                    unexportFile.write(gpioChannel);
                    unexportFile.flush();
                }
            
                // Set the port for use
                exportFile.write(gpioChannel);   
                exportFile.flush();

                // Open file handle to port input/output control
                FileWriter directionFile =
                    new FileWriter("/sys/class/gpio/gpio" + gpioChannel + 
                        "/direction");
            
                // Set port for output
                directionFile.write(GPIO_OUT);
                directionFile.flush();
            }
            
            /*** Send fastest on/off to GPIO port ***/
            
            // Set up a GPIO port as a command channel
            FileWriter commandChannel = new 
			FileWriter("/sys/class/gpio/gpio" +
              	GpioChannels[0] + "/value");
            
            // Loop forever with fastest on/off to GPIO pin
            while (true) {
                    commandChannel.write(GPIO_ON);
                    commandChannel.flush();               

                    commandChannel.write(GPIO_OFF);
                    commandChannel.flush();        
                }
            }
            
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

This should be still pretty fast and good enough for most applications. But, we are still searching for the theoretically maximum frequency we can achieve using pure Java Embedded.

Comments:

Hi Hinkmond,

Are you using a specific version of Java embedded or is it normal Java SE just for ARM? If I remember correctly there was a Java Embedded that was not SE and not ME... But it was very different and also had a very different license.

Which Java are you using?
Would it work the same on Java SE ARM?

I love this series, keep it rolling :)

Posted by Martin on March 29, 2013 at 12:18 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

Hinkmond Wong's blog on making Machine to Machine (M2M) and the Incredible Internet of Things (IoT) smarter with Java Embedded Technologies

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today