User:Ctag/RPi

From Makers Local 256
< User:Ctag(Redirected from Ctag/RPi)
Jump to: navigation, search

First Boot Setup

Configure eth0 with DHCP

edit /etc/network/interfaces to include

auto eth0

Proper Shutdown

To shutdown the pi, use this command:

sudo halt

If you unplug the pi to shut it down, the SD has a high chance of becoming corrupt.

Assigning a MAC address

This page pulled from this article.

Do you need a new MAC

The obvious first sign that you need a new MAC is a lack of internet connectivity. In order to validate changing the MAC address, follow these steps:

- Make sure that your network is using DHCP. Nothing spells futility like simply not setting an IP address to get an IP address..

- Run the following command to check your interface configuration:

$ ifconfig

- Under the eth0 sections, look for an IP next to inet addr

611px

If there's an IP there, then the MAC is likely not your problem.

I need a new MAC

Here's how to harvest a MAC from an existing on-network computer:

Linux

Just run:

$ ifconfig

Tada! The MAC is next to HWaddr

Windows

Go to Network and Sharing Center
Click on Change adapter settings
Right click Local Area Connection and select Status
Click Details...
Next to the field Physical Address is the new MAC address
Make sure to reformat the MAC address with ':' instead of '-' before installing it on your RPi


Install a new MAC

Got a new MAC? Cool, mine's 00:11:22:33:44:55

To install it, open a terminal and type:

$ sudo vi /etc/network/interfaces

You should see a file like this:

474px

Now, navigate to the line above iface eth0 inet dhcp and add auto eth0

After iface eth0 inet dhcp add hwaddress ether 00:11:22:33:44:55

Your file should now look like:

405px

Save and exit.

Back at the terminal, enter the command:

$ sudo ifconfig eth0 down hw ether 00:11:22:33:44:55

Restart the RPi and you should now have a new MAC address!

If, after shutting down or restarting the system you find that the MAC address has reverted, enter the last line again and restart.

SSH

Raspbian

SSH is enabled by default on Raspbian.
Ensure that you have a valid IP address (may need an authenticated MAC as well) and use a program such as PuTTy Tray to connect to the RPi.

Debian

I have not used stock Debian on the RPi yet, however there is a guide for setting up SSH: steve.dynedge.co.uk

SSH Client

Have SSH working? Great, now you need a program that will let you connect! I use and recommend PuTTy Tray for it's utility and aesthetics.

Custom MOTD

When logging into the RPi from a terminal, bash can provide a Message Of The Day.

Custom MOTD:

let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`

# get the load averages
read one five fifteen rest < /proc/loadavg

echo "$(tput setaf 2)
   .~~.   .~~.    `date +"%A, %e %B %Y, %r"`
  '. \ ' ' / .'   `uname -srmo`$(tput setaf 1)
   .~ .~~~..~.    
  : .~.'~'.~. :   Uptime.............: ${UPTIME}
 ~ (   ) (   ) ~  Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
( : '~'.~.'~' : ) Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
 ~ .~ (   ) ~. ~  Running Processes..: `ps ax | wc -l | tr -d " "`
  (  : '~' :  )   IP Addresses.......: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` and `wget -q -O - http://icanhazip.com/ | tail`
   '~ .~~~. ~'    Weather............: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=EUR|UK|UK001|NAILSEA|" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'`
       '~'
$(tput sgr0)"

Paste the MOTD script into ~/.bash_profile.

To open .bash_profile:

$ vi ~/.bash_profile

It should be an empty file.

Tada!

558px

Reference:

http://www.raspberrypi.org/phpBB3/viewtopic.php?t=23440

Check RAM

Check to see how much ram your RPi has, and how much is being used:

$ free -h

574px

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=63&t=20255


Increase SWAP File

Swap is like RAM, but hosted on your SD card. It will allow the board to support memory-intensive programs without crashing.

To increase the size of the Swap file, open /etc/dphys-swapfile in a text editor and change:

CONF_SWAPFILE=100

To whatever value (in MB) that you want.

Reference: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=46472

Keyboard Layout

Set the correct (US, not UK) keyboard for RPi. This is only necessary if you have plugged a keyboard directly into the RPi, it doesn't seem to have any effect on SSH.

$ sudo dpkg-reconfigure keyboard-configuration

Reference:

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=18906

Temperature Monitoring

Temperature shell script:

#!/bin/bash

cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 % $cpuTemp1))
gpuTemp0=$(/opt/vc/bin/vcgencmd measure_temp)
gpuTemp0=${gpuTemp0//\'/}
gpuTemp0=${gpuTemp0//temp=/}

echo CPU Temp: $cpuTemp1"."$cpuTempM"C"
echo GPU Temp: $gpuTemp0

Overclocking

WARNING: IF YOU HAVE A CLASS 10 SD CARD, YOU MAY NOT OVERCLOCK YOUR PI, THE CARD WILL BECOME CORRUPT.

The RPi can be overclocked from the file: /boot/config.txt

Raspbian comes with a utility that can auto-configure the overclock for you.

$ sudo raspi-config

Reference: http://www.jeremymorgan.com/tutorials/raspberry-pi/how-to-overclock-raspberry-pi/

Stress test shell script:

#!/bin/bash
#Simple stress test for system. If it survives this, it's probably stable.
#Free software, GPL2+

echo "Testing overclock stability..."

#Max out the CPU in the background (one core). Heats it up, loads the power-supply. 
nice yes >/dev/null &

#Read the entire SD card 10x. Tests RAM and I/O
for i in `seq 1 10`; do echo reading: $i; sudo dd if=/dev/mmcblk0 of=/dev/null bs=4M; done

#Writes 512 MB test file,  10x.
for i in `seq 1 10`; do echo writing: $i; dd if=/dev/zero of=deleteme.dat bs=1M count=512; sync; done

#Clean up
killall yes
rm deleteme.dat

#Print summary. Anything nasty will appear in dmesg.
echo -n "CPU freq: " ; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
echo -n "CPU temp: " ; cat /sys/class/thermal/thermal_zone0/temp
dmesg | tail 

echo "Not crashed yet, probably stable."

Copy and paste the text into a file in your home directory and name it 'stress.sh'. Then run:

$ sudo chmod +x stress.sh

And run it with:

$ screen -S StressTest
$ ./stress.sh
[Ctrl+a] then [d] to escape the instance of screen

Heatsinks

A heatsink should only be necessary for the following reasons:

- 24/7 use

- Overclocking

- Style points

I suggest either using a small self-adhering heatsink for RAM, or cut a larger one up and mount it with thermal glue.

400px

Installing Software

Apt-Get Rundown

Raspbian is a great distro to have with RPi, because it's based on Debian, a really flippin cool branch of Linux. Because of this, we have access to a tool called apt-get which helps manage the software and programs installed on your pi.

Installing with Apt-Get

To install a software package (like some of the one's I have listed) with apt-get, you can generally use this command:

$ sudo apt-get install packagename

Updating with Apt-Get

To update the software on RPi (the RPi_Monitor will let you know what needs updating):

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get autoclean
$ sudo apt-get autoremove

Suggested Packages

htop (keep an eye on cpu loads)

vim (text editor!)

tmux (awesome screen multiplexer!)

RPi-Monitor (data server, lets you know what's up)

Setup tmux

Create the file ~/.tmux.conf

$ vi ~/.tmux.conf

insert in the file:

bind-key C-a last-window
set-option -g prefix C-a
bind-key C-a last-window
set -g base-index 1

Installing Python Dev

I'm going to try installing Octoprint in a bit, but it needs some Python.

Reference: http://raspberry.io/wiki/how-to-get-python-on-your-raspberrypi/_source/

Install away:

$ sudo apt-get install python-dev
$ curl -O http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ sudo python get-pip.py
$ sudo pip install virtualenv

..Aand I have no clue what that did. Hopefully it'll help with Octoprint!

Building Slic3r

Reference: http://entropyprojects.blogspot.com/2012/08/slic3r-on-raspberry-pi.html

First, install prerequisites:

$ sudo apt-get install git build-essential libgtk2.0-dev libwxgtk2.8-dev libwx-perl libmodule-build-perl libnet-dbus-perl 
$ sudo apt-get install cpanminus curl libextutils-cbuilder-perl gcc-4.7 g++-4.7

Extra bit:

$ cd ~
$ curl -L http://cpanmin.us | perl - --sudo App::cpanminus
$ wget http://search.cpan.org/CPAN/authors/id/S/SM/SMUELLER/ExtUtils-ParseXS-3.18_04.tar.gz

Go to your home directory and clone the Slic3r source:

$ cd ~
$ git clone https://github.com/alexrj/Slic3r.git
$ cd Slic3r

Now, increase your SWAP pagefile in /etc/dphys-swapfile (make sure your SD card has room):

Change:

CONF_SWAPFILE=100

To:

CONF_SWAPFILE=512

Now, you can use CPAN to build some dependancies:

$ sudo cpanm --force --verbose ExtUtils::CppGuess ExtUtils::Typemaps ExtUtils::XSpp
$ sudo cpanm --force --verbose ~/ExtUtils-ParseXS-3.18_04.tar.gz
$ sudo cpanm --force --verbose B::CC Boost::Geometry::Utils Math::Clipper Math::ConvexHull Math::Geometry::Voronoi Math::PlanePath Moo Wx

You should now be able to start Slic3r from a root terminal with ./slic3r.pl

Building Repetier-Server

Repetier-Host doesn't seem to run on Raspbian. If you get it working, tell me.

As a response, it looks like the Repetier project created Repetier-Server (Repserv) specifically for the RPi.

Guide for installing Repserv: http://www.repetier.com/repetier-server-download/

There are two ways to get RepServ, you can download the pi specific executable, which I have not used or tried, or you can arm yourself with a large swap file and march forward, into the build-it-yourself territory.

To build:

  • Install dependencies:
$ sudo apt-get install cmake libboost-all-dev git
  • Clone the GitHub source in your home directory:
$ git clone https://github.com/repetier/Repetier-Server.git
  • Move into the new directory:
$ cd Repetier-Server
  • Make the build folder:
$ mkdir build
$ cd build
  • Build it!
$ cmake ..
$ make

(make will take forever to finish, I showed up the next day to it completed)

  • Now you need to setup runtime
$ sudo cp RepetierServer /usr/bin
$ sudo cp ../linux/repetier-server.conf /etc
$ sudo mkdir /var/lib/Repetier-Server /var/lib/Repetier-Server/configs /var/lib/Repetier-Server/www 
$ sudo mkdir /var/lib/Repetier-Server/storage /var/lib/Repetier-Server/languages
$ sudo cp -r ../www/* /var/lib/Repetier-Server/www
$ sudo cp ../languages/* /var/lib/Repetier-Server/languages
$ sudo cp ../linux/init_Repetier-Server_debian /etc/init.d/Repetier-Server
$ sudo chmod 755 /etc/init.d/Repetier-Server
$ sudo update-rc.d Repetier-Server defaults
  • Reboot, the server should be running.

You can access the web interface at RPi-ip-address:8080

I was originally under the impression that the Repserv worked with Repetier-Host over a network. But now I think that the server works independently from the webpage.

Installing Octoprint

Extra Resources:

http://stackoverflow.com/questions/13437244/mjpg-streaming-with-a-raspberry-pi-and-a-webcam

https://github.com/foosel/OctoPrint/wiki/Setup-on-a-Raspberry-Pi-running-Raspbian

  • Clone the git project
$ git clone https://github.com/foosel/OctoPrint.git
  • Install the Python Dev from above!
  • Move into the new OctoPrint folder, and install dependencies:
$ sudo pip install -r requirements.txt

That was... easy. It's ready to go, to launch OctoPrint:

$ ./run

Now you can access the web interface from pi-ip-address:5000!