
JVL
we're not kids anymore.
todays bird
Three Goblin Art

PR's Tumblrdome

oozey mess
Peter Solarz
PUT YOUR BEARD IN MY MOUTH

#extradirty
i don't do bad sauce passes

shark vs the universe
$LAYYYTER
trying on a metaphor

Love Begins
Not today Justin
almost home
"I'm Dorothy Gale from Kansas"
art blog(derogatory)
No title available
taylor price

seen from Türkiye
seen from Türkiye
seen from China
seen from Canada

seen from Türkiye
seen from Norway
seen from United States
seen from Italy

seen from Malaysia

seen from Malaysia

seen from United States
seen from United States
seen from Ireland
seen from United States

seen from Canada
seen from Malaysia

seen from Malaysia
seen from United States

seen from United States

seen from Canada
@macaaw
Raspberry Pi - run program at start-up
There are loads of ways of running a command at start-up in Linux but my favoured approach is to create an initialisation script in /etc/init.d and register it using update-rc.d. This way the application is started and stopped automatically when the system boots / shutdowns. Create script in /etc/init.d
sudo nano /etc/init.d/NameOfYourScript
The following is an example based on starting up the no-ip service [/usr/local/bin/noip], but change the name of the script and the command to start and stop it and it would work for any command.
#! /bin/sh # /etc/init.d/noip ### BEGIN INIT INFO # Provides: noip # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Simple script to start a program at boot # Description: A simple script from www.stuffaboutcode.comwhich will start / stop a program a boot / shutdown. ### END INIT INFO # If you want a command to always run, put it here # Carry out specific functions when asked to by the system case "$1" in start) echo "Starting noip" # run application you want to start /usr/local/bin/noip2 ;; stop) echo "Stopping noip" # kill application you want to stop killall noip2 ;; *) echo "Usage: /etc/init.d/noip {start|stop}" exit 1 ;; esac exit 0
Warning - its important you test your script first and make sure it doesn't need a user to provide a response, press "y" or similar, because you may find it hangs the raspberry pi on boot waiting for a user (who's not there) to do something!
Make script executable
sudo chmod 755 /etc/init.d/NameOfYourScript
Test starting the program
sudo /etc/init.d/NameOfYourScript start
Test stopping the program
sudo /etc/init.d/NameOfYourScript stop
Register script to be run at start-up To register your script to be run at start-up and shutdown, run the following command:
sudo update-rc.d NameOfYourScript defaults
Note - The header at the start is to make the script LSB compliant and provides details about the start up script and you should only need to change the name. If you want to know more about creating LSB scripts for managing services, see http://wiki.debian.org/LSBInitScripts If you ever want to remove the script from start-up, run the following command:
sudo update-rc.d -f NameOfYourScript remove
Wiring thermometer
VNC Server
Install tight VNC: “sudo apt-get install tightvncserver"
Run the program: “tightvncserver"
Start a VNC session: “vncserver :1 -geometry 1024x728 -depth 24"
You must use Chicken of the VNC
Redirect Output to a File
If you want to do the redirection within the Python script, set sys.stdout to an file object does the trick:
import sys sys.stdout = open('file', 'w') print 'test'
A far more common method is to use shell redirection when executing (same on Windows and Linux):
$ python foo.py > file
Reset Raspberry Pi Serial Port
It seems that this is a known issue with the Raspberry Pi. The GitHub geniePi.c has the following workaround:
Code:
// Try to overcome a bug with the Raspberry Pi (or indeed, any other serial
// port that sends a garbage character when you first open it),
// by sending out dummy characters until we get a NAK back, hopefully
// then the display sequencer will be in a stable state.
for (i = 0 ; i < 10 ; ++i)
{
geniePutchar ('X') ;
if (genieGetchar () == GENIE_NAK)
break ;
}
return pthread_create (&myThread, NULL, genieReplyListener, NULL) ;
}
Enabling the serial port
UART
In order to use the dedicated UART pins on the raspberry pi, first they have to be removed from their default application which is debugging.
To do this edit "/boot/cmdline.txt" and "/etc/inittab".
You can backup this files if you want to return to the default configuration:
cp /boot/cmdline.txt /boot/cmdline.bak
cp /etc/inittab /etc/inittab.bak
Remove "console=ttyAMA0,115200" and "kgdboc=ttyAMA0,115200" configuration parameters from the "/boot/cmdline.txt" configuration file using nano editor.
nano /boot/cmdline.txt
Comment the last line on the "/etc/inittab" file. Put a '#' before "T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100.
nano /etc/inittab
Now the RXD (GPIO15) and TXD (GPIO14) pins are available for general UART use.
This is an example application to use the UART pins using Python and the pyserial library:
To install Pyserial download the latest version from http://sourceforge.net/projects/pyserial/files/pyserial/
Install by running the setup.py
python setup.py install
Open a Python terminal (remember to always be running under SuperUser by using sudo or su):
python
To test it without the need of another device simply connect raspberry's TXD and RXD pins to each other:
Run the following commands on the python terminal:
import serial
ser = serial.Serial("/dev/ttyAMA0")
ser.write("UART the Font")
read = ser.read()
print read
ser.close()
The print command should have printed the string sent using the write command. To confugre the UART port, read the following introduction: http://pyserial.sourceforge.net/shortintro.html
Install "minicom"
Install "minicom" for terminal emulation:
apt-get install minicom
You can use minicom using the next line command
minicom -b 9600 -o -D /dev/ttyAMA0
Install Serial Driver for Mac
You must install this driver for the Mac to recognize the 4D display and the RFX...
http://www.ftdichip.com/Drivers/VCP.htm
Get a list of Mac USB ports
ls /dev/tty.usb*
Open SSL
sudo aptitude install python-openssl
Profiling
python -m cProfile -s time mine.py
More profiling
$ sudo apt-get install graphviz $ git clone https://code.google.com/p/jrfonseca.gprof2dot/ gprof2dot $ ln -s "$PWD"/gprof2dot/gprof2dot.py ~/bin $ cd $PROJECT_DIR $ gprof2dot.py -f pstats profile.pstats | dot -Tsvg -o callgraph.svg
http://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script
Profiling using pycallgraph
Extract pycallgraph-0.5.1.zip and then hop into the directory and run:
python setup.py install
Just before your first line of code you want to graph, put in the following code:
import pycallgraph
pycallgraph.start_trace()
To stop the trace and generate the graph, put in the following code (usually at the end of your program):
pycallgraph.make_dot_graph('test.png')
http://pycallgraph.slowchop.com/pycallgraph/wiki/documentation/0.5.1
Send notification through to iPhone
http://push.since2006.com/api-push?uid=1033%m&secret=F68XJP&title=new%20alarm&content=hello
App: Push Messenger
Auto running Python program on startup
cd /home/pi/.config
mkdir autostart
Create a file called mypythonprogram.desktop
[Desktop Entry] Encoding=UTF-8 Type=Application Name=mystartup Comment= Exec=sudo python /home/pi/mystartup.py StartupNotify=false Terminal=false Hidden=false
Store this file in /home/pi/.config/autostart
Restart the Pi
Setting Up Netifaces on Raspberry Pi
sudo apt-get install python-netifaces