{"id":130,"date":"2013-08-15T12:23:28","date_gmt":"2013-08-15T12:23:28","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/pi\/?page_id=130"},"modified":"2013-08-23T16:34:31","modified_gmt":"2013-08-23T16:34:31","slug":"clockatoo","status":"publish","type":"page","link":"https:\/\/blog.soton.ac.uk\/pi\/clockatoo\/","title":{"rendered":"Clockatoo"},"content":{"rendered":"<p><b>1) Getting started and setting the clock<\/b><\/p>\n<p><b>Geekroo Raspberry Pi LED Clock Expansion Board &#8211; Clockatoo<\/b> is an I2C device for the Raspberry Pi. It comes with some Python code to make the &#8220;Clockatoo&#8221; work. Install the 4-digit LED taking care not to put the LED up-side-down (as per Figures below). Then stack the Clockatoo on the Raspberry Pi using\u00a0 the 26-pin GPIO header.<\/p>\n<div>\n<div><a href=\"http:\/\/geekroo.com\/wiki\/File:Product-Clockatoo-00.JPG\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/geekroo.com\/wiki\/images\/thumb\/6\/67\/Product-Clockatoo-00.JPG\/180px-Product-Clockatoo-00.JPG\" width=\"278\" height=\"192\" \/><\/a><a href=\"http:\/\/geekroo.com\/wiki\/File:Product-Clockatoo-03.JPG\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/geekroo.com\/wiki\/images\/thumb\/4\/43\/Product-Clockatoo-03.JPG\/180px-Product-Clockatoo-03.JPG\" width=\"280\" height=\"195\" \/><\/a><\/div>\n<\/div>\n<div><\/div>\n<p>Now you need to configure the I2C in case this is not already done. After log in, edit this file\u00a0: <strong><code>\/etc\/modules<\/code><\/strong> by running<strong> sudo nano <code>\/etc\/modules <\/code><\/strong>and add these two lines to the end of the file if they&#8217;re not there:<\/p>\n<p><strong><code> i2c-bcm2708<br \/>\ni2c-dev <\/code> <\/strong><\/p>\n<p>Then your <code>\/etc\/modules<\/code> should be looking like this:<\/p>\n<div>\n<div><a href=\"http:\/\/geekroo.com\/wiki\/File:Product-Clockatoo-Install_01.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/geekroo.com\/wiki\/images\/thumb\/2\/28\/Product-Clockatoo-Install_01.jpg\/500px-Product-Clockatoo-Install_01.jpg\" width=\"500\" height=\"314\" \/><\/a><\/p>\n<div><\/div>\n<\/div>\n<\/div>\n<p>Now it&#8217;s time to see if the Clockatoo has been properly connected to the Raspberry Pi or not. Run the following command, to install the i2c-tools utility:<\/p>\n<p><code> sudo apt-get install python-smbus<br \/>\nsudo apt-get install i2c-tools <\/code><\/p>\n<p>After the installation, type the follow command to see all the connected devices.<br \/>\nFor the Raspberry Pi Revision 1:<\/p>\n<p><code> sudo i2cdetect -y 0 <\/code><\/p>\n<p>For the Raspberry Pi Revision 2:<\/p>\n<p><code> sudo i2cdetect -y 1 <\/code><\/p>\n<p>If your Clockatoo has been properly stacked on the top of the Raspberry Pi, you should be able to see these two numbers: 68 and 70<\/p>\n<div>\n<div><a href=\"http:\/\/geekroo.com\/wiki\/File:Product-Clockatoo-Install_02.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/geekroo.com\/wiki\/images\/thumb\/7\/7f\/Product-Clockatoo-Install_02.jpg\/500px-Product-Clockatoo-Install_02.jpg\" width=\"500\" height=\"314\" \/><\/a><\/div>\n<\/div>\n<p>Now to download the software for Clockatoo type the following commands:<br \/>\n<code> sudo apt-get install git<br \/>\ngit clone <a href=\"\/\/github.com\/geekroo\/Geekroo-Product-Clockatoo.git\" rel=\"nofollow\">git:\/\/github.com\/geekroo\/Geekroo-Product-Clockatoo.git<\/a> <\/code><\/p>\n<p>After downloading, if you use <code>ls<\/code> command, you should be able to see the &#8220;Geekroo-Product-Clockatoo&#8221; folder. Like this:<\/p>\n<div>\n<div><a href=\"http:\/\/geekroo.com\/wiki\/File:Product-Clockatoo-Install_03.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/geekroo.com\/wiki\/images\/5\/5b\/Product-Clockatoo-Install_03.jpg\" width=\"666\" height=\"230\" \/><\/a><\/div>\n<\/div>\n<p>Go into that folder, and run the &#8220;Clockatoo&#8221; script:<\/p>\n<p><code> cd Geekroo-Product-Clockatoo\/<br \/>\ncd R2.0\/ <\/code>(If you&#8217;re using the Raspberry Pi Revision 2)<\/p>\n<p>Or<\/p>\n<p><code> cd Geekroo-Product-Clockatoo\/<br \/>\ncd R1.0\/ <\/code>(If you&#8217;re using the Raspberry Pi Revision 1)<\/p>\n<p>Now run the script:<\/p>\n<p><code> sudo python clockatoo.py <\/code><\/p>\n<p>Now the Clockatoo should be working for you by displaying the time on the LCD screen. The Raspberry Pi keeps updating the time automatically from the global ntp (nework time protocol) servers. Clockatoo gets time from the Raspberry Pi. So you can always see the current time.<\/p>\n<p>http:\/\/geekroo.com\/wiki\/Manual:RPi_Expansion_Board_-_Clockatoo<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2) Using the incorporated buzzer as an alarm<\/strong><\/p>\n<p>The buzzer can be controlled through the WiringPi library. WiringPi2 for Python is an excellent GPIO handling system written by Gordon Henderson and packaged for Python by Phil Howard. Installing WiringPi2 for Python is very simple, but there are a couple of required packages, so we\u2019ll install those first. Before we install anything, though, let\u2019s update the package first<\/p>\n<p><code>sudo apt-get update<\/code><br \/>\nThis is what should happen\u2026<\/p>\n<p><a href=\"http:\/\/raspi.tv\/wp-content\/uploads\/2013\/05\/update2.png\"><img decoding=\"async\" title=\"update2\" alt=\"\" src=\"http:\/\/raspi.tv\/wp-content\/uploads\/2013\/05\/update2.png\" width=\"658\" \/><\/a><\/p>\n<p>Now we need the following.<br \/>\n<code>sudo apt-get install python-dev python-pip<\/code><\/p>\n<p>Now we\u2019re ready to install WiringPi2 for Python itself<br \/>\n<code>sudo pip install wiringpi2<\/code><\/p>\n<p>You will see lots of messages. pip, the python package installer that you just installed, is compiling WiringPi2 and installing it all for you. After lots of messages starting with \u201cgcc \u2013 pthread\u201d, you should see this\u2026<\/p>\n<p><a href=\"http:\/\/raspi.tv\/wp-content\/uploads\/2013\/05\/wpinstalled.png\"><img decoding=\"async\" title=\"wpinstalled\" alt=\"\" src=\"http:\/\/raspi.tv\/wp-content\/uploads\/2013\/05\/wpinstalled.png\" width=\"284\" \/><\/a><\/p>\n<p>Now you should be good to go. Let\u2019s check that it works with a live Python environment. Type the following commands in the terminal, with end-line between each of them.<\/p>\n<p><code>sudo python<\/code><br \/>\n<code>import wiringpi2<br \/>\nwiringpi2.piBoardRev()<\/code><\/p>\n<p><a href=\"http:\/\/raspi.tv\/wp-content\/uploads\/2013\/05\/wptest.png\"><img decoding=\"async\" title=\"wptest\" alt=\"\" src=\"http:\/\/raspi.tv\/wp-content\/uploads\/2013\/05\/wptest.png\" width=\"571\" \/><\/a><\/p>\n<p>We just imported wiringpi2 and used one of its new functions piBoardRev() which is the built-in Raspberry Pi revision checker.\u00a0 If that all works as it should, type <strong><code>ctrl+d<\/code><\/strong> to exit python<\/p>\n<p>You are installed and ready for action with WiringPi2\u2032s GPIO features.<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"uDxXI5Cz4g\"><p><a href=\"https:\/\/raspi.tv\/how-to-install-wiringpi2-for-python-on-the-raspberry-pi\">How to install WiringPi2 for Python on the Raspberry Pi<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;How to install WiringPi2 for Python on the Raspberry Pi&#8221; &#8212; RasPi.TV\" src=\"https:\/\/raspi.tv\/how-to-install-wiringpi2-for-python-on-the-raspberry-pi\/embed#?secret=uDxXI5Cz4g\" data-secret=\"uDxXI5Cz4g\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p>Now in order to make the buzzer work you need to type the following commands in the terminal (one at a time):<\/p>\n<p><strong>sudo python<\/strong><\/p>\n<pre><strong>import wiringpi2 as wiringpi \r\nwiringpi.wiringPiSetup()\r\nwiringpi.softToneCreate(7)\r\nwiringpi.softToneWrite(7,1)\t\t\t\t\t\r\n<\/strong><\/pre>\n<p>The softTone library is used for producing the signal on the GPIO which is connected to the buzzer. The buzzer is connected to GPIO Pin 4, which corresponds to WiringPi GPIO Pin 7. The second parameter for softToneWrite is the frequency, drive it higher and the alarm sound will become steadily more irritating until you&#8217;re sure to wake up!<\/p>\n<p>http:\/\/pi.gadgetoid.com\/pinout\/clockatoo<\/p>\n<p>Pressing <strong>Ctrl+D<\/strong> will terminate the python program but will not make the annoying sound disappear. For this, you need to type in the terminal a command which will set the GPIO 7 from High to Low. The following will do: <strong>gpio mode 7 in<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><!--\nPRE.ctl { font-family: \"Lohit Hindi\",monospace; }P { margin-bottom: 0.21cm; }A:link {  }\n--><b>3) Displaying text on the Clockatoo LCD<\/b><\/p>\n<p>By modifying the Clockatoo library provided by Geekroo, text rather than the actual time can be displayed onto the LED Screen. The 4 digit 7-segment display is designed for digits so some of the letters (such as &#8216;m&#8217; or &#8216;w&#8217;) will appear a bit different on the LED but should make sense.<\/p>\n<p>First, make sure that the <b>clockatoo.py <\/b>program used to display time is not running as it will interfere with the text displaying. Then, you will need to modify the <b>Raspi_7Segment.py <\/b>file by typing (when located in the <b>\/Geekroo-Product-Clockatoo\/R2.0<\/b> directory) <b>sudo nano Raspi_7Segment.py. <\/b> This will open up the python script in which you need to copy and paste the following bits of code:<\/p>\n<pre>\u00a0# Basic text lookup table ( a-z, -, _ space, 0-9 ), lowercase only<\/pre>\n<div dir=\"LTR\" id=\"LC19\">\n<pre>\u00a0\u00a0letters = { 'a':0x77, 'b':0x7c, 'c':0x39, 'd':0x5e, 'e':0x79, 'f':0x71, \\<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC20\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'g':0x3d, 'h':0x74, 'i':0x06, 'j':0x1e, 'k':0x76, 'l':0x38, \\<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC21\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'm':0x15, 'n':0x54, 'o':0x5c, 'p':0x73, 'q':0x67, 'r':0x50, \\<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC22\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0's':0x6d, 't':0x78, 'u':0x3e, 'v':0x1c, 'w':0x2a, 'x':0x76, \\<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC23\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'y':0x66, 'z':0x5b, '0':0x3f, '1':0x30, '2':0x5b, '3':0x4f, \\<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC24\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'4':0x66, '5':0x6d, '6':0x7d, '7':0x07, '8':0x7f, '9':0x6f, \\<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC25\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0' ':0x00, '-':0x40, '_':0x08, '.':0x80 }<\/pre>\n<\/div>\n<p>This needs to be added after the enumeration: <b>digits = [ 0x3F, 0x06, 0x5B<\/b>, \u2026&#8230;&#8230; and before the <b>#Constructor. <\/b>This code enumerates all the letters\/digits and characters which will be needed to display text on the screen and assigns each one of them with a value in hexadecimal which corresponds to certain segments on an LCD digit to be turned ON. For example <b>&#8216;_&#8217;:0x08 <\/b>will only turn ON the lower segment resulting in a <b>\u201cunderscore<\/b>\u201d displayed on the screen.<\/p>\n<p>The following code also needs to be added. This will define a new function called <b>writeTextString <\/b>which will be called every time text is to be displayed on the LCD. It can be added anywhere towards the end of the code, in between two other functions. For example it can be added between <b>def _<\/b><b>init<\/b><span style=\"text-decoration: underline\"><b>_<\/b><\/span><b> <\/b>and <b>def writeDigitRaw. <\/b><\/p>\n<pre>def writeTextString(self, string, speed=0.5):<\/pre>\n<div dir=\"LTR\" id=\"LC34\">\n<pre>\u00a0\u00a0\u00a0\u00a0string = '    ' + string.lower() + '    '<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC35\">\n<pre>\u00a0\u00a0\u00a0\u00a0buf = []<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC36\">\n<pre>\u00a0\u00a0\u00a0\u00a0disp = []<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC37\">\n<pre>\u00a0\u00a0\u00a0\u00a0for c in string:<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC38\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if c in self.letters:<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC39\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buf.append(self.letters[c])<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC40\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else:<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC41\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0continue<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC42\"><\/div>\n<div dir=\"LTR\" id=\"LC43\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if(len(buf) &gt; 3):<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC44\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0disp = buf[-4:]<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC45\"><\/div>\n<div dir=\"LTR\" id=\"LC46\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (len(disp) &gt; 0):<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC47\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.writeDigitRaw(0,disp[0])<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC48\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (len(disp) &gt; 1):<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC49\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.writeDigitRaw(1,disp[1])<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC50\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (len(disp) &gt; 2):<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC51\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.writeDigitRaw(3,disp[2])<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC52\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (len(disp) &gt; 3):<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC53\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.writeDigitRaw(4,disp[3])<\/pre>\n<\/div>\n<div dir=\"LTR\" id=\"LC54\">\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0time.sleep(speed)<\/pre>\n<\/div>\n<p>Once these two pieces of code have been added, save the file with <b>Ctrl+x <\/b>making sure to overwrite it and not saving it under a new name. Now write the following commands in a terminal (with end of line between each command):<\/p>\n<p><b>sudo python <\/b><\/p>\n<pre><b>from Raspi_7Segment import SevenSegment<\/b>\r\n<b>delay_seconds = 0.5<\/b>\r\n<b>segment = SevenSegment(address=0x70)<\/b>\r\n<b>segment.writeTextString('hello world',delay_seconds)<\/b><\/pre>\n<p><b>sudo python <\/b>enables the python environment in the command line. The next line imports the module <b>Raspi_7Segment<\/b> which you have just modified, and creates reference in the current namespace to the object <b>SevenSegment<\/b> located inside the module. Then the <b>segment <\/b>variable initialised and used to call the newly added <b>writeTextString <\/b>function to display the text. The delay controls the speed at which characters scroll off to the left, modify this to scroll faster\/slower.<\/p>\n<p>http:\/\/pi.gadgetoid.com\/post\/047-clockatoo-clock-board-says-hello-world<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1) Getting started and setting the clock Geekroo Raspberry Pi LED Clock Expansion Board &#8211; Clockatoo is an I2C device for the Raspberry Pi. It comes with some Python code to make the &#8220;Clockatoo&#8221; work. Install the 4-digit LED taking care not to put the LED up-side-down (as per Figures below). Then stack the Clockatoo &hellip; <\/p>\n<p><a class=\"more-link block-button\" href=\"https:\/\/blog.soton.ac.uk\/pi\/clockatoo\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":84718,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-130","page","type-page","status-publish","hentry","nodate"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/users\/84718"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":7,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages\/130\/revisions"}],"predecessor-version":[{"id":133,"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/pages\/130\/revisions\/133"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/pi\/wp-json\/wp\/v2\/media?parent=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}