Writing RAM efficient Arduino code

Developing the software for the wind stations I often run into problems and random restarts of the Arduino. Soon I realised it was due to that I ran out of RAM, 2k does not last that long, specifically when every debug string you put in consumes RAM. I found out about PROGMEM but I did not find so much more information on how to use it so instead I focused on getting things to work. But now when I re-write the whole communication code I plan to do it right!

So have looked a bit more into it and found the great article Putting constant data into program memory (PROGMEM) by Nick Gammon. It explains the whole problem as well as give many practical tips on how to write RAM efficient Arduino code.

And another recommendation is to use the latest Arduino IDE, the 1.5.8 Beta. It uses much newer compiler etc as described in this post. Also when compiling it generates not only information about how much of the storage space you sketch uses but also how much RAM is used at start. Like this:
Sketch uses 9,412 bytes (30%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,126 bytes (54%) of dynamic memory, leaving 922 bytes for local variables. Maximum is 2,048 bytes.

Remember that this only indicates the situation at start so do you have functions that use large arrays that will not be shown there.

Debugging HTTP communication over GSM

I’m writing a HTTP client for the Arduino. The debugging options on the Arduino are quite limited. And in general doing low level HTTP programming a tool like SockSpy is invaluable. Though for traffic to reach SockSpy it must be connected to a public TCP IP port. With the common use of firewalls and NATed networks this is generally not the case. How do you solve that?

If you have access to a public server on the internet, SSH is your salvation! Setup a reverse SSH tunnel from your server(yelloworb.com in my case, port 3000) to your local machine(port 2000), then configure SockSpy to connect back to the server(if thats the web server you try to talk HTTP with). Like this:
ssh -R 3000:localhost:2000 yelloworb.com
sockspy 2000 www.server.com 80

And change your code to talk to your server instead(yelloworb.com and port 3000 in my case).

To get the port forwarding working you need to enable GatewayPorts in the sshd configuration. Read here how to do that. The SSHd manpages has more useful information.

How to get PostgreSQL to work with Rails3 on Mac OSX snowleopard

I’m about to host a web app on Heroku and they are using PostgreSQL for database. Followed the instructions and added gem ‘pg’ to my Gemfile and made bundle install but it failed:
Installing pg (0.11.0) with native extensions /Users/kalle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

Thought I didn’t have PostgreSQL installed so installed it via MacPorts:
sudo port install postgresql90

but still got the same error! After a bit of googling I found out it was due to that the bin folder was not in the path. So by doing this it worked:
export PATH=/opt/local/lib/postgresql90/bin/:${PATH}
env ARCHFLAGS="-arch x86_64" bundle install

Geotag your images and place them on maps

Geotagging isn’t anything really new, been around a couple of years. There are some different tools that will help you to download a track from your GPS unit and synchronize it with the timestamp from images to set positioning data in the image. Then you can place those on Google Earth or on the Flickr Map.

But what I have not been able to find is a free piece of software that will use a GPS connected to a mobile phone and generate a track to synchronize with images. So I wrote one. Now I’m looking for people who would like to give it a test to find bugs etc. The software is yet quite simple, it scans for bluetooth devices and you can select the one to connect to. Then will it start to read positioning data from it and when it gets a good position it is stored in a GPX file on your phone.

I uploaded an example from earlier today onto Flickr.

Some advices and whats needed:
Make sure flickr use your GeoTags.(via)
You need Microsoft LocationStamper, download here.
You need a mobile phone with Java and also JSR-82 and JSR-75, like SonyEricsson K750 or K800.
And you need a bluetooth GPS, I use Holux GPSlim236. Nav4All sells them quite cheap, 70€.

HotSync Fatal Exception

I have been working on a Palm application for somw days now. Its a tool to log data from a device connected to the serial port of the Palm. The data is stored in a file on the memory card. The first version will just support one specific device, the 3DM-G tilt and motion sensor from Microstrain Inc.

I stumbled into some weird problems. All worked just dine in the Palm Simulator on the PC but once I moved it to the Palm T3 I use the T3 crashed after each hotsync. This answers why: Re: HotSync Fatal Exception