BrickPi documentation

Hey mstorm,

Are you looking at this repository: https://github.com/DexterInd/BrickPiJava

Or another Java implementation?

Hey John,
That is the one, I understand now why it was not working and using the python implemenation in combination with the c-version I have reverse engineer it. It is running now.

This is great to hear! What did you have to fix to get it to run?

It is not 100% fixed yet. When you pull it from the repo, there is a maven build file that takes the Pi4J 0.0.5 version from central. This API is the community edition but not the hacked version that I found in the repo. There is the difference. With the hacked version of Pi4J it runs since it can handle a heigher baud rate (50000). The community edition does not allow this baud rate. The solution is to find what has been hacked in that version and try to implement that hack in the snapshot version of 1.0.1 of Pi4J. When the hack is contributed and accepted by pi4j than it will work out of the box when the Pi4J dependency is upgraded. The other problem is the serial interface, there are some threading problems between the current implementation in the repo with the serial interface, still debugging.

The other problem is that the Java version is far behind of the python version. A lot of sensors are not supported yet ;-). I have rewritten the BrickPi for Java so it is more object oriented. The API is 100% decoupled from the BrickPI current hardware platform so it allows developers to add future hardware platforms. I have created a flexible service provider for it. The API and SPI is not compatible with the current version in the repo. I saw that nobody is active in the last 2 years on the current Java Repo, is Java not active here?

The steps I will take is:

  1. to reverse engineer the PI4J hack and hopefully the are accepting the patch.
  2. Upgrade the Repo here when the Pi4J has release with the patch so that version works.

Sensor port 5 is also not supported, and I need this for my robot. I hope to implement this also in the next month.

Hi mtstorm,

I’m also using Java with BrickPi and Pi 2 & 3 for a hobby project. I haven’t used the netbeans projects, since I prefer eclipse. So far I haven’t tried to use the motors or sensors from Java, since my focus is on Computer vision for robots. My fork of the BrickPiJava is here https://github.com/woolfel/BrickPiJava

Hey guys, have either of you used the ev3dev Java for the BrickPi? I just linked it on our brickpi page, but i haven’t tried it (https://github.com/ev3dev-lang-java/ev3dev-lang-java)

Also, Woolfel, we would love a pull request if you have one!

Hi John,

Let me clean the stuff up first before I make a pull request. It’s a bit messy at the moment ;p

I was waiting until I had time to clean things up and make it more presentable. I should have some time tonight to do that and will try to make a pull request.

Hi all,
Both repo’s are bit out of date. They all use the hacked version 0.0.5 but this is not 100% compatible with the brickpi. I try to figure out what is changed in that hacked version. If somebody has a clue, please post, that will be a huge timesaver. I would like to use the led’s on the board to have a visual feedback if the board is activated or not. GPIO_27 is not in 0.0.5, wrong PI…

@Woolfel, sensors and motors are not great supported for Java as with the Py version. I wish to change that :slight_smile:

There I think it’s a risk since upgrading is not yet possible until this hack is fixed.

Yet a stupid question but does anybody know how to contact ergouser or can somebody ask ergouser about this hack?

@mtstorm - I plan to start working with the motors from Java in a week or two, so I can help debug and fix it.

@mtstorm - I was comparing the source in BrickPiJava versus what’s up on the official pi4j github. The one that’s in BrickPiJava/lib/pi4j-core-0.0.5.jar has this for loading native libs

static {
    // Load the platform library
    NativeLibraryLoader.load("pi4j", "libpi4j.so");
}

Where as the current pi4j has this

static {
    // Load the platform library
    NativeLibraryLoader.load("libpi4j.so");
}

At first I was having issues with the serial port not initializing, so I unjarred pi4j-core-0.0.5 and copied libpi4j.so to /usr/lib/jni/ folder. that got past the serial port error, but the motor doesn’t run on Raspberry Pi 3 for me. Tomorrow I will try the Pi 2 B and Pi 1 B+

Sorry for the delay. Thanks for you input. I will try to get the newer version of Pi4J and look in to the native library. I use model B+. Have you any luck already. I will keep you posted.

With the newer version of Pi4J are the LEDs operational, but the port fails for the baud rate. I will keep on digging.

After investigation I saw a change in the PI4J API, the changed the class NativeLibraryLoader in 2014. The say they have simplified the loading thing and that it now (after 0.0.5), only supports the loading for the embeded resource, aka the so-file/ native library. When I look in the I2C.java file the removed the same statement, just as you have pointed out for the NativeLibraryLoader.

static {
// Load the platform library
// Removed -> NativeLibraryLoader.load(“pi4j”, “libpi4j.so”);
// Added -> NativeLibraryLoader.load(“libpi4j.so”);
}

The first parameter is “pi4j” and points to a native library in the system classloader but not on the lib dir. When it fails in will try to resolve the so file in the jar itself. In the newer version it loads only from the jar file. I will seek if there is libpi4j.so somewere in the classpath on the PI.

It could also be the case that the libpi4j.so is hacked for the baud rate.

@mtstorm - I was guessing the libpi4j.so might also be hacked for higher baud rate. I did extract the native .so file from current and 0.0.5. On my Pi3 it didn’t work with the motor. I will try it with my Pi 2B and B+ this weekend if I have time.

peter

@mtstorm - I came across this bug in pi4j that has been closed. The baud rate was limited due to the wiringPi pi4j was using.

That bug was closed. I think 1.1 snapshot is suppose to have the fix.

@woolfel Nice!!! Thanks for your updates. I will start working on it. I will get the pi4j snapshot from there repo, this is good news. I will post my progress asap to let you know if it works. On Twitter they say they will release half of april!! Then this can be included in the repo :slight_smile: as a project dependency. I will keep you posted!!!

Small update; The new version of pi4j is nicer than the previous one and is not backward compatible. With some minor code changes it’s easy todo. Changes are is that the interface Serial is now thowing IOException (very nice better). AutoClosabe is now on the interface Serial (love that) so try with resources can be used. There are some renames of methods like availableBytes() -> available() . The read is now very nice, no read for a single byte but an array, so you need to use read (int length). Than it easy to implement it. The shutdown of the serial has been removed, need to figure that out how to release the serial (other then close, do not know yet.)

I’m still working on it, I will keep you posted.

An update. I have added the snaphot version “1.1-20160409.004953-44” of pi4j-core that should work, but I am a bit clueless. The API has changed and I think I am overlooking some new features of the serial interface of PI4J. The only thing now is working are the LED on the BrickPI, but there is no communication between the software and the BrickPi CPU’s yet using the serial. I can open the serial port with the correct baudrate of 500,000 but then, after sending, there is no response of the BrickPI. I have made a loopback connection for the serial and that running fine (I have added some stuff to the baudrate issue https://github.com/Pi4J/pi4j/issues/89 , maybe they have some nice suggestings.). I do not have an osciloscope here at my disposal, but I have and idea that the brickpi is not getting any data. I made a loopback connector for the serial and run a test and that runs fine.

Is there a possibility to make a ping between the rpi and the brickpi. This would be very nice to check if the communication between hardware and software would be running. Is this an idea to implement that in the monitors of the brickpi? for instance getting the version of the monitors software, and implement a basicloopback feature in it (ping idea).

I think I made an error somewere, the bug is between the monitor and the keyboard ;-). I will continue an keep you posted.