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.


maandag 10 juni 2013

Apple OS X keyboard shortcuts

some shortcuts to remember. Original source: http://ss64.com/osx/syntax-keyboard.html

OS X Keyboard Shortcuts

Screen Capture to disk:
  command Shift Key 3                   Screen to jpeg file on desktop
  command Shift Key 4 + Drag:           Selection to jpeg file on desktop
  command Shift Key 4 + Spacebar:       Window (click camera) to jpeg file
Screen Capture to clipboard:
  command Shift Key 3 + Ctrl:           Screen to clipboard
  command Shift Key 4 + Drag + Ctrl:    Selection to clipboard
  command Shift Key 4 + Spacebar + Ctrl Window (Camera effect)
Dock /Switch Applications
  command option D      Show/Hide Dock
  command Tab      Switch applications (even while dragging a file)
  command `        Switch between document Windows in current application
  option Dock     Switch application, hide previous one
  command Dock     Switch application, hide all others
 Ctrl option command *  Toggle Monochrome Hi Visibility
  command +drag will prevent dock icons from moving out of the way
             (useful when dragging items to the trash)
Apple Finder
  option + Drag   Explicit COPY (will copy even if destation is on same volume)
  command + Drag   Explicit MOVE (will move even if destation is on different volume)
  command option + Drag Make alias in new location
  command D        Duplicate
  command L        Make Alias
  command R        Show original
  command O        Open item
  command ↓        Open item
  command S        Save
  command Shift Key S      Save as
  command N        New Finder window
  command Shift Key N      New Folder
  command Q        Quit Application
  command W        Close Window
  command option W      Close all Windows
  command I        Get Info
  command option I      Super Get Info (change whatever you click on)
  command option S      Show/Hide the Finder sidebar
  command option Y      Toggle Slideshow mode (show selected graphic files full-screen)
  command P        Print
  command T        Add to Favorites
  command Delete   Move to Trash
  command E        Eject
  command F        Find
  command ~        Cycle finder windows (including desktop)
  Tab        Highlight next item
  command + double-click folder icon will open in new window
  command + ↑      Move up one directory
  command + [      go back
  command + ]      go forward
  command Shift Key A     Open Applications Folder
  command Shift Key D     Open Desktop Folder
  command Shift Key U     Open Applications/Utilities/ Folder
  command Shift Key H     Open Home Folder
  command Shift Key K     Go to network
  command K        Connect to server
  command Shift Key G     Go to folder... (type full path)
  command Shift Key ⌫     Empty Trash (Finder Menu )
  command Shift Key option ⌫   Empty Trash without dialog

Finder-Hide App:
  command H        Hide Application 
  command option H      Hide other applications

Hide all other apps*:
  option command + click on dock icon
  option command + click inside app window

Hide all other apps that are in front*:
  option + click dock icon (of running app)
  option + click inside app window

*Some older (pre-intel) apps may struggle with these
QuickLook
  Spacebar (or command Y)   Activate QuickLook on the selected file(s)
  command option Y               Full Screen QuickLook on the selected file(s)
Terminal
  command left/right arrow   Switch windows
  command 1                  Switch to 1st terminal window
  command 2, command 3...          Switch to 2nd, 3rd window
Spotlight
  command Spacebar           Activate/deactivate Spotlight
  command option Spacebar         Open Spotlight window
  command Return / command Click   Open the top/next item
  command ↓ / ↑              Move to next/previous category
Editing Text (email, TextEdit etc)
  option ←       Move one word left
  option →       Move one word right
 Ctrl A     Beginning of Sentence (Home)
 Ctrl E     End of Sentence(End) 
  command ←       Beginning of line
  command →       End of line
  option [       “  Smart quote (open/left)
  option Shift Key [     ” Smart quote (close/right)
  option ]       ‘  Smart quote (open/left) Also Apostrophe: O‘Brien
  option Shift Key ]     ’ Smart quote (close/right)
            Scroll one page up (cursor retains position)
            Scroll one page down (cursor retains position)
  option         Move one page up  (reposition cursor)
  option         Move one page down
  command ↑ or   Scroll to beginning of document
  command ↓ or   Scroll to end of document

  Add shift key Shift Key to the above to also select the text.

  option ⌫      Delete previous word  
  option Del     Delete next word
 Ctrl D     Delete next character (Del)
  command Shift Key .     Show hidden files in open and save dialogs (Snow Leopard only)
  command Shift Key /     Open Application Help (Search)

  option Scrollbar           Jump to exact scrollbar location
  option Scrollbar arrows    Scroll page at a time (page up/down)
  option Volume up/down      Open Sound preferences
  Control Shift Key Eject       Turn display off (brightness=0)
  option Brightness up/down  Open Display preferences
Shutdown/Logoff:
  POWER         Sleep now
  POWER         Hold for 10 seconds (force shut down)  
  Ctrl Eject    Restart, Sleep, Shutdown dialog box
  Ctrl Shift Key Eject  Sleep the display now
  command option Eject    Sleep the computer now

  command Ctrl Eject  Quit all applications and restart
  command option Ctrl Eject Shut down the computer now (Graceful Shutdown)
  command option Esc       Force Quit menu - selectively force quit applications
  command option Shift Key Esc     Hold for three seconds to Force Quit the foremost application (Leopard/Snow Leopard)
  command .(period)   Stop a process
  command Ctrl+power  Immediate restart (dangerous, only use if the system is frozen)
Log out:
  command Shift Key Q         Log out (Apple Menu)
  command Shift Key option Q       Log out immediately (Apple Menu)
During Startup:
  Shift      Safe Boot mode - Press shift asap AFTER the startup chime 
  command V        Start up in Verbose mode.
  command S        Start up in Single-User mode (command line)
    X        Force OS X startup
  command option Shift Key ⌫   Bypass primary startup volume (will seek DVD or external disk)
    C        Start up from a CD (if it has a system folder)
    D        Start up from first partition
    N        Attempt to start up from a network server(NetBoot)
    R        Force PowerBook screen reset
    T        Start up in FireWire Target Disk mode
  Option     Select startup disk 
  command option P R   PRAM Reset - Hold down Cmd-Option-R with your left hand,
              then press POWER to start up and immediately press P with your right hand.
              See KB 2238  At the prompt you can  type: reset-nvram and/or reset-all 
  command option O F   Open Firmware
  command E        Eject CD (press during/after startup chime)
  mouse      Eject CD (hold mouse button down during startup)
command is the Command or Apple key
option is the Option or Alt key
Shift Key is the Shift key
⌫ is the Backspace key

Toggle hidden files

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder