donderdag 17 oktober 2013

Lipo powered Raspberry Pi

I needed a completely wireless Raspberry Pi so I looked into some battery power options.

Whatever power supply I would use it should end in a micro usb connector. I first stripped a cheap cable and then soldered 2 wires. You can find the pinout here.  Don't worry about the data pins since we'll only power the rPi.


My first idea was to use 4 AA type batteries. Without load they measured 5.75V which is over the 5.25V max of USB spec. I'm not sure how much the Raspberry Pi itself can handle (it has a regulator on board from what I can see) but I went for it anyway and noticed the voltage dropped to 5.30V on load.

Perfect for a raspberry Pi? Not at all! They only last for about 30 minutes. The voltage then dropped too much and the USB dongles stopped working. The power led on the pi still blinked but no USB == no wifi (wireless remember?).

I then explored lipo power. I have several batteries laying around. Just needed a 5V regulator. Not those 3 pin thingies that get hot like hell wasting all the power as heat.


The easy solution is to buy a UBEC, switching voltage regulators used in RC electronics. They accept a wide range of lipo voltages and you can find these online for 5 USD or less.

The fun solution is to find a cheaper DIY alternative.  I found something referenced as MP2307 (just search it on ebay, it's all over the place). According to the datasheet we can use this to regulate input from 4.75V up to 23V to a more rPi friendly 5V (anything from 0.925V to 20V). The below image shows how to use it.


The components look very similar to those commercially available UBEC. And guess what, you can ignore the modifications listed in the pic on top and just solder your connectors and a 10k pot. As soon as you power it up and change the voltage to something around 5V the black part in the middle that you should have removed will pop.

Now I just need to finish with some shrinkwrap and I have my lipo powered Raspberry Pi up and running. BTW don't forget that lipo batteries don't like being over discharged (or over charged, or dropped, or being abused in any other way).




zaterdag 7 september 2013

configure error libusb headers missing

I got the below error while trying to build libnfc on a mac running mountain lion.

configure: error: The libusb headers are missing

I first checked if libusb what installed with macports. That was OK so I kept looking. Turned out I needed the libusb-legacy package instead.

sudo port install libusb-legacy

woensdag 4 september 2013

raspberry pi apt-get illegal instruction

After an apt-get dist-upgrade attempt all apt-get calls on a raspberry pi with official raspbian distro returned an unhealthy illegal instruction response.

A quick look at my /etc/apt/sources.list showed that I specified a non raspbian source there. So I had to get the apt files back from http://archive.raspbian.org/raspbian/pool/main/a/apt/ as deb packages and install them again.

The commands, make sure to check the given url for the proper releases.

wget http://archive.raspbian.org/raspbian/pool/main/a/apt/apt_0.9.7.8%2brpi1_armhf.deb
wget http://archive.raspbian.org/raspbian/pool/main/a/apt/libapt-pkg4.12_0.9.7.8%2brpi1_armhf.deb

sudo dpkg -i apt_0.9.7.8+rpi1_armhf.deb libapt-pkg4.12_0.9.7.8+rpi1_armhf.deb 



dinsdag 20 augustus 2013

Forecast weather API android lib

I used to call the google weather API within several Android apps. Until Google once decided to shut that service down. Since then I have been looking around for an alternative.

I finally found a great service hosted by forecast. They have a visually attractive presentation on their homepage. But what's more important is that their pricing model is also nice. You get 1000 free API calls a day. If you want more you get to pay.

Anyway, I decided to subscribe for that service. In return you get an API key. Next I created a simple library project to parse the result.

What it does is a background http get (using the default httpClient) with the parameters you provided with the builder. The json response is then parsed using gson. A quick example:

    double latitude = 37.8267;
    double longitude = -122.423;

    ForecastCallBuilder builder = ForecastCallBuilder.getInstance();
    builder.key("YOUR_API_KEY_HERE").latitude(latitude)
            .longitude(longitude).units(Units.AUTO);
    ResponseListener listener = new ResponseListener() {

        @Override
        public void handleResponse(HttpServiceOutput result) {
            if( result == null || result.getException() != null ){
                Toast.makeText(getApplicationContext(), "Failed to fetch data!", Toast.LENGTH_SHORT).show();
            }
            else {
                // you should check for nullpointers on the forecast data before display
                Toast.makeText(getApplicationContext(), "Summary: " + result.getForecastResponse().getCurrently()
                            .getSummary(), Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void preExecution() {
            Toast.makeText(getApplicationContext(), "Fetching forecast data now...", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void postExecution() {
            // here you cold inform about call being done
        }

    };
    builder.performCall(listener);

For more information visit the project at https://github.com/hanscappelle/android-forecast-lib.
Forecast developer documentation is available at https://developer.forecast.io/docs/v2.

maandag 19 augustus 2013

ActionBarCompat and NavigationDrawer example

I finally found some time to get the recently released support version of the Android ActionBar implemented. Also known as ActionBar Compat, with support back to Android 2.1 or api level 7.

This will soon be used in my phototools application to replace the ActionBarSherlock and SlidingMenu. For the sliding menu we can now use the official navigation drawer pattern.

First thing I noticed was that the navigation drawer example only goes back to level 14. So here is my github project to fix that. This is a first draft. Some style attributes were replaced with fixed dimensions to get this example running on 2.1.

Check the readme for more instructions. Don't forget to get the support library reference fixed.

Vote if you want a tutorial.


donderdag 18 juli 2013

AppleScript select RAW pictures iPhoto library

A quick appleScript I wrote to select all images from the current library that are from a certain type.

The type is checked with the extension found in the path of the original picture (original path property of photo object). The below example is to select all NON NEF pictures. NEF filetype being the Nikon Raw format.

tell application "iPhoto"

    select (every photo in current album whose original path does not contain ".NEF")
    
end tell


woensdag 10 juli 2013

jade template with variable in element id

For most NodeJS projects I rely on Jade for rendering views.

A quick example of how to generate a set of elements based on your data:

ul
  each val in [1, 2, 3, 4, 5]
    li= val

This will render the following html:

<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

And another quick example of how to assign id and class names to an element:

a#main-link.some-class

Resulting:

<a id="main-link" class="some-class"></a>

A very powerful yet easy and minimal syntax for HTML. However I often need to combine these two. That is render a list of items in which the element IDs are specific for each rendered element. The solution looks like this. Consider the items set to hold objects with an ._id and value property.

ul
  each item in items
    li(id='element#{item._id})= item.value

That's it.