Category Archives: snippet

Few tweaks for Raspberry Pi

Use Adafruit’s Occidentalis distro as your base system. It has all neat stuff done for you (sshd running pi/raspberry). It also includes wlan driver for Asus USB-N10 USB WLAN-adapter (which is great and goes through one celement floor).

Make your system up to date by running this command sequence:

rm /etc/ssh/ssh_host_* && dpkg-reconfigure openssh-server
apt-get -y update
apt-get -y install locales
apt-get -y install ntpdate
apt-get -y install ntp fake-hwclock
apt-get -y dist-upgrade

Make a temp filesystem to store logs and all running stuff. Add this row to /etc/fstab:

tmpfs /var/tmp tmpfs nodev,nosuid,size=50M 0 0

Edit /etc/rsyslog.conf and replace all /var/log/ instances with /var/tmp/

One last warning: Your SD card WILL corrupt some day if you don’t do a proper shutdown. Make a backup of your SD card when it’s all set up! If you don’t believe: try it. It’s the nature of SD card that makes this and there’s no easy way out.

Heading difference

A problem that pops up always. When needing to calculate heading difference between two compass courses?

float calculateHeadError(float heading, float target)
#define PI2 PI*2.0
while (heading<0) heading += PI2;
while (target<0) target += PI2;

while (heading>PI2) heading -= PI2;
while (target>PI2) target -= PI2;

float res = heading-target;

if ((headingPI))
res =(heading+PI2)-target;

if ((heading>PI) && (target {
res= (heading)-(target+PI2);
return res;

External interrupts on Atmega 328

It’s this simple:

PCMSK2 |= (1< PCICR |= (1 << PCIE2); // set PCIE2 to PCMSK2 scan

Catch the interrupts (default when signal goes up OR down)

// code here..

PCINT?_vect vectors are always used for Pin Change Interrupt Request Interrupts (see


PCINT0..7 are asscociated with the 8 pins in PORTA and trigger the PCINT0_vect interrupt
PCINT8..15 are asscociated with the 8 pins in PORTB and trigger the PCINT1_vect interrupt
PCINT16..23 are asscociated with the 8 pins in PORTC and trigger the PCINT2_vect interrupt
PCINT24..31 are asscociated with the 8 pins in PORTD and trigger the PCINT3_vect interrupt

Arduino & millis() – overflow

We know that the value of millis() rolls over after 49 days. You can write a hack to overcome with this but how to make sure it works, without testing your code for 49 days?

Here’s the trick. Modify the arduino core code so that millis() will actually roll over after 10 seconds from start. If your Arduino program overcomes that, it will probably do it again after 49 days.

Edit file /Applications/

.. And modify / replace:
volatile unsigned long timer0_millis = ULONG_MAX - (1000*10);

Better colors for Arduino IDE

With just small changes you can make Arduino IDE better for your eyes. Try this, change theme.txt that is located in /Applications/, dunno about Windows.

status.notice.fgcolor = #000000
status.notice.bgcolor = #54919e
status.error.fgcolor = #ffffff
status.error.bgcolor = #662000
status.edit.fgcolor = #000000
status.edit.bgcolor = #cc9900
status.font = SansSerif,plain,12

# settings for the tabs at the top
# (tab images are stored in the lib/theme folder)
header.bgcolor = #216886
header.text.selected.color = #1a1a00
header.text.unselected.color = #ffffff
header.text.font = SansSerif,plain,12

console.font = Monospaced,plain,11
console.font.macosx = Monaco,plain,10
console.color = #000000
console.output.color = #cccccc
console.error.color = #ff3000

buttons.bgcolor = #044f6f
buttons.status.font = SansSerif,plain,12
buttons.status.color = #ffffff

linestatus.color = #ffffff
linestatus.bgcolor = #044f6f


# foreground and background colors
editor.fgcolor = #ffffff
editor.bgcolor = #000000

# highlight for the current line
# highlight for the current line

# caret blinking and caret color
editor.caret.color = #FF00FF

# color to be used for background when ‘external editor’ enabled
editor.external.bgcolor = #c8d2dc

# selection color
editor.selection.color = #888888

# area that’s not in use by the text (replaced with tildes) = #7e7e7e,bold

# little pooties at the end of lines that show where they finish
editor.eolmarkers = false
editor.eolmarkers.color = #999999

# bracket/brace highlighting
editor.brackethighlight = true
editor.brackethighlight.color = #FF0000


# e.g abstract, final, private = #00FFFF,plain

# e.g. beginShape, point, line = #00FFFF,plain

# e.g. byte, char, short, color = #FF00FF,bold


# constants: e.g. null, true, this, RGB, TWO_PI = #5599CC,plain

# p5 built in variables: e.g. mouseX, width, pixels = #00FFFF,plain

# e.g. + – = / = #00FFFF,plain

# ?? maybe this is for words followed by a colon
# like in case statements or goto = #7e7e7e,bold

# TEXT – COMMENTS = #7e7e7e,plain = #7e7e7e,plain

# LINE STATUS – editor line number status bar at the bottom of the screen
linestatus.font = SansSerif,plain,10
linestatus.height = 20

BenQ M23 loosing network

If your BenQ M23 GSM module is losing network or doesn’t stay in the network you might have to register it to network with command:


Where 24405 is the “numeric format is the GSM Location Area Identification number which consists of a three BCD digit country code coded as in ITU-T E.212 Annex A[10], plus a two BCD digit network code, which is administration specific”.

You can get LAC number by commanding:


(and wait for 10 seconds or so..)

Reset Arduino programmatically

This code resets Arduino – in-line – in program, whenever called. Ugly, but works.

// definition
void(* resetFunc) (void) = 0; //declare reset function @ address 0