Java API - getting started

Hi,

Got my Blinkstick Square today and got wondering about a Java client…

I’ve build a Java client for WS281x (https://github.com/tobyweston/unicorn-hat) before that just wrapped a C library in a Java API. So all the low level stuff was handled by the C (https://github.com/richardghirst/rpi_ws281x) code.

Just wondering about getting started with a Blinkstick API. Is the basic protocol over USB, so I would write a wrapper over low level USB code but not need to worry driver software for the actual Neopixels? I’m thinking something like USB4J? If so, any pointers to the protocol?

I’ve seen the official Processing and Android repos, should I start there?

Thanks,
Toby

Just grab the blinkstick.jar from the Processing library and that’s all you need for Java API implementation. There are no other dependancies required.

1 Like

Thanks. I’ve made a start with that although I get a lot of IO Exception generated from the underlying HID library. When they occur, it seems to disable the stick. Is that something you’ve seen before?

When I say disable, I mean the device is no longer available (via ioreg on mac, device manager on windows) and the device itself will sporadically flicker one or two pixels (maybe ~30 secs apart). A white color, similar to when you first plug it in. Ring any bells?

I’ll keep plugging away on https://github.com/tobyweston/blinkstick-java and will try an alternative HID library (hid4java vs codeminder’s lib)…

Regarding flickering pixels: Do you have a similar behavior when using the BlinkStick Client Software?

According to my experience IOException can appear if you sending the colors too fast to the device (less than 20ms between set_color’s for example).

Can you exclude a “real” connection loose, means an unsteady USB port or hub or a broken cable?

The client doesn’t seem to have the flickering but wont recognise the stick after “breaking” it with IOExceptions. I haven’t figured out how to get it back reliably and have been resorting to reboots!

Swapping the cable is my next course of action :smiley:

Just to describe things a little more;

I tried a new cable, I get a brief flash/flicker on connection but don’t seem to be able to reliably “see” the stick. I’m on Mac but will try again in Windows asap.

The client (v2) where once it shows the device name (I named it with info block 1) now shows just the serial number and the refresh icon does nothing. Screenshot and logs attached.

Logs;

2016-09-07 21:52:17,538 [1] INFO  Main - --------------------------------------
2016-09-07 21:52:17,550 [1] INFO  Main - BlinkStick Client 2.0-rc9 application started
2016-09-07 21:52:18,003 [1] INFO  Main - Loading data
2016-09-07 21:52:18,073 [1] DEBUG Main - Registering/Unregistering startup
2016-09-07 21:52:18,073 [1] DEBUG Main - Loading main form icon
2016-09-07 21:52:18,103 [1] DEBUG Main - Building popup menu
2016-09-07 21:52:18,108 [1] DEBUG Main - Showing popup menu
2016-09-07 21:52:18,108 [1] DEBUG Main - Setting up tray icon
2016-09-07 21:52:18,251 [1] DEBUG Main - Setting up treeview
2016-09-07 21:52:18,258 [1] DEBUG Main - Adding notifications to the tree
2016-09-07 21:52:18,627 [1] DEBUG NotificationService - Creating service...
2016-09-07 21:52:18,627 [1] INFO  NotificationService - Service created
2016-09-07 21:52:18,627 [1] INFO  NotificationService - Starting notification monitoring...
2016-09-07 21:52:18,628 [1] INFO  NotificationService - Started.
2016-09-07 21:52:18,628 [1] DEBUG Main - Initialization done

Terminal output from ioreg doesn’t include ‘BlinkStick’;

$ ioreg -p IOUSB -w0 | sed 's/[^o]*o //; s/@.*$//' | grep -v '^Root.*' 
IOUSBHostDevice
FaceTime HD Camera (Built-in)
IOUSBHostDevice
IOUSBHostDevice
BRCM20702 Hub
Bluetooth USB Host Controller
Apple Internal Keyboard / Trackpad

Any ideas how I can kick-start things to recognise the HID device? Unplugging seems to do nothing :’(

Plug off and in is normally the solution. Maybe there is still an instance trying to connect your Stick.

Sorry, writing on a mobile and some of my Last text got lost. After a reboot everything is ok again? The flash when Connecting means the device got power. An error could occur if 2 instances trying to control the device for example blinkstick client and java at the same time. And as explained before a missing delay between signals (min 20ms).

I’ll give it a more thorough test using just the official client after a reboot and see if it feels more stable.

BTW, I’m only sending data down every 250ms,

Just to follow up, I put something in my client to ensure a the call frequency is never < 20ms and it seems to make everything much more stable (no more random exceptions from the USB lib). I guess I was accidently calling it too frequently.

I still have problems getting the stick to be recognised reliably, but I’ll try a few more operating systems and report back…

That is always my mistake. I thought it could not be but checking the code then is telling another story :).

We´re still trying to find a phenomenon with a few USB controllers. Sometimes you need a hub sometimes you don´t. If you have some info which controllers work directly and which don´t that would be great.
For example:
I did some tests on different machines and found out that a “Intel® 7 Series/C216 Chipset Family USB Enhanced Host Controller - 1E2D (USB 2.0)” does not work, but a “Intel® 5 Series/3400 Series Chipset Family USB Universal Host Controller - 3B36 (USB 2.0)” does (tested with windows 7 and 10).

Hi, I use BlinkStick Pro to drive Smart Pixels. Can i use blinkstick.jar from the Processing library ?