<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://hackingbytes.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://hackingbytes.com/" rel="alternate" type="text/html" hreflang="en" /><updated>2026-06-06T12:24:17+00:00</updated><id>https://hackingbytes.com/feed.xml</id><title type="html">HackingBytes</title><subtitle>Geek&amp;Tech blog on a Raspberry Pi*
</subtitle><author><name>Stefano Balzan</name><email>stefano.balzan@gmail.com</email></author><entry><title type="html">Hello World Camp</title><link href="https://hackingbytes.com/2016/07/12/hello-world-camp.html" rel="alternate" type="text/html" title="Hello World Camp" /><published>2016-07-12T00:00:00+00:00</published><updated>2016-07-12T00:00:00+00:00</updated><id>https://hackingbytes.com/2016/07/12/hello-world-camp</id><content type="html" xml:base="https://hackingbytes.com/2016/07/12/hello-world-camp.html"><![CDATA[<p>I’ve just spent a week in Rapallo, near Genoa, working as a teacher and entertainer for a robotics camp.</p>

<p>It was organised by <a href="https://iit.it/">IIT</a> (Istituto Italiano di Tecnologia) and <a href="http://www.sterrenlab.com/">SterrenLab</a> and was addressed to boys aged 10 - 13.</p>

<p>I worked with two colleagues, Lara and Luca, organizing the week and guiding the group during the activities.
We stayed, together with the participants, in a cozy hotel close to the town centre, going out occasionally to spend some time at the beach and visit IIT in Genoa.</p>

<p>Here are the pictures taken during the camp activities complete with a short description: some lab/activities we carried out during the week, the town and the visit at IIT.</p>

<p>Sunday - 6:10 AM. Departure from Milan, Central Station.</p>

<p><a href="/assets/images/articles/hello-world-camp/departure.jpg"><img src="/assets/images/articles/hello-world-camp/700px/departure.jpg" alt="" /></a></p>

<p>Rapallo, a view from the rooftop of the hotel.</p>

<p><a href="/assets/images/articles/hello-world-camp/rapallo-landscape.jpg"><img src="/assets/images/articles/hello-world-camp/700px/rapallo-landscape.jpg" alt="" /></a></p>

<p>We started with some educational games on Monday. We first built scribbling machines, then some squishy circuits with LEDs and conductive dough.</p>

<div class="grid-container">
<div class="grid grid--px-3">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/scribbling-machines.jpg"><img src="/assets/images/articles/hello-world-camp/420px/scribbling-machines.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/squishy-circuits.jpg"><img src="/assets/images/articles/hello-world-camp/420px/squishy-circuits.jpg" alt="" /></a></p>
    </div>
</div>
</div>

<p>Activities started in the morning right after breakfast and continued until mid-afternoon, interrupted by lunch and some breaks.</p>

<p>We spent a day playing with <a href="https://scratch.mit.edu/">Scratch</a>, creating animations and mini-games, and getting a bit more familiar with programming by solving <a href="https://blockly-games.appspot.com/">Blockly Games</a> challenges.</p>

<p>The second half of the week was committed to building and programming a robot.
After assembling the structure and wiring the sensors, we gave the kids some code to experiment with and modify.<br />
At the end every group built an autonomous robot that moved along the clap of one’s hands and avoided obstacles.</p>

<p><a href="/assets/images/articles/hello-world-camp/robot.jpg"><img src="/assets/images/articles/hello-world-camp/700px/robot.jpg" alt="" /></a></p>

<p>During the week we also had time to relax, both at the hotel and outside. Here’s a picture of the beach!</p>

<p><a href="/assets/images/articles/hello-world-camp/rapallo-beach.jpg"><img src="/assets/images/articles/hello-world-camp/700px/rapallo-beach.jpg" alt="" /></a></p>

<p>Last but most important, we spent a day visiting IIT, in Genoa.
I had the chance to see in person two different humanoid robots being developed there:</p>
<ul>
  <li><strong>Walkman</strong>, a 1.85m tall 120kg heavy robot, developed to work in disaster scenarios</li>
  <li><strong>iCub</strong>, a “child” robot built to support research in embodied artificial intelligence.</li>
</ul>

<p><a href="/assets/images/articles/hello-world-camp/iit-entrance.jpg"><img src="/assets/images/articles/hello-world-camp/700px/iit-entrance.jpg" alt="" /></a></p>

<div class="grid-container">
<div class="grid grid--px-3">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/walkman.jpg"><img src="/assets/images/articles/hello-world-camp/420px/walkman.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/icub-in-action.jpg"><img src="/assets/images/articles/hello-world-camp/420px/icub-in-action.jpg" alt="" /></a></p>
    </div>
</div>
</div>

<p>Saturday, the day of the departure, everyone had the chance to show what they had created during the week to their parents.</p>

<div class="grid-container">
<div class="grid grid--px-3">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/presentation-day-scribbling.jpg"><img src="/assets/images/articles/hello-world-camp/420px/presentation-day-scribbling.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/presentation-day-robot.jpg"><img src="/assets/images/articles/hello-world-camp/420px/presentation-day-robot.jpg" alt="" /></a></p>
    </div>
</div>
</div>

<p>Right after that, I took a train home and I got back right on time for dinner :)</p>

<p>That’s all. It was an intense week. Working with 30 kids, organising all the activities and tutoring them wasn’t an easy task, but it went greatly and everybody was satisfied.</p>

<p>Here are few other photos I took:</p>

<div class="grid-container">
<div class="grid grid--px-3">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/rapallo-landscape-by-night.jpg"><img src="/assets/images/articles/hello-world-camp/420px/rapallo-landscape-by-night.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/walkman-in-action.jpg"><img src="/assets/images/articles/hello-world-camp/420px/walkman-in-action.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/me-with-icub.jpg"><img src="/assets/images/articles/hello-world-camp/420px/me-with-icub.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/hello-world-camp/story3.jpg"><img src="/assets/images/articles/hello-world-camp/420px/story3.jpg" alt="" /></a></p>
    </div>
</div>
</div>]]></content><author><name>Stefano Balzan</name></author><summary type="html"><![CDATA[I’ve just spent a week in Rapallo, near Genoa, working as a teacher and entertainer for a robotics camp. It was organised by IIT (Istituto Italiano di Tecnologia) and SterrenLab and was addressed to boys aged 10 - 13. I worked with two colleagues, Lara and Luca, organizing the week and guiding the group during the activities. We stayed, together with the participants, in a cozy hotel close to the town centre, going out occasionally to spend some time at the beach and visit IIT in Genoa. Here are the pictures taken during the camp activities complete with a short description: some lab/activities we carried out during the week, the town and the visit at IIT. Sunday - 6:10 AM. Departure from Milan, Central Station. Rapallo, a view from the rooftop of the hotel. We started with some educational games on Monday. We first built scribbling machines, then some squishy circuits with LEDs and conductive dough. Activities started in the morning right after breakfast and continued until mid-afternoon, interrupted by lunch and some breaks. We spent a day playing with Scratch, creating animations and mini-games, and getting a bit more familiar with programming by solving Blockly Games challenges. The second half of the week was committed to building and programming a robot. After assembling the structure and wiring the sensors, we gave the kids some code to experiment with and modify. At the end every group built an autonomous robot that moved along the clap of one’s hands and avoided obstacles. During the week we also had time to relax, both at the hotel and outside. Here’s a picture of the beach! Last but most important, we spent a day visiting IIT, in Genoa. I had the chance to see in person two different humanoid robots being developed there: Walkman, a 1.85m tall 120kg heavy robot, developed to work in disaster scenarios iCub, a “child” robot built to support research in embodied artificial intelligence. Saturday, the day of the departure, everyone had the chance to show what they had created during the week to their parents. Right after that, I took a train home and I got back right on time for dinner :) That’s all. It was an intense week. Working with 30 kids, organising all the activities and tutoring them wasn’t an easy task, but it went greatly and everybody was satisfied. Here are few other photos I took:]]></summary></entry><entry><title type="html">Arduino for physicists</title><link href="https://hackingbytes.com/2016/05/03/arduino-for-physicists.html" rel="alternate" type="text/html" title="Arduino for physicists" /><published>2016-05-03T00:00:00+00:00</published><updated>2016-05-03T00:00:00+00:00</updated><id>https://hackingbytes.com/2016/05/03/arduino-for-physicists</id><content type="html" xml:base="https://hackingbytes.com/2016/05/03/arduino-for-physicists.html"><![CDATA[<p>A week ago I had the chance to organize a workshop with Francesco Maiocchi, a colleague of mine, at the department of physics.</p>

<p>The workshop was part of a wider project, <strong>LCM OpenLab</strong>, a series of conferences and lessons aimed at introducing IT tools &amp; free software to physics students.<br />
Being a member of the <a href="http://lcm.mi.infn.it" target="_blank">LCM Staff</a> and one of the minds behind the OpenLab initiative, I could’t miss the chance to give a talk myself!</p>

<p>I and Francesco, a first year student, decided to introduce the <strong>Arduino platform</strong> to the students giving them the opportunity to try out the board and build different devices.</p>

<p>We believe Arduino provides a simple but yet powerful interface to the microcontrollers world and it represents a great opportunity for anyone involved in science or tech. <u>Every physics student should at least know what Arduino enables him to do!</u></p>

<div class="grid-container">
<div class="grid grid--p-3">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/arduino-for-physicists/lcm-poster.png"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/lcm-poster.jpg" alt="" /></a></p>
    </div>

  <div class="cell cell--6" style="display: flex; flex-direction: column;">
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino8.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino8.jpg" alt="" /></a></p>
      <div style="flex: 1"></div>
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino1.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino1.jpg" alt="" /></a></p>
    </div>
</div>
</div>

<p>The workshop consisted of a 2 hours activity. Right after a <strong>short presentation</strong> of the platform - available <a href="/assets/images/articles/arduino-for-physicists/slideshow.pdf">here</a> - all the students had the chance to <strong>work with the board</strong> and build some circuits.</p>

<p>Divided into small groups, the participants started wiring a simple led circuit and controlling it with a few lines of code. This first activity went pretty smooth, since all the participants, being physics student, had already took programming classes and knew how to write simple C/C++ statements.</p>

<p>Then we moved onto a more challenging task, connecting and <strong>controlling a 16x2 LCD character display</strong>. It turned out to be quite easy and fun eventually, even for those less experienced in electronics, thanks to a <a href="/assets/images/articles/arduino-for-physicists/schematic.png">simple visual schematic</a> I had prepared with the <a href="http://fritzing.org/" target="_blank">Fritzing software</a>.</p>

<p>Done with LCD wiring and testing, each group moved onto a different project, all of them using the previously wired display. <strong>We had prepared in advance four different kits</strong>, one for each group, with all the necessary  - hardware &amp; software -  to build:</p>
<ul>
  <li>an <em>electrical conductivity meter for liquids</em></li>
  <li>a <em>1-axis servo-controlled stabilizer</em></li>
  <li>a <em>Bluetooth remote display</em></li>
  <li>an <em>ultrasound distance meter</em></li>
</ul>

<p>For this final project we provided the source code ready for upload, since we didn’t have enough time to explain all the advanced software features and programming paradigm.</p>

<p><strong>More than 35 people signed up</strong> for the Workshop and we had to repeat the event the next week. At the end  everybody was satisfied and appreciated the preparation and the support we provided them during the activity.<br />
Many participants also asked us where they could get an Arduino board and additional resources.</p>

<p>Here are some pictures of the event:</p>

<div class="grid-container">
<div class="grid grid--px-3">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino6.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino6.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino5.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino5.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino3.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino3.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino4.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino4.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino2.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino2.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/arduino-for-physicists/arduino7.jpg"><img src="/assets/images/articles/arduino-for-physicists/thumbnail/arduino7.jpg" alt="" /></a></p>
    </div>
</div>
</div>]]></content><author><name>Stefano Balzan</name></author><summary type="html"><![CDATA[A week ago I had the chance to organize a workshop with Francesco Maiocchi, a colleague of mine, at the department of physics. The workshop was part of a wider project, LCM OpenLab, a series of conferences and lessons aimed at introducing IT tools &amp; free software to physics students. Being a member of the LCM Staff and one of the minds behind the OpenLab initiative, I could’t miss the chance to give a talk myself! I and Francesco, a first year student, decided to introduce the Arduino platform to the students giving them the opportunity to try out the board and build different devices. We believe Arduino provides a simple but yet powerful interface to the microcontrollers world and it represents a great opportunity for anyone involved in science or tech. Every physics student should at least know what Arduino enables him to do! The workshop consisted of a 2 hours activity. Right after a short presentation of the platform - available here - all the students had the chance to work with the board and build some circuits. Divided into small groups, the participants started wiring a simple led circuit and controlling it with a few lines of code. This first activity went pretty smooth, since all the participants, being physics student, had already took programming classes and knew how to write simple C/C++ statements. Then we moved onto a more challenging task, connecting and controlling a 16x2 LCD character display. It turned out to be quite easy and fun eventually, even for those less experienced in electronics, thanks to a simple visual schematic I had prepared with the Fritzing software. Done with LCD wiring and testing, each group moved onto a different project, all of them using the previously wired display. We had prepared in advance four different kits, one for each group, with all the necessary - hardware &amp; software - to build: an electrical conductivity meter for liquids a 1-axis servo-controlled stabilizer a Bluetooth remote display an ultrasound distance meter For this final project we provided the source code ready for upload, since we didn’t have enough time to explain all the advanced software features and programming paradigm. More than 35 people signed up for the Workshop and we had to repeat the event the next week. At the end everybody was satisfied and appreciated the preparation and the support we provided them during the activity. Many participants also asked us where they could get an Arduino board and additional resources. Here are some pictures of the event:]]></summary></entry><entry><title type="html">A simple, stacking, Real Time Clock for Raspberry</title><link href="https://hackingbytes.com/2015/04/25/ds1307-rtc-raspberry.html" rel="alternate" type="text/html" title="A simple, stacking, Real Time Clock for Raspberry" /><published>2015-04-25T00:00:00+00:00</published><updated>2015-04-25T00:00:00+00:00</updated><id>https://hackingbytes.com/2015/04/25/ds1307-rtc-raspberry</id><content type="html" xml:base="https://hackingbytes.com/2015/04/25/ds1307-rtc-raspberry.html"><![CDATA[<p class="warning"><strong>NOTE:</strong> The RTC module is compatible with Raspberry A+ / B+ / 2.<br />
This tutorial was originally written for a Raspberry B+ running Arch Linux ARM, however you should be able to adapt it to other configurations with few or even no changes.</p>

<p>Lately, in my few spare time I tried to play around with the Pi.</p>

<p>Looking for something simple that I could build by myself I decided to add a simple hardware clock.
I picked a simple DS1307, although not very precise, for many reasons:</p>

<ul>
  <li>it was cheap</li>
  <li>required a simple circuitry and few components</li>
  <li>it could be easily connected through a I2C interface</li>
  <li>Arch Linux ARM already has a kernel module compiled for it.</li>
</ul>

<p>I looked around on the Web for a prebuilt DS1307 RTC, like those sold by SparkFun, but the one I wanted was so expensive I would have built one by myself for half the price.
And so I did! It was even fun and I finally learned how to properly sold on a perfboard without spilling solder everywhere ;)</p>

<p>Here’s a short but exhaustive guide to build one.</p>

<p>For this project you need:</p>

<ul>
  <li>1x DS1307 chip</li>
  <li>1x IC 2x4 socket</li>
  <li>1x 32.768 kHz crystal (Load-capacitance 12.5 pF)</li>
  <li>1x CR2032 battery and a battery holder</li>
  <li>2x 1000 $\Omega$ resistors</li>
  <li>a 2x20 header (or better a stacking header)</li>
  <li>a piece of perfboard (at least 20x12 holes) and some small wires</li>
</ul>

<p>Here’s the scheme of the RTC and some pictures showing the process:</p>

<p><img src="/assets/images/articles/ds1307-rtc-raspberry/rtc-ds1307-scheme.jpg" alt="" class="center" /></p>

<p>First of all solder the components on the perfboard following the circuit diagram above leaving some space for the 2x20 header, which will be soldered later.</p>

<p><strong>[Click images to see hi-res version]</strong></p>

<div class="grid-container">
<div class="grid grid--p-2">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/building-bottom.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/building-bottom.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/building-bottom.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/building-bottom2.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/building-top.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/building-top.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/building-top2.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/building-top2.jpg" alt="" /></a></p>
    </div>
</div>
</div>

<p>Now solder the header and connect the <strong>+5V</strong>, <strong>GND</strong>, <strong>SDA</strong> and <strong>SDL</strong> wires to the header.
Optionally you could just connect the four wires to the GPIO without any header.</p>

<p>Since the I2C inteface supports multiple devices and I’ll probably need to stack something else on the Pi I decided to install a stacking header, like <a href="https://www.adafruit.com/products/1979">these found @ adafruit.com</a>.</p>

<p>If you are planning to stack something else on top of the Pi pick a stacking header instead of a simple one.
Please note that soldering the four wires to the stacking header will be a bit tricky. Using a double side perfboard would probably make things easier.</p>

<p>I used 4 1x10 stacking headers (usually sold for arduino projects) and arranged them into a 2x20, since I couldn’t find a cheap 2x20. I also cut two 2x20 pieces of perfboard and used them to create a solid base for the header. I soldered the wires to their pins and eventually fixed everything with some hot glue, making the board rock solid.</p>

<p>Look at the pictures for a better description. You may also find by yourself a good way to solder the header.</p>

<div class="grid-container">
<div class="grid grid--p-2">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/glued-top.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/glued-top.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/glued-bottom.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/glued-bottom.jpg" alt="" /></a></p>
    </div>
</div>
</div>

<p>This what I’ve got in the end and how it looks stacked on the Raspberry Pi B+</p>

<div class="grid-container">
<div class="grid grid--p-2">
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/final.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/final.jpg" alt="" /></a></p>
    </div>
  <div class="cell cell--6">
      <p><a href="/assets/images/articles/ds1307-rtc-raspberry/hi-res/final-on-raspberry.jpg"><img src="/assets/images/articles/ds1307-rtc-raspberry/preview/final-on-raspberry.jpg" alt="" /></a></p>
    </div>
</div>
</div>

<p>Good, it’s now time to connect the Real Time Clock to the raspberry and see what happens.</p>

<p>This is the procedure I’ve followed, using root privileges:</p>

<ol>
  <li>With the Pi running edit <strong><em>/boot/config.txt</em></strong> adding or uncommenting
    <div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="w"> </span><span class="py">device_tree_param</span><span class="p">=</span><span class="s">i2c_arm=on</span>
</code></pre></div>    </div>
    <p>thus enabling I2C interface. This is required since Kernel v. 3.18 (~ Jan 2015) which introduced Device Tree support. Read <a href="https://www.raspberrypi.org/forums/viewtopic.php?p=675658#p675658">this article @ raspberrypi.org</a> for further infos.</p>
  </li>
  <li>
    <p>Create a file <strong><em>/etc/modules-load.d/i2c-rtc.conf</em></strong> containing</p>

    <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> i2c-dev
 rtc-ds1307
</code></pre></div>    </div>

    <p>Although point <strong>1.</strong> should be enough I also added the <b>i2c-dev</b> module explicitly.</p>
  </li>
  <li>
    <p>Now power off the Pi, plug the RTC board on the GPIO and power it on again.</p>
  </li>
  <li>
    <p>Typing a couple of lines in the shell will reveal if the hard work done up to this moment was worth it ;)</p>

    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nv">$ </span><span class="nb">echo </span>ds1307 0x68 <span class="o">&gt;</span> /sys/class/i2c-adapter/i2c-1/new_device
 <span class="nv">$ </span>hwclock <span class="nt">-r</span>
</code></pre></div>    </div>

    <p>If everything goes fine the Raspberry should be able to access the RTC through the I2C interface and read the time stored on it. It should be set around year 2000 or even before.</p>
  </li>
  <li>If you’ve made it so far, congratulations!<br />
 Now the hardware clock (RTC) should be synchronized with system clock. If the Pi was connected to the Internet since boot, it should be as easy as running <code class="language-plaintext highlighter-rouge">hwclock -w</code>.<br />
 Else read the man page to find out how to set it manually.</li>
</ol>

<p>I wanted to achieve a behavior similar to a personal computer, where RTC time is loaded immediately at boot by the kernel. Unfortunately Arch Linux ARM for raspberry doesn’t provide Real Time Clock support already built into the Kernel, since a stock RPi does not come with one preinstalled.</p>

<p>The cleanest solution would be recompiling the kernel with static RTC support. A good article explaining this can be found <a href="http://blog.lemoneerlabs.com/post/time-y-wimey-stuff">here at lemoneerlabs.com</a></p>

<p>Another possibility is reading the clock and setting time from user space, and that’s what I did, inspired by laziness :D</p>

<p>Well, laziness apart, I picked it because I didn’t want to interfere with kernel updates and have to recompile it manually in the future.</p>

<p>Now you have to mess a bit with systemd services:</p>

<ol start="6">
  <li>
    <p>Create and enable <strong>rtc-init</strong> systemd service:
write in <strong><em>/etc/systemd/system/</em></strong> a <strong><em>rtc-init.service</em></strong> file containing the following lines</p>

    <div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="w"> </span><span class="nn">[Unit]</span><span class="w">
 </span><span class="py">Description</span><span class="p">=</span><span class="s">RTC Clock Setup and Time Sync</span>
<span class="w"> </span><span class="py">Before</span><span class="p">=</span><span class="s">netctl-auto@eth0.service</span>
<span class="w">    
 </span><span class="nn">[Service]</span><span class="w">
 </span><span class="py">Type</span><span class="p">=</span><span class="s">oneshot</span>
<span class="w"> </span><span class="py">ExecStart</span><span class="p">=</span><span class="s">/usr/lib/systemd/scripts/rtc-setup</span>
<span class="w">    
 </span><span class="nn">[Install]</span><span class="w">
 </span><span class="py">WantedBy</span><span class="p">=</span><span class="s">multi-user.target</span>
</code></pre></div>    </div>

    <p>Then add in <strong><em>/usr/lib/systemd/scripts/</em></strong> an <strong><em>rtc-setup</em></strong> shell script like this</p>

    <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="c">#!/bin/sh</span>
    
 <span class="nb">echo </span>ds1307 0x68 <span class="o">&gt;</span>/sys/bus/i2c/devices/i2c-1/new_device
 <span class="nb">echo</span> <span class="s2">"RTC DS1307 Installed"</span>
    
 hwclock <span class="nt">-s</span>
 <span class="nb">echo</span> <span class="s2">"System Time synced with RTC Time"</span>
</code></pre></div>    </div>

    <p>and give it right permissions with <code class="language-plaintext highlighter-rouge">chmod 755 rtc-setup</code>.<br />
 Run <code class="language-plaintext highlighter-rouge">systemctl enable rtc-init</code> to enable the service at startup.</p>
  </li>
  <li>
    <p>Move to <strong><em>/usr/lib/systemd/system/</em></strong> and make a backup copy of <strong><em>systemd-timesyncd</em></strong> with
<code class="language-plaintext highlighter-rouge">cp systemd-timesyncd systemd-timesyncd.original</code>, then edit <strong><em>systemd-timesyncd</em></strong> as shown below</p>

    <div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="w"> </span><span class="nn">[Unit]</span><span class="w">
    
 </span><span class="na">...</span><span class="w">
    
 </span><span class="py">After</span><span class="p">=</span><span class="s">systemd-remount-fs.service systemd-tmpfiles-setup.service systemd-sysusers.service rtc-init.service</span>
<span class="w"> </span><span class="py">Before</span><span class="p">=</span><span class="s">time-sync.target shutdown.target</span>
<span class="w"> </span><span class="py">Conflicts</span><span class="p">=</span><span class="s">shutdown.target</span>
<span class="w">    
 </span><span class="na">...</span><span class="w">
    
 </span><span class="nn">[Install]</span><span class="w">
 </span><span class="py">WantedBy</span><span class="p">=</span><span class="s">multi-user.target</span>
</code></pre></div>    </div>
  </li>
  <li>
    <p>Edit <strong><em>/etc/netctl/eth0</em></strong> (file name may vary based on Ethernet interface name) commenting out <em>ExecUpPost</em> line:</p>

    <div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="w"> </span><span class="py">Description</span><span class="p">=</span><span class="s">'A basic dhcp ethernet connection'</span>
<span class="w"> </span><span class="py">Interface</span><span class="p">=</span><span class="s">eth0</span>
<span class="w"> </span><span class="py">Connection</span><span class="p">=</span><span class="s">ethernet</span>
<span class="w"> </span><span class="py">IP</span><span class="p">=</span><span class="s">dhcp</span>
<span class="w"> </span><span class="c">#ExecUpPost='/usr/bin/ntpd -gq || true'
</span><span class="w">    
 </span><span class="c">## for DHCPv6
</span><span class="w"> </span><span class="c">#IP6=dhcp
</span><span class="w"> </span><span class="c">## for IPv6 autoconfiguration
</span><span class="w"> </span><span class="c">#IP6=stateless
</span></code></pre></div>    </div>

    <p>This disables automatic time sync with <b>ntpd</b> (at network startup during boot), since it’s already performed by <b>systemd-timesyncd</b> service.<br /></p>
  </li>
  <li>
    <p>Eventually run <code class="language-plaintext highlighter-rouge">$ timedatectl set-ntp true</code> to enable the edited version of <strong>systemd-timesyncd</strong> service</p>
  </li>
</ol>

<p>Reboot and enjoy, your Pi should now load the rtc time at startup (in a few seconds). Then, if you are connected to the internet the <strong>systemd-timesyncd</strong> service fetches current time with Simple NTP protocol and syncs it with system time and hardware time (your RTC).</p>

<p>I measured the clock drift disabling <strong>systemd-timesyncd</strong> service for a couple of days. It turned out that the clock has an accuracy of 20 ppm, it lose a couple of seconds each day. It was more than acceptable for me, since my Raspberry is always online and can sync time periodically.</p>]]></content><author><name>Stefano Balzan</name></author><summary type="html"><![CDATA[NOTE: The RTC module is compatible with Raspberry A+ / B+ / 2. This tutorial was originally written for a Raspberry B+ running Arch Linux ARM, however you should be able to adapt it to other configurations with few or even no changes. Lately, in my few spare time I tried to play around with the Pi. Looking for something simple that I could build by myself I decided to add a simple hardware clock. I picked a simple DS1307, although not very precise, for many reasons: it was cheap required a simple circuitry and few components it could be easily connected through a I2C interface Arch Linux ARM already has a kernel module compiled for it. I looked around on the Web for a prebuilt DS1307 RTC, like those sold by SparkFun, but the one I wanted was so expensive I would have built one by myself for half the price. And so I did! It was even fun and I finally learned how to properly sold on a perfboard without spilling solder everywhere ;) Here’s a short but exhaustive guide to build one. For this project you need: 1x DS1307 chip 1x IC 2x4 socket 1x 32.768 kHz crystal (Load-capacitance 12.5 pF) 1x CR2032 battery and a battery holder 2x 1000 $\Omega$ resistors a 2x20 header (or better a stacking header) a piece of perfboard (at least 20x12 holes) and some small wires Here’s the scheme of the RTC and some pictures showing the process: First of all solder the components on the perfboard following the circuit diagram above leaving some space for the 2x20 header, which will be soldered later. [Click images to see hi-res version] Now solder the header and connect the +5V, GND, SDA and SDL wires to the header. Optionally you could just connect the four wires to the GPIO without any header. Since the I2C inteface supports multiple devices and I’ll probably need to stack something else on the Pi I decided to install a stacking header, like these found @ adafruit.com. If you are planning to stack something else on top of the Pi pick a stacking header instead of a simple one. Please note that soldering the four wires to the stacking header will be a bit tricky. Using a double side perfboard would probably make things easier. I used 4 1x10 stacking headers (usually sold for arduino projects) and arranged them into a 2x20, since I couldn’t find a cheap 2x20. I also cut two 2x20 pieces of perfboard and used them to create a solid base for the header. I soldered the wires to their pins and eventually fixed everything with some hot glue, making the board rock solid. Look at the pictures for a better description. You may also find by yourself a good way to solder the header. This what I’ve got in the end and how it looks stacked on the Raspberry Pi B+ Good, it’s now time to connect the Real Time Clock to the raspberry and see what happens. This is the procedure I’ve followed, using root privileges: With the Pi running edit /boot/config.txt adding or uncommenting device_tree_param=i2c_arm=on thus enabling I2C interface. This is required since Kernel v. 3.18 (~ Jan 2015) which introduced Device Tree support. Read this article @ raspberrypi.org for further infos. Create a file /etc/modules-load.d/i2c-rtc.conf containing i2c-dev rtc-ds1307 Although point 1. should be enough I also added the i2c-dev module explicitly. Now power off the Pi, plug the RTC board on the GPIO and power it on again. Typing a couple of lines in the shell will reveal if the hard work done up to this moment was worth it ;) $ echo ds1307 0x68 &gt; /sys/class/i2c-adapter/i2c-1/new_device $ hwclock -r If everything goes fine the Raspberry should be able to access the RTC through the I2C interface and read the time stored on it. It should be set around year 2000 or even before. If you’ve made it so far, congratulations! Now the hardware clock (RTC) should be synchronized with system clock. If the Pi was connected to the Internet since boot, it should be as easy as running hwclock -w. Else read the man page to find out how to set it manually. I wanted to achieve a behavior similar to a personal computer, where RTC time is loaded immediately at boot by the kernel. Unfortunately Arch Linux ARM for raspberry doesn’t provide Real Time Clock support already built into the Kernel, since a stock RPi does not come with one preinstalled. The cleanest solution would be recompiling the kernel with static RTC support. A good article explaining this can be found here at lemoneerlabs.com Another possibility is reading the clock and setting time from user space, and that’s what I did, inspired by laziness :D Well, laziness apart, I picked it because I didn’t want to interfere with kernel updates and have to recompile it manually in the future. Now you have to mess a bit with systemd services: Create and enable rtc-init systemd service: write in /etc/systemd/system/ a rtc-init.service file containing the following lines [Unit] Description=RTC Clock Setup and Time Sync Before=netctl-auto@eth0.service [Service] Type=oneshot ExecStart=/usr/lib/systemd/scripts/rtc-setup [Install] WantedBy=multi-user.target Then add in /usr/lib/systemd/scripts/ an rtc-setup shell script like this #!/bin/sh echo ds1307 0x68 &gt;/sys/bus/i2c/devices/i2c-1/new_device echo "RTC DS1307 Installed" hwclock -s echo "System Time synced with RTC Time" and give it right permissions with chmod 755 rtc-setup. Run systemctl enable rtc-init to enable the service at startup. Move to /usr/lib/systemd/system/ and make a backup copy of systemd-timesyncd with cp systemd-timesyncd systemd-timesyncd.original, then edit systemd-timesyncd as shown below [Unit] ... After=systemd-remount-fs.service systemd-tmpfiles-setup.service systemd-sysusers.service rtc-init.service Before=time-sync.target shutdown.target Conflicts=shutdown.target ... [Install] WantedBy=multi-user.target Edit /etc/netctl/eth0 (file name may vary based on Ethernet interface name) commenting out ExecUpPost line: Description='A basic dhcp ethernet connection' Interface=eth0 Connection=ethernet IP=dhcp #ExecUpPost='/usr/bin/ntpd -gq || true' ## for DHCPv6 #IP6=dhcp ## for IPv6 autoconfiguration #IP6=stateless This disables automatic time sync with ntpd (at network startup during boot), since it’s already performed by systemd-timesyncd service. Eventually run $ timedatectl set-ntp true to enable the edited version of systemd-timesyncd service Reboot and enjoy, your Pi should now load the rtc time at startup (in a few seconds). Then, if you are connected to the internet the systemd-timesyncd service fetches current time with Simple NTP protocol and syncs it with system time and hardware time (your RTC). I measured the clock drift disabling systemd-timesyncd service for a couple of days. It turned out that the clock has an accuracy of 20 ppm, it lose a couple of seconds each day. It was more than acceptable for me, since my Raspberry is always online and can sync time periodically.]]></summary></entry><entry><title type="html">Hello HackingBytes!</title><link href="https://hackingbytes.com/2015/01/02/hello-world.html" rel="alternate" type="text/html" title="Hello HackingBytes!" /><published>2015-01-02T00:00:00+00:00</published><updated>2015-01-02T00:00:00+00:00</updated><id>https://hackingbytes.com/2015/01/02/hello-world</id><content type="html" xml:base="https://hackingbytes.com/2015/01/02/hello-world.html"><![CDATA[<p>Here it is, my blog is eventually ready and online!</p>

<p>After a long time spent setting things up, I finally have my own self-hosted website.</p>

<p>This blog will hopefully collect tutorials, how-tos and infos about projects I’m involved in but also considerations and random thoughts on general topics.</p>

<p>Being keen on many IT projects and interested in learning something more about the World Wide Web I decided to get my hands in the dirt and set up my own private server. I already needed an online place to publish my work and building up everything by myself turned out to be fun and really instructive.</p>

<p>Looking for an inexpensive solution I decided to invest 35€ in a <a href="http://www.raspberrypi.org/">Raspberry Pi</a>. Bought the Raspy, I downloaded the latest <a href="http://archlinuxarm.org/">Arch Linux ARM</a> image and installed the packages I needed. Done. I had a small, low power and silent machine ready for my purpose.</p>

<p>My Raspy currently features this <a href="https://hackingbytes.com/">website</a>, a <a href="https://hackingbytes.com/paste/">paste bin</a>, a <a href="https://hbb.pw">URL shortener</a>, a private <a href="http://owncloud.org/">Owncloud</a> instance and much more thanks to an <a href="http://nginx.org/en/">Nginx HTTP server</a>.</p>

<p>Running my own SMTP Server also allow me to receive directly E-Mail messages addressed <a href="mailto:webmaster@hackingbytes.com">@hackingbytes.com</a>.</p>

<p>Last but not least, on my home LAN I can share documents across computers and different systems via <a href="http://www.samba.org/">Samba</a> and play music with <a href="http://www.musicpd.org/">MPD</a>.</p>

<p>Perhaps I will explain in detail how to set up and run those services in future posts or how-tos.</p>

<p>At the moment I’m working on a small 12 Volts UPS which should keep running my home router and Raspy for at least a couple of hours - hopefully a little more - in case of AC power failure. I’ll publish some schematics as soon as I find time to build and properly test it.</p>

<p>Stay Tuned and <a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">add this website to favorites</a> if you like it!</p>]]></content><author><name>Stefano Balzan</name></author><summary type="html"><![CDATA[Here it is, my blog is eventually ready and online! After a long time spent setting things up, I finally have my own self-hosted website. This blog will hopefully collect tutorials, how-tos and infos about projects I’m involved in but also considerations and random thoughts on general topics. Being keen on many IT projects and interested in learning something more about the World Wide Web I decided to get my hands in the dirt and set up my own private server. I already needed an online place to publish my work and building up everything by myself turned out to be fun and really instructive. Looking for an inexpensive solution I decided to invest 35€ in a Raspberry Pi. Bought the Raspy, I downloaded the latest Arch Linux ARM image and installed the packages I needed. Done. I had a small, low power and silent machine ready for my purpose. My Raspy currently features this website, a paste bin, a URL shortener, a private Owncloud instance and much more thanks to an Nginx HTTP server. Running my own SMTP Server also allow me to receive directly E-Mail messages addressed @hackingbytes.com. Last but not least, on my home LAN I can share documents across computers and different systems via Samba and play music with MPD. Perhaps I will explain in detail how to set up and run those services in future posts or how-tos. At the moment I’m working on a small 12 Volts UPS which should keep running my home router and Raspy for at least a couple of hours - hopefully a little more - in case of AC power failure. I’ll publish some schematics as soon as I find time to build and properly test it. Stay Tuned and add this website to favorites if you like it!]]></summary></entry></feed>