My Astro Pi programs

Uncomment the comments after %%bash magic to execute

Install Ipython in raspbian wheezy


In [3]:
%%bash
#sudo aptitude install ipython-notebook

To control the raspberry pi from an external computer through this notebook:


In [3]:
%%bash
cat << EOF > /tmp/ipython.sh
#!/usr/bin/env bash
cd /home/pi/astro
ipython notebook --ip=* --no-browser
EOF
#mkdir -p /home/pi/bin
#chmod a+x /tmp/ipython.sh
#mv /tmp/ipython.sh /home/pi/bin

After execute this script from the raspberry pi terminal:

$ notebook.sh

connect from the browser of some external computer into the port 8888 of your raspberry IP, e.g, http://192.168.1.4:8888

or from the Raspberry Pi browser into: localhost:8888

Kernel panic

If accidentally the raspberry pi get unpluged and a kernel panic appears after boot, don't panic!. Load the SD card into a Linux machine, umount all the partions, and execute:

# fsck -y /dev/mmcblk0p1

# fsck -y /dev/mmcblk0p2

Install Astro Pi

See https://www.raspberrypi.org/learning/astro-pi-guide for further info. WARNING: take a long time...

Exec the following command from the console:

wget -O - http://www.raspberrypi.org/files/astro-pi/astro-pi-install.sh --no-check-certificate | bash

Program to write message


In [11]:
from astro_pi import AstroPi
ap = AstroPi()
ap.show_message("Hello my name is Tim Peake", text_colour=(255, 255, 0), back_colour=(0, 0, 255))
ap.clear()

Repeat the message 3 times


In [7]:
from astro_pi import AstroPi
ap = AstroPi()
for i in range(3):
    ap.show_message("38", text_colour=(255, 255, 0), back_colour=(0, 0, 255))

temperature


In [17]:
%%bash
cat << EOF > temp.py
from astro_pi import AstroPi
ap = AstroPi()
temp = ap.get_temperature()
print(round(temp,1))
EOF

In [18]:
%%bash
sudo python temp.py


30.9

Sudo

To avoid the sudo stuff, you can launch the ipython notebook as root and use the AstroPi-sudo notebook --at your own risk!--


In [1]:
%%bash
#git config --global user.email "restrepo.simon@gmail.com"
#git config --global user.name "Simon Restrepo"
#git add AstroPi.ipynb
git commit -a -m "Recover from kernel panic"
git push origin master


# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	temp.py
nothing added to commit but untracked files present (use "git add" to track)
Everything up-to-date

In [ ]: