Oh no, not another Raspberry Pi article (that is probably out of date too)

I was late to the game when it came to the Raspberry Pi.  I heard about it, before it was released, I raised an eyebrow in its general direction and went back to working with my BeagleBone.... I then heard that no one could get a Pi and there was a huge waiting list.  I continued playing with my BeagleBone.  I got hold of a 7" LCD screen for the BeagleBone and spent many an evening/night...ok, until 3am some times - compiling my own kernel to be able to use the screen.  I learnt quite a lot along the way.

It was at this point that the Pi then became generally available - it was on the 2nd revision and there were a ton of online articles out there about people doing stuff with it.  So, I put the BeagleBone back on the shelf (yes, that's the shelf of "once it's put here, it shall gather dust until I rekindle my curiosity and fire it back up again...shelf"), obtained a Pi and all the accessories and set about seeing what I could do with it.
At this point I must add, I was running an old HP Proliant ML350 server in my garage - it was running ESX server so I could have multiple VMWare images running to allow me to "do" various things and access the server externally.

I thought....why am I running this hulking great HP Server with 4 CPUs, 8Gb RAM, huge great noisy fans and about 500Gb of SCSI drives just to stream music to my Tablet when I'm out and about? (I did actually use it for more than that, but I'd bore you with the details.... let's just say, Arduino temp. sensors, MQTT, Mosquitto and an Android notification app... I digress).
I roughly worked out the cost of running this hulk and decided to see if I could replace it with the Raspberry Pi - that consumes about the same power as a light bulb.  I'm still not sure you're meant to leave a Pi on 24x7, but it seems to be doing okay so far.
I had a few ups and downs setting up the device to do what I wanted it to do, in the end I did the smart thing and wrote down some instructions for myself - so I didn't have to think about it and didn't miss anything when doing it for the 5th time that day/night.

These instructions were to help me setup the Pi so I could run:

  • NGinx webserver (with php if needed)
  • MongoDB ('cos all the cool kids are doing stuff with it)
  • NodeJS (well.....you have to ask?)
  • ExpressJS (REST api access to the MongoDB)

I then setup Pi:2 to be dedicated to streaming music from an external USB Drive - that works like a charm.

anyway, here are the tony style install notes that make sense to me - I'll keep them here just incase the SDCards get fried and I need to do this again.


change pi password
pi/somepwdthatisreallysecurehonest

sudo raspi-config

Expand rootfs – expand the root partition to fill the SD card
memory_split = 64MB
Overscan – enabled
ssh – enabled
boot_behaviour – start desktop on boot

(audio - set to analog)

boot to desktop - for convenience
set up the Wifi (can do this manually, but this is quicker and less typing!)

sudo raspi-config
memory_split – how much memory should the GPU have? I set mine to 32MB of the 512MB as I won’t be running graphically intensive apps. I hope this frees up most of the resource to run MongoDB
boot_behaviour – start console on boot

####################################

sudo nano /etc/network/interfaces

#iface default inet dhcp
iface default inet static

address 192.168.0.121
broadcast 192.168.0.255
network 192.168.0.0
netmask 255.255.255.0
gateway 192.168.0.1


sudo apt-get update
sudo apt-get upgrade

############NGinx#####################h
sudo apt-get install nginx

sudo apt-get install php5-fpm

sudo service nginx start

sudo nano /etc/php5/fpm/php.ini
change cgi.fix_pathinfo from 1 to 0

sudo service php5-fpm restart

sudo nano /etc/nginx/sites-available/default

root /usr/share/nginx/www;
index index.php index.html index.htm;


server {
    listen 8081;


location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

sudo service nginx restart

cd /usr/share/nginx
sudo chown pi www
cd www
sudo chown pi *.html

nano index.php
<?php
phpinfo();
?>

can then test working okay by opening web browser:

http://tonypig.servebeer.com:8081/index.php


#################setup Maplin robot arm#############

sudo usermod -aG plugdev pi

sudo nano /etc/udev/rules.d/85-robotarm.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="1267", ATTRS{idProduct}=="0000", ACTION=="add", GROUP="plugdev", MODE="0666"

sudo apt-get install python-pip -y && sudo pip install pyusb --upgrade

sudo shutdown -r now


dmesg | grep usb | grep 1267
look for New USB device found


sudo apt-get install git-core

git clone https://github.com/peterlavelle/maplinarm

cd maplinarm/
ls
chmod 755 *.py

nano testarm.csv
shoulder-up,1.00,1.00
elbow-down,1.00,2.00
light-on,2.00,1.00
base-clockwise,4.00,1.00
shoulder-down,1.00,1.00
grip-close,1.00,1.00
base-anti-clockwise,4.00,2.00
grip-open,1.00,1.00
elbow-up,1.00,2.00
stop

command,duration,pause

./commander.py testarm.csv


############NodeJS##################
[do NOT do this.....]
sudo apt-get install nodejs

but do this instead:

wget http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-arm-pi.tar.gz
(The following version is now available - replace the v0.10.22 with v0.10.28)
wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-arm-pi.tar.gz

tar -xvzf node-v0.10.28-linux-arm-pi.tar.gz

node-v0.10.28-linux-arm-pi/bin/node --version
should display: v0.10.28

sudo nano /etc/profile

NODE_JS_HOME=/home/pi/node-v0.10.28-linux-arm-pi
PATH=$PATH:$NODE_JS_HOME/bin
export PATH

then check that node is working okay by running the following commands from console:

node -v
npm -v

node --version  (0.10.28)
npm --version   (1.4.9)

####################################



##########MongoDB####################
sudo apt-get install git-core build-essential scons libpcre++-dev xulrunner-dev libboost-dev libboost-program-options-dev libboost-thread-dev libboost-filesystem-dev

git clone git://github.com/RickP/mongopi.git
OR
sudo apt-get install build-essential libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev scons libboost-all-dev python-pymongo git
(adds about 230mb extra)

cd ~
git clone https://github.com/skrabban/mongo-nonx86
cd mongo-nonx86


[do the following in the evening / overnight as it will take quite a few hours!]

sudo scons

sudo scons --prefix=/opt/mongo install


sudo adduser --firstuid 100 --ingroup nogroup --shell /etc/false --disabled-password --gecos "" --no-create-home mongodb


sudo nano /etc/profile

$ PATH=$PATH:/opt/mongo/bin/
$ export PATH


sudo mkdir /var/log/mongodb/

sudo chown mongodb:nogroup /var/log/mongodb/

sudo mkdir /var/lib/mongodb

sudo chown mongodb:nogroup /var/lib/mongodb

sudo cp debian/init.d /etc/init.d/mongod

sudo cp debian/mongodb.conf /etc/

sudo ln -s /opt/mongo/bin/mongod /usr/bin/mongod

sudo chmod u+x /etc/init.d/mongod

sudo update-rc.d mongod defaults

sudo /etc/init.d/mongod start


mongo


#clean up
sudo scons -c

#find top 20 largest files
du -a /var | sort -n -r | head -n 20



(need to create /data/db also and set chown to pi, if using default settings)

##############now make the Mongo driver###############
sudo apt-get php5-dev
sudo apt-get php-pear
sudo pecl install mongo

sudo nano /etc/php5/fpm/php.ini

extension=mongo.so

sudo service nginx restart
sudo service php5-fpm restart
##############################################



###################set up SAMBA to share files###########################
sudo apt-get install samba samba-common-bin
sudo smbpasswd -a pi

configure: /etc/samba/smb.conf

workgroup = WORKGROUP
wins support = yes

[pihome]
comment= Pi Home
path=/mnt/usb
browseable=Yes
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=no
##############################################



This is specifically for the "2nd Pi" that is dedicated to streaming music:

###############streaming music###############################
sudo apt-get install mpd
sudo apt-get install mpc ncmpc #or ncmpcpp (GUI front end)
sudo apt-get install alsa-utils

modify /etc/mpd.conf

bind_to_address "any"
file location "/mnt/usb/music/music"
mixer_type "software"


$alsamixer
if says MM then is muted

$ mpc update                        'makes mpd read the music directory
                                    'and update its database
$ mpc listall                       'lists all the music in the database
$ mpc insert ‘album or song name’   'adds something to the playlist
$ mpc playlist                      'prints the playlist
$ mpc play                          'plays the playlist
$ mpc volume 80


sudo usermod -a -G audio mpd
sudo usermod -a -G pi mpd     #/mnt/usb is for group pi? (change to audio)

sudo /etc/init.d/mpd restart

aplay -vv /usr/share/sounds/alsa/Front_Right.wav



setup /mnt/usb
sudo nano /etc/fstab

/dev/sda1 /mnt/usb vfat uid=1000,gid=1000,defaults 0 2


##############################################

Sound output by default will by either HDMI or Audio Out Jack, and by default it will auto-detect,:

HDMI output:
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 2

Audio Jack output:
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 1

Autodetect output:
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 0

this created static noise when I attempted to aplay tail\ toddle.mp3
not ideal, but at least there was some noise!

running Auremo MPD Client - it plays the music on the Raspi!!!!
Oh, I get it now!!!!
The Android app doesn't play the music on the tablet but is just a controller!
##############################################


This info is specifically for the LCD screen I have attached to the Pi:
https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install

Start by getting access to the GPIO by making a device link
 sudo sh -c "echo 252 > /sys/class/gpio/export"
 ls -l /sys/class/gpio

Once you verify that you see GPIO #252, then you can set it to an output, this will turn off the display since it will output 0 by default
 sudo sh -c "echo 'out' > /sys/class/gpio/gpio252/direction"

Then turn the display back on with
 sudo sh -c "echo '1' > /sys/class/gpio/gpio252/value"

or back off
 sudo sh -c "echo '0' > /sys/class/gpio/gpio252/value"

edit the following file: /etc/kbd/config
set BLANK_TIME=30

No comments:

Post a Comment