Raspberry
Dopo aver installato Raspbian e collegato una vecchia televisione, l'immagine risulta spostata a sinistra. Per corregere il posizionamento verticale ho effettuato la seguente modifica alla configurazione:
vi /boot/config.txt (sudo)
Modificare la seguente riga
overscan_left=26 #overscan_right=16 #overscan_top=16 #overscan_bottom=16
Ora che riesco a digitare comandi e visualizzare il loro output procedo con l'installazione. Attivo interfaccia grafica
startx
Collego alla rete wifi, la chiavetta Dlink è riconosciuta automaticamente e basta quindi inserire la PSK.
A questo punto installo xrdp, al fine di collegarmi da un PC windows, la vecchia tele PAL non ha una grafica entusiasmante.
apt-get update apt-get install xrdp
Prossimo obiettivo far funzionare un vecchio monitor con ingresso DVI-D (cavo 2,80€)
hdmi_safe=1
Obiettivo raggiunto, ma la risoluzione usata è a dir poco deludente (pisquana).
Tolgo un po di bordo
overscan_left=0 overscan_right=0 overscan_top=0 overscan_bottom=0
Rimuovo la modalità safe e forzo il riconoscimento
hdmi_safe=1 hdmi_force_hotplug=1
Ora imposto la risoluzione che meglio si adatta al monitor
hdmi_group=2 hdmi_mode=16 (hdmi_mode=16 1024x768 60Hz)
Le specifiche si trovano seguendo il link [1]
Ora passiamo all'installazione di "Quake". Seguo le istruzioni da link [2]
Installiamo il compilatore (speriamo basti lo spazio sulla SD
sudo apt-get install git gcc build-essential libsdl1.2-dev
Controlliamo
df -h
Filesystem Size Used Avail Use% Mounted on rootfs 1.8G 1.4G 311M 82% / /dev/root 1.8G 1.4G 311M 82% / devtmpfs 93M 0 93M 0% /dev tmpfs 19M 256K 19M 2% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 37M 0 37M 0% /run/shm /dev/mmcblk0p1 56M 17M 40M 30% /boot
Scarichiamo i sorgenti
git clone https://github.com/raspberrypi/quake3.git
Modificare il percorso delle LIB
cd quake3 vi build.sh ARM_LIBS=/opt/vc/lib
Modificare gli INCLUDE
INCLUDES="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads"
Nessun cross compilatore
#CROSS_COMPILE=bcm2708-
Ora si compila
./build.sh
Scarichiamo il Demo Park
pi@raspberrypi ~ $ wget http://dl.dropbox.com/u/1816557/Q3%20Demo%20Paks.zip --2012-12-02 16:36:41-- http://dl.dropbox.com/u/1816557/Q3%20Demo%20Paks.zip Resolving dl.dropbox.com (dl.dropbox.com)... 174.129.253.24, 184.73.171.217, 50.16.240.166, ... Connecting to dl.dropbox.com (dl.dropbox.com)|174.129.253.24|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 72084355 (69M) [application/zip] Saving to: `Q3 Demo Paks.zip'
100%[===================================================================================>] 72,084,355 326K/s in 8m 20s 2012-12-02 16:45:04 (141 KB/s) - `Q3 Demo Paks.zip' saved [72084355/72084355]
Ora rimane proprio poco spazio. Inoltre sono più di 20 minuti che sta compilando, speriamo non fonda. Ora ha finito, ci ha messo circa 1 ora.
Ora salvo immagine SD e allargo la partizione di root.
Per allargare la partizione di root
sudo raspi-config
Quindi si seleziona
expand_rootfs
Si riavvia e si attende che il lavoro sia finito. Ecco il risultato
Filesystem Size Used Avail Use% Mounted on rootfs 7.3G 1.6G 5.4G 22% / /dev/root 7.3G 1.6G 5.4G 22% / devtmpfs 93M 0 93M 0% /dev tmpfs 19M 252K 19M 2% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 37M 0 37M 0% /run/shm /dev/mmcblk0p1 56M 17M 40M 30% /boot
Interfacciamaento con I2c a MPU6050
Modificare
vi /etc/modprobe.d/raspi-blacklist.conf
#blacklist i2c-bcm2708
Quindi un reboot
modprobe i2c-dev ls /dev/i2c*
ls -la /dev/i2c* crw------- 1 root root 89, 0 Dec 3 15:35 /dev/i2c-0 crw------- 1 root root 89, 1 Dec 3 15:35 /dev/i2c-1
chmod o+rw /dev/i2c*
ls -la /dev/i2c*
crw----rw- 1 root root 89, 0 Dec 3 15:35 /dev/i2c-0 crw----rw- 1 root root 89, 1 Dec 3 15:35 /dev/i2c-1
Installiamo ora gli i2c-tools
apt-get -y install git i2c-tools
Verificare che veda il dispositivo su bus i2c sul bus 0 nel mio caso
i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse! I will probe file /dev/i2c-0. I will probe address range 0x03-0x77. Continue? [Y/n] y 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Rilevato dispositivo all'indirizzo 0x68 (MPU6050)
Documentazione:
[3]
[4]
Ora preparo un programma mio, prendendo spunto dalla rete.
#include <stdio.h> #include <stdlib.h> #include <linux/i2c-dev.h> #include <fcntl.h> #include <string.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> void ReadTemperatura(int); unsigned int ReadW(int , unsigned char ); unsigned char ReadB(int , unsigned char ); void InitMpu6050(int); //**** Global int address = 0x68; int main(int argc, char **argv) { printf("**** MPU6050 test program ****\n"); int fd; // File descrition int result; char *fileName = "/dev/i2c-0"; // Name of the port we will be using unsigned char buf[10]; // Buffer for data being read/ written on the i2c bus if ((fd = open(fileName, O_RDWR)) < 0) { // Open port for reading and writing printf("Failed to open i2c port\n"); exit(1); } if (ioctl(fd, I2C_SLAVE, address) < 0) { // Set the port options and set the address of the device we wish to speak to printf("Unable to get bus access to talk to slave\n"); exit(1); } InitMpu6050(fd); //ReadTemperatura(fd); result = ReadW(fd,0x3b); double dT = ( (double) result + 12412.0) / 340.0; printf("Temp as decimal: %f\n",dT); // display bearing with decimal place result = ReadW(fd,0x3b); printf("Ax as decimal: %u\n",result); // display Acc X result = ReadW(fd,0x3d); printf("Ay as decimal: %u\n",result); // display Acc Y result = ReadW(fd,0x3f); printf("Az as decimal: %u\n",result); // display Acc Z result = ReadW(fd,0x43); printf("Gx as decimal: %u\n",result); // display Gyro X result = ReadW(fd,0x45); printf("Gy as decimal: %u\n",result); // display Gyro Y result = ReadW(fd,0x47); printf("Gz as decimal: %u\n",result); // display Gyro Z return 0; } void InitMpu6050(int fd_mpu6050) { unsigned char buf[10]; // Buffer for data being read/ written on the i2c bus if (ioctl(fd_mpu6050, I2C_SLAVE, address) < 0) { // Set the port options and set the address of the device we wish to speak to printf("Unable to get bus access to talk to slave\n"); exit(1); } buf[0] = 0x41; // This is the register we want to read from if ((write(fd_mpu6050, buf, 1)) != 1) { // Send register we want to read from printf("Error writing to i2c slave\n"); exit(1); } } void ReadTemperatura(int fd_mpu6050) { unsigned char buf[10]; // Buffer for data being read/ written on the i2c bus buf[0] = 0x41; // This is the register we want to read from if ((write(fd_mpu6050, buf, 1)) != 1) { // Send register we want to read from printf("Error writing to i2c slave\n"); exit(1); } if (read(fd_mpu6050, buf, 2) != 2) { // Read back data into buf[] printf("Unable to read from slave\n"); exit(1); } else { unsigned char highByte = buf[0]; unsigned char lowByte = buf[1]; unsigned int result = (highByte <<8) + lowByte; // Calculate bearing as a word value double dT = ( (double) result + 12412.0) / 340.0; printf("Temp as decimal: %f\n",dT); // display bearing with decimal place } } unsigned int ReadW(int fd_mpu6050, unsigned char addr) { unsigned char buf[10]; // Buffer for data being read/ written on the i2c bus unsigned int result; buf[0] = addr; // This is the register we want to read from if ((write(fd_mpu6050, buf, 1)) != 1) { // Send register we want to read from printf("Error writing to i2c slave\n"); exit(1); } if (read(fd_mpu6050, buf, 2) != 2) { // Read back data into buf[] printf("Unable to read from slave\n"); exit(1); } else { unsigned char highByte = buf[0]; unsigned char lowByte = buf[1]; result = (highByte <<8) + lowByte; // Calculate bearing as a word value } return result; } unsigned char ReadB(int fd_mpu6050, unsigned char addr) { unsigned char buf[10]; // Buffer for data being read/ written on the i2c bus unsigned char result; buf[0] = addr; // This is the register we want to read from if ((write(fd_mpu6050, buf, 1)) != 1) { // Send register we want to read from printf("Error writing to i2c slave\n"); exit(1); } if (read(fd_mpu6050, buf, 1) != 1) { // Read back data into buf[] printf("Unable to read from slave\n"); exit(1); } else { result = buf[0]; } return result; }
Poi ne compilo uno bello, fatto da qualcuno che ha tempo per programmare.