Reading from the Adafruit GPS sensor on the Pi

Per instructions in the Oracle Embedded Java MOOC this week, here’s the steps to get gpsd setup to read from the sensor if it’s attached via a USB TTL cable:

sudo apt-get install gpsd gpsd-clients python-gps

ls /dev/ttyUSB* – to check what USB port we’re connected to

sudo gpsd /dev/ttyUSBx -F /var/run/gpsd.sock to start the daemon, replace x with the port number from step above

cgps -s – to run the client

 

If the GPS is attached via GPIO pins, then, similarly to above:

ls /dev/ttyAMA* – to check what AMA port we’re connected to

sudo gpsd /dev/ttyAMAx -F /var/run/gpsd.sock to start the daemon

Check check you’re reading data from the connected port, you can do:

cat /dev/ttyAMA0 – and you should see the raw messages being read from the card.

To interpret data coming from the card, read a line until you get a line prefixed with $, and then the next 5 chars represent the message type:

$GPGGA = gps position data

$GPVTG = velocity data

Enabling i2c on Raspbian

Add the following to /etc/modules:

i2c-bcm2708
i2c-dev

Install i2c-tools:

sudo apt-get install i2ctools

Edit /etc/modprobe.d/raspi-blacklist.conf and remove/comment out these two lines:

blacklist spi-bcm2708
blacklist i2c-bcm2708

Detect your ic2 interface with:

sudo i2cdetect -y 1 #1 = Pi model B

If you get this error:

Error: Could not open file '/dev/i2c-1' or `/dev/i2c/1': No such file or directory

Then run this first and you should be good to go:

sudo modprobe i2c-dev

More info here.

Disabling strict key checking on ssh

Key checking on ssh validates that the remote system you’re attempting to connect to is the same server that you connected to the last time, to help prevent the possibility that someone has hijacked the DNS name, IP, or the hardware itself.

However, some times you may want to avoid this checking. For example, I have a Raspberry Pi that I boot from multiple SD cards, but each is setup with the same IP. If strict key checking is enabled then your ssh client will prevent you from connecting when it detects a signature change. You’ll see this error:

RSA host key for 192.168.x.x has changed and you have requested strict checking.

To avoid this, edit or add ~/.ssh/config, and add:

Host 192.168.x.x
    StrictHostKeyChecking no

where the IP can be the IP of the machine you’re connecting to, or you can use a * wildcard too (maybe not as secure).

If you’ve already connected and have a key in your known_hosts, then I think you need to delete this entry first, and then try with this config.

 

Raspberry Pi ARM ASM syscall notes

A few notes on useful syscalls:

SWI 0 : executes instruction based on value in R7

Write to screen: R7 = 4

MOV R7, #4 @ Syscall 4 = write to screen
MOV R0, #1 @ stdout: move 1 to R0
MOV R2, #4 @ length of string to R2
LDR R1, =string
SWI 0
string:
    .ascii "testn"

Read from keyboard: R7 = 3

MOV R7, #3 @ Syscall 3 = read from keyboard
MOV R0, #0 @ stdin?: move 0 to R0
MOV R2, #4 @ length of string to ready to R2
LDR R1, =string @ load R1 value to string location 
SWI 0
string:
    .ascii ""