BrickPi Java

First working version is checked in here:

You can clone a complete Netbeans Project including the required libraries. It uses pi4j. The jar in the project has been modified to support he 500000 baud rate.

Most sensors are missing. Except for I2C, color_full and ultrasonic other sensors should work as a RawSensor.

Motor is implemented but not yet tested.

The interfaces/APIs are subject to change at this point.

You can integrate Netbeans so that it will automatically copy the code to the PI following the instructions here:

Comments, feedback and help appreciated.

Awesome! I would really like to try this out and give some feedback.

Also, when you feel you’ve got it in a stable place, we would like to link to your github repo so others can use it as well. That’s really awesome!

Motors are in there (+/-) encoder count problems. Sample code is in BrickPiTests. Basically:

get the pi instance:

BrickPi brickPi = BrickPi.getBrickPi();

create a sensor, eg touch:

TouchSensor touchSensor = new TouchSensor();

associate it with the port on the pi:

brickPi.setSensor(touchSensor, 0);

Set up the sensors:


(Also starts the polling thread so that calling:


is unnecessary.)

value of the sensor:




Similarly, create a motor:

Motor motor = new Motor();
brickPi.setMotor(motor, 0);

Get the current speed:


Change the speed:


Repeat for more motors and sensors.

Awesome! I am going to make this post sticky, and we’ll put this up under “languages” on our website. Thanks so much!

I’ve a problem with Ultrasonic sensor. It give me random value from 990 to 1010. I’m using the same procedure descript in the last post. What could be the problem?

Thanks a lot

I’m trying this code to read value from ultrasonic sensor but it gives me random value from 990 to 1010. What could be the problem?



I can’t seem to make the motor working.
Has anybody successfully make the motor running?

How can I help to test this?


I’ve just tried the Java library but only the Ultrasonic sensor. It looks great. Thanks for add Java support to the BrickPi. I would like to add sensors and robotic controllers (ie. Tetrix, Matrix) so I try to get into the code and I should say is not that easy for me like it was for lejos (Java on the Lego Brick).
In lejos you have method for write and read register on the device and, if you have access to the device spec, you are almost done.
With BrickPi Java, as far I understood, the reads and writes follow different rules/protocol, where I can get details about that?
Could someone just add a very simple sensor, one that use at least a “write” to a register (ie. set the accelerometer scale), with few comments? I think this will help understand the “mapping” between the device spec and the BrickPi’s bytes we send/read from the serial.

Hello st0g1e and tatobrutto, i would contact the Java project creator directly about this issue.