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
ntpdate uk.pool.ntp.org
apt-get -y install ntp fake-hwclock
rpi-update
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

External interrupts on Atmega 328

It’s this simple:


pinMode(5,INPUT);
PCMSK2 |= (1<
--
Catch the interrupts (default when signal goes up OR down)

ISR(PCINT2_vect)
{
// code here..
}

PCINT?_vect vectors are always used for Pin Change Interrupt Request Interrupts (see http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html)

--
Remember:

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/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/wiring.c

.. And modify / replace:
#include
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/Arduino.app/Contents/Resources/Java/lib/theme, dunno about Windows.

# GUI – STATUS
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

# GUI – TABS
# 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

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

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

# GUI – LINESTATUS
linestatus.color = #ffffff
linestatus.bgcolor = #044f6f

# EDITOR – DETAILS

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

# highlight for the current line
editor.linehighlight.color=#005500
# highlight for the current line
editor.linehighlight=true

# 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)
editor.invalid.style = #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

# TEXT – KEYWORDS

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

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

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

# TEXT – LITERALS

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

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

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

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

# TEXT – COMMENTS
editor.comment1.style = #7e7e7e,plain
editor.comment2.style = #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:

AT+COPS=1,2,”24405″

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:

AT+COPS=?

(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

Source: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1288779911/3#3