<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Stephen C Phillips (Posts about Python)</title><link>http://blog.scphillips.com/</link><description></description><atom:link type="application/rss+xml" href="http://blog.scphillips.com/categories/python.xml" rel="self"></atom:link><language>en</language><copyright>Contents © 2018 &lt;a href="mailto:steve@scphillips.com"&gt;Stephen C Phillips&lt;/a&gt; </copyright><lastBuildDate>Sat, 29 Dec 2018 20:25:42 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Getting a Python script to run in the background (as a service) on boot</title><link>http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/</link><dc:creator>Stephen C Phillips</dc:creator><description>&lt;div class="section" id="getting-a-python-script-to-run-in-the-background-as-a-service-on-boot"&gt;
&lt;h2&gt;Getting a Python script to run in the background (as a service) on boot&lt;/h2&gt;
&lt;p&gt;For some of my projects I write a simple service in Python and need it
to start running in the background when the Raspberry Pi boots.
Different Linux distributions use different ways of starting and
stopping services (some now use
&lt;a class="reference external" href="http://en.wikipedia.org/wiki/Upstart"&gt;Upstart&lt;/a&gt;, some
&lt;a class="reference external" href="http://en.wikipedia.org/wiki/Systemd"&gt;systemd&lt;/a&gt;). I am using the
"Wheezy" Debian distribution on my Raspberry Pi, and in this case the
proper way to do this is using an "init script". These are stored in the
&lt;tt class="docutils literal"&gt;/etc/init.d&lt;/tt&gt; folder. In there you can find scripts that for instance,
start the networking system or a print server. Debian Wheezy uses the
old Sys V init system which means that these scripts are run according
to symbolic links in the &lt;tt class="docutils literal"&gt;/etc/rc.x&lt;/tt&gt; directories. The &lt;a class="reference external" href="http://www.debuntu.org/how-to-managing-services-with-update-rc-d/"&gt;Debian
documentation&lt;/a&gt;
explains this.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/"&gt;Read more…&lt;/a&gt; (9 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>Python</category><category>Raspberry Pi</category><guid>http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/</guid><pubDate>Sun, 21 Jul 2013 13:05:28 GMT</pubDate></item><item><title>European public holiday leaderboard</title><link>http://blog.scphillips.com/posts/2013/01/european-public-holiday-leaderboard/</link><dc:creator>Stephen C Phillips</dc:creator><description>&lt;div class="section" id="european-public-holiday-leaderboard"&gt;
&lt;h2&gt;European public holiday leaderboard&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="http://www.it-innovation.soton.ac.uk/"&gt;I work in a lot of European
projects&lt;/a&gt;. This means that we
often have weekly teleconferences across several countries which are
often scuppered by a partner or partners being on holiday because of a
national holiday. In the UK, all our public holidays are put on Mondays
(with some Fridays) so that you don't get the country shutting down in
the middle of the week. In other countries the public holidays (e.g.
saints' days) just land on the same date every year with two results:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Sometimes they land on a weekend so most people don't actually get a
holiday.&lt;/li&gt;
&lt;li&gt;When they land on a Tuesday or a Thursday lots of people take off the
Monday or Friday as well to make a really long weekend and you lose
almost half a week.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href="http://blog.scphillips.com/posts/2013/01/european-public-holiday-leaderboard/"&gt;Read more…&lt;/a&gt; (3 min remaining to read)&lt;/p&gt;&lt;/div&gt;</description><category>Python</category><guid>http://blog.scphillips.com/posts/2013/01/european-public-holiday-leaderboard/</guid><pubDate>Tue, 01 Jan 2013 12:29:49 GMT</pubDate></item><item><title>Moving the Where Clock from a web browser</title><link>http://blog.scphillips.com/posts/2012/12/moving-the-where-clock-from-a-web-browser/</link><dc:creator>Stephen C Phillips</dc:creator><description>&lt;div&gt;&lt;!-- title: Moving the Where Clock from a web browser --&gt;
&lt;!-- slug: moving-the-where-clock-from-a-web-browser --&gt;
&lt;!-- date: 2012-12-27 15:39:12 --&gt;
&lt;!-- tags: Python,Raspberry Pi,Where Clock --&gt;
&lt;!-- description: --&gt;
&lt;div class="section" id="moving-the-where-clock-from-a-web-browser"&gt;
&lt;h2&gt;Moving the Where Clock from a web browser&lt;/h2&gt;
&lt;p&gt;Now I've got a web server and I've got code to control the stepper
motor, let's put them together and control the stepper motor from a web
browser! Here's the new code: &lt;tt class="docutils literal"&gt;clockServer.py&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.scphillips.com/posts/2012/12/moving-the-where-clock-from-a-web-browser/"&gt;Read more…&lt;/a&gt; (1 min remaining to read)&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</description><category>Python</category><category>Raspberry Pi</category><category>Where Clock</category><guid>http://blog.scphillips.com/posts/2012/12/moving-the-where-clock-from-a-web-browser/</guid><pubDate>Thu, 27 Dec 2012 15:39:12 GMT</pubDate></item><item><title>A simple Python webserver</title><link>http://blog.scphillips.com/posts/2012/12/a-simple-python-webserver/</link><dc:creator>Stephen C Phillips</dc:creator><description>&lt;div&gt;&lt;!-- title: A simple Python webserver --&gt;
&lt;!-- slug: a-simple-python-webserver --&gt;
&lt;!-- date: 2012-12-27 10:38:55 --&gt;
&lt;!-- tags: Python,Raspberry Pi --&gt;
&lt;!-- description: --&gt;
&lt;div class="section" id="a-simple-python-webserver"&gt;
&lt;h2&gt;A simple Python webserver&lt;/h2&gt;
&lt;p&gt;Now I can &lt;a class="reference external" href="http://blog.scphillips.com/posts/2012/12/a-python-class-to-move-the-stepper-motor/"&gt;control the stepper-motor from Python&lt;/a&gt;
I need to be able to tell the Raspberry Pi to move the motor from my
phone so that, for instance, when I get to work it can tell the motor to
move the indicator hand to point to "Work".&lt;/p&gt;
&lt;p&gt;To do this, the easiest way seem to me to be using a web server on the
Pi. I want to make it so that if you GET the URL
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;http://&amp;lt;raspberry.server&amp;gt;:8080/move?a=90&lt;/span&gt;&lt;/tt&gt; then it will move the hand to
90 degrees. This normally requires a web server and a CGI script but it
seemed overkill to install Apache or even something lighter-weight such
as lighttpd or nginx for such a simple task so I've written my own: much
more interesting!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.scphillips.com/posts/2012/12/a-simple-python-webserver/"&gt;Read more…&lt;/a&gt; (3 min remaining to read)&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</description><category>Python</category><category>Raspberry Pi</category><guid>http://blog.scphillips.com/posts/2012/12/a-simple-python-webserver/</guid><pubDate>Thu, 27 Dec 2012 10:38:55 GMT</pubDate></item><item><title>A Python class to move the stepper motor</title><link>http://blog.scphillips.com/posts/2012/12/a-python-class-to-move-the-stepper-motor/</link><dc:creator>Stephen C Phillips</dc:creator><description>&lt;div&gt;&lt;!-- title: A Python class to move the stepper motor --&gt;
&lt;!-- slug: a-python-class-to-move-the-stepper-motor --&gt;
&lt;!-- date: 2012-12-26 23:40:27 --&gt;
&lt;!-- tags: Python,Raspberry Pi,Where Clock --&gt;
&lt;!-- description: --&gt;
&lt;div class="section" id="a-python-class-to-move-the-stepper-motor"&gt;
&lt;h2&gt;A Python class to move the stepper motor&lt;/h2&gt;
&lt;p&gt;To properly control the stepper motor from the Raspberry Pi we need a
class to represent it. This is one of the most direct ways of
understanding object oriented programming (OOP): from the class you make
an "object" and the object represents and controls an object in the real
world (the stepper motor).&lt;/p&gt;
&lt;p&gt;The class lets us remember (and control) all the information we need:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;the pins the motor is connected on;&lt;/li&gt;
&lt;li&gt;the speed of the motor;&lt;/li&gt;
&lt;li&gt;the angle the motor is currently pointing to.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://blog.scphillips.com/posts/2012/12/a-python-class-to-move-the-stepper-motor/"&gt;Read more…&lt;/a&gt; (4 min remaining to read)&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</description><category>Python</category><category>Raspberry Pi</category><category>Where Clock</category><guid>http://blog.scphillips.com/posts/2012/12/a-python-class-to-move-the-stepper-motor/</guid><pubDate>Wed, 26 Dec 2012 23:40:27 GMT</pubDate></item><item><title>Wiring done right</title><link>http://blog.scphillips.com/posts/2012/12/wiring-done-right/</link><dc:creator>Stephen C Phillips</dc:creator><description>&lt;div&gt;&lt;!-- title: Wiring Done Right --&gt;
&lt;!-- slug: wiring-done-right --&gt;
&lt;!-- date: 2012-12-24 14:16:42 --&gt;
&lt;!-- tags: Python,Raspberry Pi,Where Clock --&gt;
&lt;!-- description: --&gt;
&lt;div class="section" id="wiring-done-right"&gt;
&lt;h2&gt;Wiring Done Right&lt;/h2&gt;
&lt;p&gt;With the new jumper leads from eBay I wired it all up again. For the
power, the motor controller board has 4 pins and I don't know why. Two
of them are bridged by a jumper and by the other two there is a "-" and
a "+" and "5-12V" underneath. I wired the 5V pin of the Pi (P2) to the
one labelled "+" and the ground pin of the Pi (P1) to the "-". Seems to
work, but I don't know if I just got lucky or whether it doesn't matter
which way round you put them.&lt;/p&gt;
&lt;p&gt;For the controller lines I wired P18, P22, P24 and P26 to IN1, IN2, IN3
and IN4 respectively. That done, I turned it on and tried some software.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.scphillips.com/posts/2012/12/wiring-done-right/"&gt;Read more…&lt;/a&gt; (3 min remaining to read)&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</description><category>Python</category><category>Raspberry Pi</category><category>Where Clock</category><guid>http://blog.scphillips.com/posts/2012/12/wiring-done-right/</guid><pubDate>Mon, 24 Dec 2012 14:16:42 GMT</pubDate></item></channel></rss>