What about 2014++ ?

A very short review on 2014

Well, actually only about this blog ;)

While a lot has happened in tech, only very few things happened here on this blog: only one posting (excluding this one) and some comments – for which I’m very thankful, by the way.

I did not have any interesting stuff to blog about… most of the things that I’ve been working on did not evolve to a state that was worth writing about. Nevertheless I played around with some nice “peaces” of technology, and we’ll see how they can be used in future projects.

What to expect for 2015?

… according to new posting on this blog, of course ;)

Well, I will not force myself to write here just for the sake of writing. That would be boring for both you as a reader and me, too.

Instead I will focus more on projects that will probably turn out to be usable to a certain degree – this year’s code snippets and circuits were mostly proof-of-concepts in a very basic state.

Any ideas, what do YOU think?

Do you have any ideas or thoughts about technologies that are worth a look in 2015 – and why? I’d be glad to get a few comments about that, and maybe I can take a closer look.

So, see you in 2015 :)

Netduino Plus 2 (NETMF) and WS2812 RGB LEDs

Some weeks ago I got some Adafruit NeoPixel, a compact RGB LED module. Each LED module has a WS2812 chip that only needs three wires: power, ground and data. The data protocol is self-clocking, at a rate of 800KHz. The LED modules can be chained to build longer LED stripes. (For more details see the Adafruit NeoPixel Überguide.)

Adafruit provides an Arduino library on github to control the LEDs, but there is no direct support for Microsoft .NET Microframework (NETMF) controllers like the Netduino Plus 2 that I was going to use.

Actually, there is an advanced guide to use NETMF controllers with the WS2812 LEDs, but it requires a custom firmware, because it seems that the GPIO pins of most NETMF controllers are not fast enough to switch the signal at the needed rate (there is a timing needed in the range of 0.4μs to 0.8μs and some websites found out that the GPIO pins have a latency of 17μs). As I nearly bricked a Netduino before, I didn’t want to dive into custom firmwares at this point.

So I found a different way to send the control codes to the LEDs at the needed speed as the following photo proves:

Netduino with WS2812 LEDs

How does it work?

I thought that there must be a faster way to get signals off a Netduino Plus 2 because it has an Ethernet port and SD card slot, and I suppose they need to be adressed faster than 17μs (I haven’t evaluated this, so maybe I’m wrong with that, but it led me in the right direction). Looking at the ports that the Netduino provides my attention was drawn towards the SPI interface.

SPI (Serial Peripheral Interface) is a four-wire master-slave interface for full-duplex communication between chipsets. It has a clock wire (SCLK), output (MOSI) and input (MISO). Normally it can be used at a frequency up to some MHz, so the ports must be really fast.

My assumtion was, that I could only use the output (MOSI) pin, configure the frequency accordingly and send the needed control bytes on that wire to the LEDs. I tried some settings and data packets, but first without any success, but luckily I wasn’t the first one to try this, so I found some code snippets for different microcontrollers, that pointed me into the right direction, e.g. that a timing of 6.666MHz is recommended.

I’ve written two classes and uploaded them to github, so if you have a Netduino Plus 2 (or similar microcontroller) and don’t want to use a custom firmware to control WS2812 RGB LEDs, then maybe you want to give my code a try.

Code on github: https://github.com/jcoder/NetMFNeoPixelSPI

Usage example:

NeoPixelSPI neoPixel = new NeoPixelSPI(Pins.GPIO_PIN_D10, SPI.SPI_module.SPI1);
Pixel pixelRed = new Pixel(255, 0, 0);
Pixel pixelGreen = new Pixel(0, 255, 0);
Pixel pixelBlue = new Pixel(0, 0, 255);
Pixel pixelWhite = new Pixel(255, 255, 255);
Pixel[] block1 = new Pixel[] { pixelRed, pixelWhite };
Pixel[] block2 = new Pixel[] { pixelBlue, pixelGreen };
int waittime = 1000;
while (true)
{
 neoPixel.ShowPixels(block1);
 Thread.Sleep(waittime);
 neoPixel.ShowPixels(block2);
 Thread.Sleep(waittime);
}

The library code is not optimized (yet), and I didn’t write a helper class for easier handling of long LED stripes (because I don’t own one), so feel free to extend the code. I’m not quite sure if this approach is really a good one, but it worked for me.

Also feel free to leave a comment below if you have any remarks, ideas, etc.

As always: use this information and the code on your own risk. ;)

More Raspberry Pi Awesomeness: GPIO & Java

I’ve been playing with the GPIO capabilities of the Raspberry Pi before using Python, which comes with easy GPIO access for the Raspberry Pi.

Java 8 for ARM

As I’m yet not very familiar with Python I got excited when Oracle accounced Java 8 for the ARM platform, so I downloaded the JDK 8 (with JavaFX) for ARM Early Access from the Oracle website, copied it to the RPi, compiled an example app on my PC and copied the JAR to the RPi – and it runs!

Obviously it takes some time to start the application but it works as excepted; of course it was a very simple example and there are some limitations, especially when it comes to graphics output, but it’s a good start.

There is even JavaFX support in the JDK 8 which will output to RPi’s HDMI/Video output, but that’s a topic for another posting ;)

Java & GPIO

There is no native support for the RPi’s GPIO pins in Java, but there are two Open Source projects to get it running anyway:

  • WiringPi – an easy-to-use C library to control the GPIO pins
  • Pi4j – a Java class library providing a bridge between native code and Java to access the GPIO pins

As described on the WiringPi website you can get WiringPi via git, and then build it directly on the RPi.

The Pi4j website has lots of examples on how to work with the code, and from a Java developer’s perspective it is pretty straight forward to use Pi4j.

I’ve used some code directly from the Pi4j’s example pages, put an LED on a breadboard, connected two pins and when running the program the LED blinks! Great!

So, if you are planing to access GPIO via Java you should definitely take a look at WiringPi and Pi4j.

Raspberry Pi & GPIO & LCD = awesome

Do you remember the LCD display? I’ve connected it successfully to an Arduino lately, so when I got my Raspberry Pi some days ago it was just a matter of time to try connecting the two:

Raspberry Pi with LCD

I followed the nice instructions by Adafruit, connected all the wires, ran the code, and everything worked great.

The code is written in Python, so that’s maybe the next language to learn for me ;)

The GPIO capabilities of the Raspberry Pi look very promising, so I might use them regularly in future projects, especially when a decent amount of storage or a network connection is required (both provided by the Raspberry Pi in a very convenient way).

Arduino PWM in slow motion

Although I’m mostly working with the “normal” digital input / output on the Arduino, it might be a good idea to play with the PWM output, too, just to have a basic knowledge about it if needed.

I’ll not go too much into detail about the theoretical background of PWM (highly suggesting you to read the Wikipedia article about PWM if you want to learn more about it). Simply speaking, PWM on the Arduino creates an analogue signal between 0 and 5 Volts by pulsing the power with an interval, e.g. to provide 50% (2.5 Volts) the power is pulsed at a rate of 500 Hz (Arduino uses this frequency for PWM) with half of the time provding either 5 Volts or 0 Volts.

So, what about connecting a LED to the Arduino PWM, powering it at 50% and using high speed video recording?

Arduino PWM in slow motion from Nils on Vimeo.

At 1000 frames per second you can see the flickering that is caused by the switching power on and off at high frequency.

I currently don’t have any use case for PWM in my projects but it’s good to know how it basically works if needed ;)

New open source project: jspinfo

Just some shameless self-promotion:

I recently uploaded my 3rd open-source project to SourceForge.net. It’s called jspinfo() and – for all of you who are familiar with PHP – it’s like phpinfo() but as a JSP file.

So, if you are a developer and you need some information about some common server settings, then give jspinfo() a try: just upload the file to your Java-based application server (preferrable Apache Tomcat) and open it in your browser.

For more information and the download please visit http://jspinfo.sourceforge.net/

If you have any comments, ideas or other feedback on jspinfo() please visit the jspinfo() Ticket system or the discussion forum.

ATtiny45 meets 74HC595

Earlier today I’ve been following the Arduino Tutorial for driving a 74HC595 shift register which turned out to work pretty well.

In short, a shift register is an electronical component that can be controlled using 3 wires to change the output of 8 pins, or even more when two or more shift registers are chained together. Using a shift register can be useful when you need some more output pins on a microcontroller but only want to use few pins on the microcontroller itself.

I really suggest taking a look at the linked tutorial above for more information, everything worked great following the steps described there.

Limited number of pins on a microcontroller? Did anybody say “ATtiny”?!

Yes, there we go:

It is pretty straight forward to port the Arduino example code for controlling a shift register to work with an ATtiny45 as well.

  • Upload the ArduinoISP sketch to the Arduino Uno
  • Load the Shift Register sketch into the Arduino IDE
  • Switch the board settings to ATtiny45
  • Connect the ATtiny45 to the Arduino Uno (see my previous posting for more infos)
  • Upload the sketch through the Adruino Uno to the ATtiny

As you can see in the photo above, the Arduino is only used as a power source, the shift register – lighting the LEDs – is just driven by the ATtiny45 on the small breadboard.

I’ve been using a very simple blinking pattern which I set up in the code in an array of bytes (can you guess the pattern? shouldn’t be too hard due to the LED setup), and the program is about 1084 bytes in size. As the ATtiny45 comes with 4096 bytes of program memory there is still a decent amount of space left to build a more complex program, because I guess most of the code is used by the “invisible” part of your program (not the directly written user code but the “infrastructure” code to make it run on the chip) – but that’s just a guess ;)

Anyway, shift registers are a powerful “tool” which is easy to use because the Arduino comes with both predefined functions to work with shift registers and also useful examples, so depending on your project needs you might want to give the shift registers a try.