Hardware https://tech.feedyourhead.at/ en How to build a music-box for children https://tech.feedyourhead.at/content/how-to-build-a-music-box-for-children <span class="field field--name-title field--type-string field--label-hidden">How to build a music-box for children</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><span>The <a href="https://tonies.com/en-gb/toniebox/">Tonibox</a> is a music player for children. They can simply place figures on the box and depending on the figure, a corresponding audio book is then played. I like this concept and since my child loves audio books, I am going to build such a box.</span></p> <p><em><span>Note: I never had an original Tonibox in my hands. So I don’t know about it’s exact features and also don’t know how it really works. This article simply describes how I would build such a device.</span></em></p> <h2>Overview</h2> <p>In this article I am going to build a "Tonibox-like" device with the following components:</p> <ul><li>wooden box (160x160mm)</li> <li>PN532 NFC-Reader</li> <li>3 Watt audio speakers</li> <li>PAM8403 amplifier</li> <li>Raspberry PI 4</li> <li>Spotify(premium account)</li> <li>Local Audio Files</li> <li>Pink LEDs + resistors</li> </ul><h2>Near-field communication</h2> <figure role="group" class="caption caption-img"><img alt="Picture of a pn532 nfc-reader module" data-entity-type="file" data-entity-uuid="ea38c063-f279-48bc-82c7-c5977a8e6509" height="456" src="/sites/default/files/inline-images/pn532-unboxed.png" width="608" /><figcaption>Figure 1: PN532 NFC-Reader and equipment</figcaption></figure><p><span>Let’s think how the original Tonibox might work. I believe that the figures might have built-in NFC-tags. As soon as they are placed on the reader, it reads the ID of the tag and plays the audio book. That’s why I bought the <a href="http://wiki.sunfounder.cc/index.php?title=PN532_NFC_RFID_Module">PN532</a>-reader(see Figure 1). It's very cheap and works perfect for my purposes. This chip can be controlled via SPI, UART or I2C. After some research, it seam that I2C needs just view cables, but might be not very stable. UART has a quite slow bitrate. I2C is faster but more unstable. So I decided to use SPI. According to https://www.schnatterente.net/technik/nfc-raspberry-pi-pn532-breakout-board/5 SPI works rather fast and stable with the PN532 chip. In order to use SPI, a jumper must be set. The following diagram shows how to connect the chip to the Raspberry PI and how to set the jumpers for SPI.</span></p> <figure role="group" class="caption caption-img"><img alt="Wiring schema of the PN532 with the Raspberry PI" data-entity-type="file" data-entity-uuid="9a9f0ef8-eaf8-431e-9876-da3daf6b72e8" height="389" src="/sites/default/files/inline-images/PN532-wiring.png" width="692" /><figcaption>Figure 2: Wiring the PN532 to the Raspberry PI(Image-Source for the Raspberry PI: Raspberry Pi Foundation)</figcaption></figure><p><span>After connecting the nfc-reader it's time for the software. The easiest way to access the reader is by using the libnfc(link). It can easily installed via apt:</span></p> <span class="geshifilter"><code class="bash geshifilter-bash"> apt <span style="color: #c20cb9; font-weight: bold;">install</span> libnfc-bin libnfc-dev libnfc-examples libnfc-pn53x-examples libnfc5:armhf </code></span> <p><span>I use the following configuration to use the PN532 chip via SPI:</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;">allow_autoscan = <span style="color: #c20cb9; font-weight: bold;">true</span>   allow_intrusive_scan = <span style="color: #c20cb9; font-weight: bold;">false</span>   log_level = <span style="color: #000000;">1</span>   device.name = <span style="color: #ff0000;">"_PN532_SPI"</span> device.connstring = <span style="color: #ff0000;">"pn532_spi:/dev/spidev0.0:500000"</span></pre></div> <p><span>Now let' try to access it. The libnfc comes with a tool "nfc-poll". We will use it to read the ID of the nfc-tag with the following command:</span></p> <p><span class="geshifilter"><code class="bash geshifilter-bash"> <span style="color: #c20cb9; font-weight: bold;">sudo</span> nfc-poll </code></span></p> <p><span>I modified the source code of nfc-poll and made a nfc-daemon(https://github.com/whotwagner/nfc-daemon) that executes events when a nfc-tag is detected and when it is removed. Installation is rather simple:</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> https:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>whotwagner<span style="color: #000000; font-weight: bold;">/</span>nfc-daemon <span style="color: #7a0874; font-weight: bold;">cd</span> nfc-daemon <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> docs<span style="color: #000000; font-weight: bold;">/</span>nfc-daemon.service <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>systemd<span style="color: #000000; font-weight: bold;">/</span>system<span style="color: #000000; font-weight: bold;">/</span>nfc-daemon.service <span style="color: #c20cb9; font-weight: bold;">sudo</span> systemctl <span style="color: #7a0874; font-weight: bold;">enable</span> nfc-daemon.service <span style="color: #c20cb9; font-weight: bold;">sudo</span> systemctl start nfc-daemon.service</pre></div> <p><span>We can test the nfc-daemon by editing "/usr/local/share/nfc-daemon/run_script":</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">"hello world: "</span> <span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000; font-weight: bold;">@</span></pre></div> <p><span>We also need a stop_script "/usr/local/share/nfc-daemon/end_script":</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Goodbye World"</span></pre></div> <h2><span>Music-Daemon: Mopidy</span></h2> <p><span>By using the nfc-daemon, we can now execute scripts. Finally it's time to play music. I decided to use the music-daemon mopidy to do the playback. <a href="https://mopidy.com/">Mopidy</a> plays music from local disk, Spotify, SoundCloud, TuneIn, and more. You can edit the playlist from any phone, tablet, or computer using a variety of MPD and web clients. The installation is straight forward. I followed the guide in the <a href="https://docs.mopidy.com/en/latest/installation/pypi/#installing-extensions">mopidy-documentation</a> and installed the mopidy-server via pip3. In addition I also installed the following modules:</span></p> <ul><li>Mopidy-Mopify</li> <li>Mopidy-MPD</li> <li>Mopidy-MPRIS</li> <li>Mopidy-Spotify</li> <li>Mopidy-Spotify-Web</li> </ul><p><span>For <a href="https://www.spotify.com/">Spotify</a> we also have to create credentials. We need a spotify premium account for that. I just followed the guide at https://mopidy.com/ext/spotify/. The client_id and client_secret must be used in the configuration. I experienced some strange problems, therefor I also added the spotify-username and spotify-password to the config. I actually don't know if it also works somehow without the spotify credentials. I also believe that Mopidy-Spotify-Web is not necessary to install.</span></p> <p><span><em>/etc/mopidy/mopidy.conf</em>:</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">[</span>audio<span style="color: #7a0874; font-weight: bold;">]</span> output = alsasink   <span style="color: #7a0874; font-weight: bold;">[</span>spotify<span style="color: #7a0874; font-weight: bold;">]</span> enabled = <span style="color: #c20cb9; font-weight: bold;">true</span> username = SPOTIFY_USER password = SPOTIFY_PASS client_id = CLIENT_ID client_secret = CLIENT_SECRET   <span style="color: #7a0874; font-weight: bold;">[</span>spotify_web<span style="color: #7a0874; font-weight: bold;">]</span> client_id = CLIENT_ID client_secret = CLIENT_SECRET     <span style="color: #7a0874; font-weight: bold;">[</span>mopify<span style="color: #7a0874; font-weight: bold;">]</span> enabled = <span style="color: #c20cb9; font-weight: bold;">true</span> debug = <span style="color: #c20cb9; font-weight: bold;">false</span>   <span style="color: #7a0874; font-weight: bold;">[</span>http<span style="color: #7a0874; font-weight: bold;">]</span> enabled = <span style="color: #c20cb9; font-weight: bold;">true</span> <span style="color: #c20cb9; font-weight: bold;">hostname</span> = 0.0.0.0 port = <span style="color: #000000;">6680</span> zeroconf = Mopidy HTTP server on <span style="color: #007800;">$hostname</span> allowed_origins = csrf_protection = <span style="color: #c20cb9; font-weight: bold;">true</span> default_app = mopidy</pre></div> <p> </p> <p><span>If you want to test the sound-server, you can do that by using mpc (command-line-client) or by using the ncurses based client "<a href="https://github.com/ncmpcpp/ncmpcpp">ncmpcpp</a>".</span></p> <h2>WIFI</h2> <p><span>I do not want any cables but the loading cable on the Tonibox. So I configured wifi. I configured the raspberry pi to connect to two networks. One is my home-wifi, and one is a non-existent network. The latter one I create with my mobile phone when we are not at home.</span></p> <p><em><span>/etc/wpa_supplicant/wpa_supplicant.conf:</span></em></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #007800;">ctrl_interface</span>=<span style="color: #007800;">DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>wpa_supplicant <span style="color: #007800;">GROUP</span>=netdev <span style="color: #007800;">update_config</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">country</span>=AT   <span style="color: #007800;">network</span>=<span style="color: #7a0874; font-weight: bold;">{</span> <span style="color: #007800;">ssid</span>=<span style="color: #ff0000;">"home-net"</span> <span style="color: #007800;">psk</span>=<span style="color: #ff0000;">"home-net-password"</span> <span style="color: #007800;">key_mgmt</span>=WPA-PSK <span style="color: #007800;">id_str</span>=<span style="color: #ff0000;">"home"</span> <span style="color: #007800;">priority</span>=<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">}</span>   <span style="color: #007800;">network</span>=<span style="color: #7a0874; font-weight: bold;">{</span> <span style="color: #007800;">ssid</span>=<span style="color: #ff0000;">"mobile-hotspot"</span> <span style="color: #007800;">psk</span>=<span style="color: #ff0000;">"mobile-hotspot-password"</span> <span style="color: #007800;">key_mgmt</span>=WPA-PSK <span style="color: #007800;">id_str</span>=<span style="color: #ff0000;">"mobile"</span> <span style="color: #007800;">priority</span>=<span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">}</span></pre></div> <h2><span>Bootsound</span></h2> <p><span>In order to play a sound if the box is booted, I also want to have a nice sound that indicates that it is up and running. I downloaded a nice wav-file from <a href="http://soundbible.com/1795-Electrical-Sweep.html">soundbible.com</a> and configured a boot-script "/usr/local/bin/bootsound.sh":</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sleep</span> 15s <span style="color: #666666; font-style: italic;"># dirty hack to be sure that it is booted</span> mpc <span style="color: #c20cb9; font-weight: bold;">clear</span> mpc add file:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>pi<span style="color: #000000; font-weight: bold;">/</span>SoundEffects<span style="color: #000000; font-weight: bold;">/</span>boot.wav mpc play</pre></div> <p><span>A systemd-service will execute this script. So let's create the systemd-service "/etc/systemd/system/bootsound.service":</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">[</span>Unit<span style="color: #7a0874; font-weight: bold;">]</span> <span style="color: #007800;">Description</span>=Boot Sound <span style="color: #007800;">After</span>=avahi-daemon.service <span style="color: #007800;">After</span>=dbus.service <span style="color: #007800;">After</span>=network.target <span style="color: #007800;">After</span>=nss-lookup.target <span style="color: #007800;">After</span>=pulseaudio.service <span style="color: #007800;">After</span>=remote-fs.target <span style="color: #007800;">After</span>=sound.target <span style="color: #007800;">After</span>=mopidy.service <span style="color: #007800;">After</span>=mopidy.service   <span style="color: #7a0874; font-weight: bold;">[</span>Service<span style="color: #7a0874; font-weight: bold;">]</span> <span style="color: #007800;">Type</span>=oneshot <span style="color: #007800;">RemainAfterExit</span>=no <span style="color: #007800;">ExecStart</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>bootsound.sh   <span style="color: #7a0874; font-weight: bold;">[</span>Install<span style="color: #7a0874; font-weight: bold;">]</span> <span style="color: #007800;">WantedBy</span>=default.target</pre></div> <p><span>Now we just have to set the permissions and enable the systemd-service:</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chown</span> root.root <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>bootsound.sh <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>bootsound.sh systemctl <span style="color: #7a0874; font-weight: bold;">enable</span> bootsound.service</pre></div> <h2><span>Audio Hardware</span></h2> <figure role="group" class="caption caption-img"><img alt="Image of the PAM8403 Module" data-entity-type="file" data-entity-uuid="b3aa8596-b5cf-48a5-be45-3e2862696ed7" height="210" src="/sites/default/files/inline-images/pam8403.png" width="210" /><figcaption>Figure 3: PAM8403 Module (Image-Source: https://bdspeedytech.com/image/cache/catalog/PAM8403-750x750.png)</figcaption></figure><p>I want to keep things simple. In order to avoid a special power adapter, I simply use an amplifier that works with low power and connect it to the 5V Raspberry PI power-pins. I found the <a href="https://www.makershop.de/module/audio/pam8403-2/">PAM8403</a> amplifier module. It works with 5Volt and allows to connect two 3 Watt audio speakers. By soldering a cable to the amplifier, it is possible to connect it to the sound output of the Raspberry PI</p> <p>Finally I also need 3 Watt speakers and I will use the <a href="https://www.reichelt.at/at/de/index.html?ACTION=446&amp;LA=446&amp;nbc=1&amp;q=vis%202242">Visaton 2242</a><span>. They are not very special, work with 2 Watt and 8 Ohm and might be enough for a “toy”.</span></p> <figure role="group" class="caption caption-img"><img alt="Image of a Visaton 2242 audio speaker" data-entity-type="file" data-entity-uuid="e5c4528e-d26f-460d-bee1-8eac279d5592" height="163" src="/sites/default/files/inline-images/visaton2242.png" width="163" /><figcaption>Figure 4: Visaton 2242 ( Image-Source: reichelt.at)</figcaption></figure><figure role="group" class="caption caption-img"><img alt="Image of the wiring: raspberry pi connected to the amplifier that has the two speakers connected" data-entity-type="file" data-entity-uuid="fa62bd39-32ee-4c5a-8f1d-e2b42f9bd15e" height="380" src="/sites/default/files/inline-images/audio-cabeling.png" width="507" /><figcaption>Figure 5: Wiring the amplifier</figcaption></figure><p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/musicbox-wiring-video.mp4" type="video/mp4"></source></video></p> <h2 class="western"><span style="page-break-before:always">Joni – Connecting NFC and Mopidy</span></h2> <p><span style="line-height:100%">The final component is the script that identifies the UID of the nfc-card and looks it up in a database in order to play it using the Mopidy server. I want to make this script as simple as possible. That's why I didn't use any database at all and use a simple yaml-file instead. Since I don't expect too many entries, it might be okay. The outcome is a script called "<a href="https://github.com/whotwagner/joni.git">joni</a>".</span></p> <p><span style="line-height:100%">Installation:</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> https:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>whotwagner<span style="color: #000000; font-weight: bold;">/</span>joni.git <span style="color: #7a0874; font-weight: bold;">cd</span> joni <span style="color: #c20cb9; font-weight: bold;">sudo</span> pip3 <span style="color: #c20cb9; font-weight: bold;">install</span> . <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> bin<span style="color: #000000; font-weight: bold;">/</span>jon.py <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jon.py <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jon.py <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>joni <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>joni.log <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> pi.pi <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>joni.log</pre></div> <p><span style="line-height:100%">Now create the config-file <em>/etc/joni/config.yml</em>:</span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;">volume: <span style="color: #000000;">45</span> timeout: <span style="color: #000000;">10</span>   tracks: - id: 029i2939392a description: <span style="color: #ff0000;">"Petronella Apfelmus - Zaubertricks und Maulwurfshuegel"</span> play: - spotify:album:3HJSMsKWgmP5OCss1UD2p5   - id: 0298383219f volume: <span style="color: #000000;">20</span> <span style="color: #666666; font-style: italic;"># you can set a volume per playlist</span> description: <span style="color: #ff0000;">"Das Beste ueberhaupt"</span> play: - file:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>pi<span style="color: #000000; font-weight: bold;">/</span>Kindercds<span style="color: #000000; font-weight: bold;">/</span>Geschichten<span style="color: #000000; font-weight: bold;">/</span>Track01.wav - file:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>pi<span style="color: #000000; font-weight: bold;">/</span>Kindercds<span style="color: #000000; font-weight: bold;">/</span>Geschichten<span style="color: #000000; font-weight: bold;">/</span>Track02.wav - file:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>pi<span style="color: #000000; font-weight: bold;">/</span>Kindercds<span style="color: #000000; font-weight: bold;">/</span>Geschichten<span style="color: #000000; font-weight: bold;">/</span>Track03.wav - file:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>pi<span style="color: #000000; font-weight: bold;">/</span>Kindercds<span style="color: #000000; font-weight: bold;">/</span>Geschichten<span style="color: #000000; font-weight: bold;">/</span>Track04.wav - file:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>pi<span style="color: #000000; font-weight: bold;">/</span>Kindercds<span style="color: #000000; font-weight: bold;">/</span>Geschichten<span style="color: #000000; font-weight: bold;">/</span>Track05.wav</pre></div> <p><span style="line-height:100%">In order to run joni we have to edit the run- and end-script.</span></p> <p><em><span style="line-height:100%">/usr/local/share/nfc-daemon/run_script:</span></em></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span> <span style="color: #666666; font-style: italic;"># concats the id:</span> <span style="color: #007800;">VAR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000; font-weight: bold;">@</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ gsub (" ", "", $0); print}'</span><span style="color: #000000; font-weight: bold;">`</span>   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jon.py <span style="color: #660033;">-d</span> <span style="color: #660033;">-L</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>joni.log <span style="color: #660033;">--start</span> <span style="color: #007800;">$VAR</span></pre></div> <p><em><span style="line-height:100%">/usr/local/share/nfc-daemon/end_script:</span></em></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jon.py <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>joni<span style="color: #000000; font-weight: bold;">/</span>config.yml <span style="color: #660033;">--stop</span></pre></div> <h2 class="western"><span style="page-break-before:always">The Wooden Box</span></h2> <p>It’s rather difficult to make a toy for a child. It has to be “unbreakable”, but must not be too heavy. Choose the wood wisely and make the “walls” rather thick! I made the mistake that I used beech wood. It’s much to heavy and very hard. On the other hand, it’s a very beautiful wood.</p> <p>Since I am not very good at working with wood, my uncle helped me out and made the box(160x160x160mm) with walls that are about 30mm thick.</p> <figure role="group" class="caption caption-img"><img alt="Empty wooden box" data-entity-type="file" data-entity-uuid="2310955c-70ea-46f6-8f54-d16e9815ca88" src="/sites/default/files/inline-images/wooden-box1.png" /><figcaption>Figure 6: empty wooden box. open</figcaption></figure><figure role="group" class="caption caption-img"><img alt="empty wooden box without any electronics" data-entity-type="file" data-entity-uuid="67f6b2a9-f1c1-4461-a4cf-1fbd33ee3ac7" src="/sites/default/files/inline-images/wooden-box2.png" /><figcaption>Figure 6: empty wooden box. closed</figcaption></figure><figure role="group" class="caption caption-img"><img alt="Wooden box with built-in raspberry pi" data-entity-type="file" data-entity-uuid="005626ae-6fc6-4e6b-98f7-094d1963583a" height="482" src="/sites/default/files/inline-images/wooden-box4.png" width="642" /><figcaption>Figure 7: Builtin Raspberry PI</figcaption></figure><figure role="group" class="caption caption-img"><img alt="Music-Box with speakers and transparent plastic on top" data-entity-type="file" data-entity-uuid="b42e57cb-6195-4f5d-8436-1719277addff" height="587" src="/sites/default/files/inline-images/wooden-box5.png" width="440" /><figcaption>Figure 8: Almost finished. The music-box with speakers and a transparent plattform for the NFC-tags on top</figcaption></figure><h2 class="western"><span style="page-break-before:always">Pink LED Indicator</span></h2> <p><span style="line-height:100%">My box is a massive box made of wood. I want to place the nfc-reader on the top of it and want to have a small distance between card and reader. That's why I bought a simple pocket-mirror and used just one half of it. Since it is made of transparent plastic, it would be beautiful to place LED's there. They light up when a card is placed. I use 4 LED's. That's too much current for one GPIO-pin. As far as I know the Raspberry PI 4 GPIO-pins support up to 16mA. So I connect the LED’s with 4 GPIO-pins. One <a href="https://www.conrad.at/de/p/thomsen-184541-led-bedrahtet-pink-rund-5-mm-1120-mcd-60-20-ma-3-4-v-184541.html">LED</a> with a resistor per pin. I picked a 330Ohm resistory so that I have 10mA per GPIO-pin. In order to initialize the GPIO-pins, I placed the code in <em>/usr/local/bin/bootsound.sh:</em></span></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>   <span style="color: #c20cb9; font-weight: bold;">sleep</span> 10s <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"26"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"out"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio26<span style="color: #000000; font-weight: bold;">/</span>direction <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio26<span style="color: #000000; font-weight: bold;">/</span>value   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"19"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"out"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio19<span style="color: #000000; font-weight: bold;">/</span>direction <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio19<span style="color: #000000; font-weight: bold;">/</span>value   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"13"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"out"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio13<span style="color: #000000; font-weight: bold;">/</span>direction <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio13<span style="color: #000000; font-weight: bold;">/</span>value   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"6"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"out"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio6<span style="color: #000000; font-weight: bold;">/</span>direction <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio6<span style="color: #000000; font-weight: bold;">/</span>value   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"5"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"out"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio5<span style="color: #000000; font-weight: bold;">/</span>direction <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio5<span style="color: #000000; font-weight: bold;">/</span>value   mpc <span style="color: #c20cb9; font-weight: bold;">clear</span> mpc add file:<span style="color: #000000; font-weight: bold;">///</span>home<span style="color: #000000; font-weight: bold;">/</span>pi<span style="color: #000000; font-weight: bold;">/</span>SoundEffects<span style="color: #000000; font-weight: bold;">/</span>boot.wav mpc play</pre></div> <p><em><span style="line-height:100%">/usr/local/share/nfc-daemon/run_script:</span></em></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span> <span style="color: #007800;">VAR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000; font-weight: bold;">@</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ gsub (" ", "", $0); print}'</span><span style="color: #000000; font-weight: bold;">`</span>   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio26<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio19<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio13<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio6<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"1"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio5<span style="color: #000000; font-weight: bold;">/</span>value   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jon.py <span style="color: #660033;">-d</span> <span style="color: #660033;">-L</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>joni.log <span style="color: #660033;">--start</span> <span style="color: #007800;">$VAR</span></pre></div> <p><em><span style="line-height:100%">/usr/local/share/nfc-daemon/end_script:</span></em></p> <p></p><div class="geshifilter"><pre class="bash geshifilter-bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jon.py <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>joni<span style="color: #000000; font-weight: bold;">/</span>config.yml <span style="color: #660033;">--stop</span>   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio26<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio19<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio13<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio6<span style="color: #000000; font-weight: bold;">/</span>value <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"0"</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>class<span style="color: #000000; font-weight: bold;">/</span>gpio<span style="color: #000000; font-weight: bold;">/</span>gpio5<span style="color: #000000; font-weight: bold;">/</span>value</pre></div> <figure role="group" class="caption caption-img"><img alt="Image shows the nfc-reader module that is placed on top of the wooden box" data-entity-type="file" data-entity-uuid="786ad7de-89f4-4aba-ae92-d04157f59f70" height="649" src="/sites/default/files/inline-images/placing-nfcreader.png" width="487" /><figcaption>Figure 9: Placing the NFC-module on top of the wooden box</figcaption></figure><p> <video controls="" height="700" width="500"><source src="/sites/default/files/DateiUploads/music-box-final.mp4" type="video/mp4"></source></video></p> <h2 class="western">Special Thanks</h2> <p>This box wouldn’t be as perfect as it is now if there weren’t some friends who helped me. I want to thank “Jumpy” and his friends who made most of the wooden box. I also want to thank “Brother Patrick” with his super-cool soldering station, who showed me how to solder properly and who helped me making the electronics just perfect. And last but not least to my neighbor who printed all the labels for the NFC-cards.</p> <h2 class="western">Final words</h2> <p>It was very easy to create a Spotify-powered homemade Tonibox and it was a lot of fun for me. My child was more than delighted and listens to the audio books every day.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jan 02 2021</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hackaday" hreflang="en">HackADay</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/raspberry" hreflang="en">Raspberry</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/music" hreflang="en">Music</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/c" hreflang="en">C</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <div class="node__links"> <ul class="links inline"><li class="comment-add"><a href="/content/how-to-build-a-music-box-for-children#comment-form" title="Share your thoughts and opinions." hreflang="en">Add new comment</a></li></ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title">Comments</h2> <article data-comment-user-id="0" id="comment-291" about="/comment/291" typeof="schema:Comment" class="comment js-comment by-anonymous"> <mark class="hidden" data-comment-timestamp="1609605299"></mark> <footer class="comment__meta"> <article typeof="schema:Person" about="/user/0" class="profile"> </article> <p class="comment__submitted"><span rel="schema:author">Submitted by <span lang="" typeof="schema:Person" property="schema:name" datatype="">Andrei (not verified)</span> on Jan 02 2021</span> <span property="schema:dateCreated" content="2021-01-02T14:33:16+00:00" class="rdf-meta hidden"></span> </p> <a href="/comment/291#comment-291" hreflang="en">Permalink</a> </footer> <div class="content"> <h3 property="schema:name" datatype=""><a href="/comment/291#comment-291" class="permalink" rel="bookmark" hreflang="en">Audio Out</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Super nice project!<br /> Thank you for sharing!</p> <p>Is there a way to have an additional audio out, via Bluetooth or 3.5 mm audio jack, so it could also go through home amplifier or audio system if wanted? Spotify has quite good sound quality if opted for.</p> <p>All the best!</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=291&amp;1=default&amp;2=en&amp;3=" token="y3LrikPfV1pM77ouqb35eB-KM1KkYrBd2w4qR3WlQY8"></drupal-render-placeholder> </div> </article> <div class="indented"> <article data-comment-user-id="1" id="comment-292" about="/comment/292" typeof="schema:Comment" class="comment js-comment by-node-author"> <mark class="hidden" data-comment-timestamp="1609605530"></mark> <footer class="comment__meta"> <article typeof="schema:Person" about="/users/hoti" class="profile"> </article> <p class="comment__submitted"><span rel="schema:author">Submitted by <span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span> on Jan 02 2021</span> <span property="schema:dateCreated" content="2021-01-02T16:38:50+00:00" class="rdf-meta hidden"></span> </p> <p class="parent visually-hidden">In reply to <a href="/comment/291#comment-291" class="permalink" rel="bookmark" hreflang="en">Audio Out</a> by <span lang="" typeof="schema:Person" property="schema:name" datatype="">Andrei (not verified)</span></p> <a href="/comment/292#comment-292" hreflang="en">Permalink</a> </footer> <div class="content"> <h3 property="schema:name" datatype=""><a href="/comment/292#comment-292" class="permalink" rel="bookmark" hreflang="en">Yes, the Raspberry PI has…</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item">Yes, the Raspberry PI has Bluetooth built in. It is possible to use it for Audio output. Another nice built.-in feature is, that this box can be controlled with an App. The music-server Mopidy can be controlled via network ( https://mopidy.com/ext/mobile/ )</div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=292&amp;1=default&amp;2=en&amp;3=" token="PkLnTsrFCod0RAYCW8jC09xjVo5vibC8JhaFlipzoz8"></drupal-render-placeholder> </div> </article> </div> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=294&amp;2=comment&amp;3=comment" token="_8dmtEYvMrzg7f9GTUFmT0L61xh-uUTbizTQ2JIK1zA"></drupal-render-placeholder> </section> Sat, 02 Jan 2021 09:57:54 +0000 Hoti 294 at https://tech.feedyourhead.at HackADay: Let's make a Nukestation https://tech.feedyourhead.at/content/hackaday-lets-make-a-nukestation <span class="field field--name-title field--type-string field--label-hidden">HackADay: Let&#039;s make a Nukestation</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Every time I replace an old hard disk by a newer or bigger one I think that I'll wipe it later. Now I have a big amount of hard disks to wipe. Since wiping takes ages, I don't want to use my personal computer for that. I would prefer a small device with low energy consumption just for wiping. That's why I am going to build a "Nukestation". Basically it's just a Raspberry Pi with nwipe on it and a udev-rule for automatically wipe attached hard disks. But some extras would be nice...</p> <h3>Hardware</h3> <p>My setup is quite basic: a Raspberry Pi 3b+, a Disk-Docking-Station(USB), and a LED for signalling that the drive can safely removed/attached. I know, It would be much better to use a red LED for signalling when the Nukestation is wiping disks, but I had just green LED's at home. That's why I am gonna do that the way around.</p> <p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/nukestation.mp4" type="video/mp4" /></video> </p> <p>This video shows my setup. As soon as I plugg in the harddisk, the green led turns dark for signalling that it is not safe to remove the disk now, and on the screen we can see that nwipe starts it's job.</p> <h3>Little Extras</h3> <p>I wrote a bash-script called "nukestation.sh". This script is a wrapper for nwipe and allows us to:</p> <ul> <li>Create Pre-run-hooks(like turn off the LED)</li> <li>Run nwipe with configurable settings</li> <li>Create Post-run-hoocks(like turn on the LED)</li> <li>Send a notification including the nwipe-log via email</li> </ul> <h3>Installation</h3> <p>I won't use this Raspberry Pi only for wiping disks. That's why I need a very easy to use installation routine for the nukestation. I used the configuration management sytem <a href="https://www.ansible.com/">ansible</a> for that. The sources of my nukestation ansible-role can be downloaded on <a href="https://github.com/whotwagner/ansible-role-nukestation">Github</a>&nbsp; and the role is available on ansible-galaxy too. On a freshly installed <a href="https://www.raspberrypi.org/downloads/raspbian/">Raspbian</a>&nbsp; the Nukestation can be installed using the follwing commands:</p> <pre> <code> $ sudo apt-get install ansible $ sudo ansible-galaxy install whotwagner.nukestation $ cat > playbook.yml << EOF --- - hosts: localhost roles: - whotwagner.nukestation EOF $ sudo ansible-playbook playbook.yml </code></pre> <p>The playbook above will just install Nukestation without mailsupport. If we want to install a mailsystem with a smarthost using authentication to automatically send notifications we can use another playbook:</p> <pre> <code> $ sudo apt-get install ansible $ sudo ansible-galaxy install whotwagner.nukestation $ cat > playbook.yml << EOF - hosts: localhost roles: - whotwagner.nukestation vars: nukestation_mailconf: server: mail.example.conf:587 user: username@example.conf pass: super-secret-password from: from@example.com to: to@example.com EOF $ sudo ansible-playbook playbook.yml </code></pre> <p>A detailed documentation about the playbook and the nukestation.sh-script can be found at <a href="https://github.com/whotwagner/ansible-role-nukestation">Github</a>.</p> <h3>Conclusio</h3> <p>Nukestation allows me to wipe disks easily and I'll recieve notifications as soon as the wipejob is finished. <em>"I love it when a plan comes together"</em></p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Apr 15 2018</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hackaday" hreflang="en">HackADay</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/raspberry" hreflang="en">Raspberry</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tricks" hreflang="en">Tricks</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ansible" hreflang="en">Ansible</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=262&amp;2=comment&amp;3=comment" token="mXNkYhJywlpehAmSRx0Jlb3KcW68vS026m820TmEpE8"></drupal-render-placeholder> </section> Sun, 15 Apr 2018 16:45:24 +0000 Hoti 262 at https://tech.feedyourhead.at HackADay: Controlling computers and stuff with the mind https://tech.feedyourhead.at/content/hack-a-day-controlling-computers-and-stuff-with-my-mind <span class="field field--name-title field--type-string field--label-hidden">HackADay: Controlling computers and stuff with the mind</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I am very slothful.  I let computers do my work. That's why I became a sysadmin. In this article I am going to describe how I lifted up my lazyness to the next level by triggering a command with my mind to install a new virtual machine with: MariaDB, Nginx and Wordpress.</p> <h2>Intro</h2> <p>When I first read about the <a href="http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0111332">human-to-human-brain-interface</a> I was fascinated. It's like a science-fiction-x-men-story: controlling another human with the mind. But this is a little bit creepy too. Controlling a computer with the mind instead sounds for me more comfortable. In that way I could do all my work just by thinking of it while I am lying in my bed. That's awesome.</p> <h2>Hardware</h2> <p><img alt="Mindwave Equipment" data-entity-type="file" data-entity-uuid="516f6e07-edbb-4697-9daf-652540c07fd7" src="/sites/default/files/inline-images/mindwave_equippment.jpg" /></p> <h3>Headset</h3> <p>I did a little research and it seems the best option for an affordable EEG-headset would be the <a href="http://openbci.com/">OpenBCI-Project</a>. For my proof of concept it is still too expensive, that's why I took the <a href="http://store.neurosky.com/">Neurosky Mindwave Headset</a>. It's has just a few electrodes but it is cheap and might be good enough for my experiment. I ordered a Mindwave-Headset and not a Mindwave-Mobile-headset. The Mindwave-headset ships with a USB-dongle.</p> <p>Neurosky-Devices have a nice feature built-in: <a href="http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#thinkgear_data_values">eSense</a>. eSense  calculates the "attention"(are you focused?) and "meditation"(do you have many thoughts?) of a person. I will use this feature for triggering a command-execution.  I could also use the EEG-Data(16bin wave-format), but for this proof-of-concept I am fine with the eSense-meters.</p> <h3>Microcontroller</h3> <p>I have an old Raspberry Pi (Model B) and I installed <a href="https://www.debian.org/releases/jessie/">Debian Jessie</a> on it. A LED on a Gpio-Pin will indicate if I am concentrated or not.</p> <h2>Software</h2> <h3>Reading out EEG-Data</h3> <p>I wrote a <a href="https://github.com/whotwagner/mindwave">ruby gem</a> for interfacing the Mindwave Headset. It simply reads out all the data via serial line and parses it. There are several callback methods to overwrite.  In the following example I will override a method to read out the "attention"-value:</p> <pre> <div class="geshifilter"><pre class="ruby geshifilter-ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>   <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mindwave'</span>   <span style="color:#9966CC; font-weight:bold;">class</span> EEG <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Mindwave::Headset</span> <span style="color:#008000; font-style:italic;"># override Attention-Callback-Method</span> <span style="color:#9966CC; font-weight:bold;">def</span> attentionCall<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> str = eSenseStr<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"this is an attention #{attention} #{str}<span style="color:#000099;">\n</span>"</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># create a new instance</span> mw = EEG.<span style="color:#9900CC;">new</span> <span style="color:#008000; font-style:italic;"># mw.log.level = Logger::DEBUG</span>   <span style="color:#008000; font-style:italic;"># if we hit ctrl+c then just stop the run()-method</span> <span style="color:#CC00FF; font-weight:bold;">Signal</span>.<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#996600;">"INT"</span><span style="color:#006600; font-weight:bold;">)</span> <span style="color:#9966CC; font-weight:bold;">do</span> mw.<span style="color:#9900CC;">stop</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># Create a new Thread</span> thread = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">{</span> mw.<span style="color:#9900CC;">run</span> <span style="color:#006600; font-weight:bold;">}</span> <span style="color:#008000; font-style:italic;"># ..and run it</span> thread.<span style="color:#9900CC;">join</span>   mw.<span style="color:#9900CC;">close</span></pre></div></pre> <h3>Manipulating the Raspberry-GPIO-Pins</h3> <p>I found a nice ruby gem for manipulating the GPIO-Pins of my raspberry at <a href="https://rubygems.org/gems/rpi_gpio">rubygems.org.</a> This code will switch the GPIO_Pin 22 on every key-stroke:</p> <pre> <div class="geshifilter"><pre class="ruby geshifilter-ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>   <span style="color:#008000; font-style:italic;"># gem install rpi_gpio</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rpi_gpio'</span> <span style="color:#008000; font-style:italic;"># gem install io-console</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'io/console'</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_numbering</span> <span style="color:#ff3333; font-weight:bold;">:bcm</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> <span style="color:#006666;">22</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">setup</span> <span style="color:#006666;">22</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:output</span>   GPIO_NUM=<span style="color:#006666;">22</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_high</span> GPIO_NUM   sohigh = <span style="color:#0000FF; font-weight:bold;">true</span>   input = <span style="color:#996600;">'c'</span>   <span style="color:#CC00FF; font-weight:bold;">Signal</span>.<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#996600;">"INT"</span><span style="color:#006600; font-weight:bold;">)</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"SiGINT Cleaning up.."</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> GPIO_NUM <span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">end</span>     <span style="color:#9966CC; font-weight:bold;">while</span> input != <span style="color:#996600;">"q"</span> input = STDIN.<span style="color:#9900CC;">getch</span>   <span style="color:#9966CC; font-weight:bold;">if</span> sohigh <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_low</span> GPIO_NUM <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_high</span> GPIO_NUM <span style="color:#9966CC; font-weight:bold;">end</span>   sohigh = !sohigh <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Cleaning up.."</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> GPIO_NUM</pre></div></pre> <h2>Controlling a LED</h2> <p>So let's put all parts together. Here is some code which toggles a LED if the attention value is bigger than 79:</p> <pre> <div class="geshifilter"><pre class="ruby geshifilter-ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>   <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mindwave'</span>   <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rpi_gpio'</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_numbering</span> <span style="color:#ff3333; font-weight:bold;">:bcm</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> <span style="color:#006666;">22</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">setup</span> <span style="color:#006666;">22</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:output</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_low</span> <span style="color:#006666;">22</span>   <span style="color:#9966CC; font-weight:bold;">class</span> EEG <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Mindwave::Headset</span> <span style="color:#0066ff; font-weight:bold;">@ishigh</span> = <span style="color:#0000FF; font-weight:bold;">false</span> attr_accessor <span style="color:#ff3333; font-weight:bold;">:update</span>     <span style="color:#9966CC; font-weight:bold;">def</span> meditationCall<span style="color:#006600; font-weight:bold;">(</span>meditation<span style="color:#006600; font-weight:bold;">)</span> str = eSenseStr<span style="color:#006600; font-weight:bold;">(</span>meditation<span style="color:#006600; font-weight:bold;">)</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Meditation #{meditation} #{str}<span style="color:#000099;">\n</span>"</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># override Attention-Callback-Method</span> <span style="color:#9966CC; font-weight:bold;">def</span> attentionCall<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> str = eSenseStr<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"-&amp;gt; Attention #{attention} #{str}<span style="color:#000099;">\n</span>"</span>   <span style="color:#9966CC; font-weight:bold;">if</span> attention <span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">79</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#0066ff; font-weight:bold;">@update</span> == <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"FIRE IT UP"</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@ishigh</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_low</span> <span style="color:#006666;">22</span> <span style="color:#0066ff; font-weight:bold;">@ishigh</span> = <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_high</span> <span style="color:#006666;">22</span>   <span style="color:#0066ff; font-weight:bold;">@ishigh</span> = <span style="color:#0000FF; font-weight:bold;">true</span> stop <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#0066ff; font-weight:bold;">@update</span> = <span style="color:#0000FF; font-weight:bold;">false</span>   <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># create a new instance</span> mw = EEG.<span style="color:#9900CC;">new</span> mw.<span style="color:#9900CC;">update</span> = <span style="color:#0000FF; font-weight:bold;">true</span>   <span style="color:#008000; font-style:italic;"># mw.log.level = Logger::INFO</span>   <span style="color:#008000; font-style:italic;"># if we hit ctrl+c then just stop the run()-method</span> <span style="color:#CC00FF; font-weight:bold;">Signal</span>.<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#996600;">"INT"</span><span style="color:#006600; font-weight:bold;">)</span> <span style="color:#9966CC; font-weight:bold;">do</span> mw.<span style="color:#9900CC;">stop</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># Create a new Thread</span> thread = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">{</span> mw.<span style="color:#9900CC;">run</span> <span style="color:#006600; font-weight:bold;">}</span> <span style="color:#008000; font-style:italic;"># ..and run it</span>   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Starting..."</span> thread.<span style="color:#9900CC;">join</span>   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Cleaning up.."</span> mw.<span style="color:#9900CC;">close</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> <span style="color:#006666;">22</span></pre></div></pre> <p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/mindwave_led_lightup.mp4" type="video/mp4"></source></video></p> <h2>Automization</h2> <p>Automization is a very important part of our work at <a href="http://www.toscom.at/">Toscom</a>. I believe that sysadmins should automize as much as possible. Not only to be more efficient but also for quality management. So we do not configure servers manually but program the configuration and reuse this code as often as possible. This makes the next step very easy. I just install the configurations-management-system <a href="https://www.ansible.com/">Ansible</a> on the raspberry pi, download some (wordpress related) ansible-roles from <a href="https://galaxy.ansible.com/">ansible-galaxy </a>and call ansible-playbook within my script. Since Version 2 Ansible also includes modules for controlling <a href="https://aws.amazon.com/">Amazon AWS-Services</a>. So I will create my virtual machine in the Amazon-Cloud. Here is my playbook.yml:</p> <pre> <code> - hosts: localhost connection: local gather_facts: False tasks: - name: Provision Wordpress Instance ec2: aws_access_key: "MY-ACCESS-KEY" aws_secret_key: "MY-SUPER-SECRET-ACCESS-KEY" key_name: pi_key instance_type: t2.micro image: ami-ed82e39e wait: true wait_timeout: 500 assign_public_ip: yes vpc_subnet_id: subnet-de3b5da8 region: eu-west-1 group_id: sg-75d3c412 register: ec2 - name: Add new instance to host group add_host: hostname={{ item.public_ip }} groupname=launched ansible_user=ubuntu with_items: '{{ec2.instances}}' - name: Wait for SSH to come up wait_for: host={{item.public_dns_name}} port=22 delay=60 timeout=320 state=started with_items: '{{ec2.instances}}' - name: install wordpress hosts: launched become: True gather_facts: True vars: wp_mysql_host: 'localhost' session_post_max_size: '128M' session_upload_max_filesize: '128M' session_max_input_time: '70' session_max_execution_time: '90' roles: - valentinzberea.wordpress </code></pre> <p>I use the following roles (from <a href="https://galaxy.ansible.com/">ansible-galaxy</a>):</p> <ul><li>mats116.nginx        </li> <li>valentinzberea.wordpress</li> <li>mats116.mariadb-server    </li> <li>valentinzberea.hhvm</li> </ul><h2>Proof of Concept</h2> <p>In the next video clip, I recorded a proof of concept. First I got a connection with my headset (the light turns blue), then it took me a while to be focused. As soon as I have a focus level of 80, my program will turn on a LED and call ansible-playbook. In the clip we will see that in my Amazon AWS-Console a new virtual machine will start and install Wordpress, MariaDB and Nginx. At the end of the clip, I will copy the IP-address of the new host and connect to the Wordpress-Page on it.</p> <p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/mindcontrol_aws_wordpress.mp4" type="video/mp4"></source></video></p> <p>I did not use the Wave-Stream of the EEG-Data to detect the thoughts but only read out the attention-level of my mind. I also exited the script as soon as it fired up a command, otherwise I would have multiple command-executions on "long" thoughts aso.</p> <h2>Problems</h2> <ol><li>I cheated. I did not use the wave-data at all. I just used the attention-level I got from the Mindwave-Headset.</li> <li>This is difficult to use. How does one deliberately hold a focus with his mind? Some practice is needed...</li> <li>What if someone focuses longer? A timer is needed then, otherwise it toggles many times in a row</li> </ol><h2>Conclusion</h2> <p>I triggered a command with my mind which created a virtual machine (Amazon EC2-Instance), installed MariaDB, Nginx and Wordpress. That is one of my daily tasks and I was able to make it just by concentrating. If I combine this project with my <a href="https://tech.feedyourhead.at/content/controlling-power-outlets-using-the-rapberry-pi">power-outlets</a>, I could even make tea with my mind. It's not perfect. This technique is not very precise (neither is this headset). Even though I am very happy with the result. Maybe I will go deeper and compare signatures of EEG data to detect different states of mind.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sep 16 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hackaday" hreflang="en">HackADay</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/raspberry" hreflang="en">Raspberry</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/97" hreflang="en">Toscom</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=200&amp;2=comment&amp;3=comment" token="2BmXclPgiIaQ8G9zkGASPYUrQx8quVImoHS9NOI2gYA"></drupal-render-placeholder> </section> Fri, 16 Sep 2016 07:06:56 +0000 Hoti 200 at https://tech.feedyourhead.at Tiva cc3200: Get serial port working under Linux https://tech.feedyourhead.at/content/tiva-3200-get-serial-port-working-under-linux <span class="field field--name-title field--type-string field--label-hidden">Tiva cc3200: Get serial port working under Linux</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><a href="http://www.ti.com/ww/en/launchpad/launchpads-connected-cc3200-launchxl.html">Tiva cc3200</a> is a small board with an integrated wifi-chip. The Linux-kernel needs a few configs to be able to talk to this board using a serial console( via usb):</p> <pre><code> modprobe ftdi_sio echo 0451 c32a > /sys/bus/usb-serial/drivers/ftdi_sio/new_id </code></pre> Output of dmesg: <pre><code> dmesg [ 7717.631763] usb 1-1: new full-speed USB device number 6 using xhci_hcd [ 7717.765206] usb 1-1: New USB device found, idVendor=0451, idProduct=c32a [ 7717.765209] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 7717.765211] usb 1-1: Product: USB <-> JTAG/SWD [ 7717.765212] usb 1-1: Manufacturer: FTDI [ 7717.765213] usb 1-1: SerialNumber: cc3101 [ 7717.767653] ftdi_sio 1-1:1.0: FTDI USB Serial Device converter detected [ 7717.767688] usb 1-1: Detected FT2232C [ 7717.767899] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0 [ 7717.769914] ftdi_sio 1-1:1.1: FTDI USB Serial Device converter detected [ 7717.769942] usb 1-1: Detected FT2232C [ 7717.770078] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB1 </code></pre> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jun 18 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tricks" hreflang="en">Tricks</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/microcontroller" hreflang="en">Microcontroller</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=185&amp;2=comment&amp;3=comment" token="WcILvydcEtVUg6zpBYwW4VZeVvpQo6X03jd8Yp1Riac"></drupal-render-placeholder> </section> Sat, 18 Jun 2016 08:09:36 +0000 Hoti 185 at https://tech.feedyourhead.at HackADay: Controlling power outlets using the Raspberry Pi https://tech.feedyourhead.at/content/controlling-power-outlets-using-the-rapberry-pi <span class="field field--name-title field--type-string field--label-hidden">HackADay: Controlling power outlets using the Raspberry Pi</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/steckdosen_aktion.webm" type="video/webm"></source></video></p> <p>My plan was to control some power outlets(16 ampere) using any browser(for example with a mobile phone). I wanted to use electronics only and tried to avoid relays.</p> <p> </p> <h3>Concept</h3> <p>I installed a Debian on my Raspberry Pi(including XBMC aka Kodi) on which a lighthttpd-daemon is running. This Webserver is calling a cgi-script(perl) which enables or disables the power sockets via it's GPIO-Pins. To make it as easy as possible I just call the gpio-command from the <a href="http://wiringpi.com/">WiringPi-Project.</a> I really love to make things work automagically. That's why I also included a function for enabling or disabling a socket at a specific time. Since I kept everything as simple as possible I just used a simple at-job for this.</p> <h3>GPIO</h3> <p><img alt="Raspberry Pi GPIO Pins" data-entity-type="file" data-entity-uuid="0fdfe731-f986-49af-9c1c-28bf3a1e0d59" src="/sites/default/files/inline-images/raspberry_gpio.jpg" /></p> <p>I am using the following Pins: GPIO23(socket 1), GPIO25(socket 2), P1-02 for 5volt power supply and P1-06 for ground.</p> <h3>Wiring</h3> <p>The most difficult thing was the wiring. As I already mentioned, I really wanted to avoid relays. Therefore I created this circuit: the GPIO-Pin controls an optocoppler(MOC3041) limited by a transistor(BC547). The optocoppler itself is switching a TRIAC(BT 139). The TRIAC enables or disables the power socket.</p> <p>That's the circuit:</p> <p><img alt="Circuit" data-entity-type="file" data-entity-uuid="a6fb9d6c-242a-4a7e-a200-ba88b8fcdfa6" src="/sites/default/files/inline-images/steckdosenschaltung_schaltplan.png" /></p> <p> </p> <p>...and that's how it looks like:</p> <p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/steckdosen_aufbau.webm" type="video/webm"></source></video></p> <h3>Programming</h3> <p>The Website is very very simple and looks like this:</p> <p><img alt="Website-Screenshot" data-entity-type="file" data-entity-uuid="02d16e00-a6aa-4ed2-981c-28baf11edae4" src="/sites/default/files/inline-images/steckdosenwebsite.jpg" /></p> <p>..very basic, isn't it?</p> <p>Don't forget to change the sudo-rights for www-data:</p> <p>/etc/sudoers:</p> <pre> <code> www-data ALL=NOPASSWD:/usr/local/bin/gpio </code></pre> <p>You can find all the sources of this project on <a href="https://github.com/whotwagner/power-outlets">my github</a>.</p> <h3><br /> Final Words</h3> <p>This project was a lot of fun. I got much support at the <a href="https://metalab.at/">Meta Lab(The very best hacker-space in vienna),</a> The project works very well. I also implemented some (green)diodes for indicating if the sockets are enabled or not. And don't forget that I really installed a full <a href="https://kodi.tv/">xbmc-system</a>. That's why my sockets are also a full multimedia center!!</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Mar 05 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hackaday" hreflang="en">HackADay</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/raspberry" hreflang="en">Raspberry</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=164&amp;2=comment&amp;3=comment" token="-SY7lVx3Xoo2MZaTaovmasF1HkfkWgNMPbp_cxgoyzM"></drupal-render-placeholder> </section> Sat, 05 Mar 2016 15:57:26 +0000 Hoti 164 at https://tech.feedyourhead.at Space Invaders using 8x8 LED-Display on Tiva-Board TM4C1294XL https://tech.feedyourhead.at/node/145 <span class="field field--name-title field--type-string field--label-hidden">Space Invaders using 8x8 LED-Display on Tiva-Board TM4C1294XL</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I created 2 tasks in RTOS: one for reading from uart and one for the display(<a href="http://www.mikroe.com/click/8x8-r/">8x8 LED-Matrix</a>). Both tasks are communicating via queues. The space-invaders-programm gets started by pressing F1. If F2 is pressed, the programm will display all keyboard-input on the led-display.</p> <p> <video controls="" height="1280" width="720"><source src="/sites/default/files/DateiUploads/tiva.ogv" type="video/ogg" /></video> </p> <p><a href="/sites/default/files/DateiUploads/RTOS_8x8Click.tar.gz">Click here to download the sources</a></p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jan 15 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hackaday" hreflang="en">HackADay</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <div class="node__links"> <ul class="links inline"><li class="comment-add"><a href="/node/145#comment-form" title="Share your thoughts and opinions." hreflang="en">Add new comment</a></li></ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title">Comments</h2> <article data-comment-user-id="0" id="comment-103" about="/comment/103" typeof="schema:Comment" class="comment js-comment by-anonymous"> <mark class="hidden" data-comment-timestamp="1543927016"></mark> <footer class="comment__meta"> <article typeof="schema:Person" about="/user/0" class="profile"> </article> <p class="comment__submitted"><span rel="schema:author">Submitted by <span lang="" typeof="schema:Person" property="schema:name" datatype="">TheDap (not verified)</span> on Nov 30 2018</span> <span property="schema:dateCreated" content="2018-11-30T08:37:33+00:00" class="rdf-meta hidden"></span> </p> <a href="/comment/103#comment-103" hreflang="en">Permalink</a> </footer> <div class="content"> <h3 property="schema:name" datatype=""><a href="/comment/103#comment-103" class="permalink" rel="bookmark" hreflang="en">uwielbiam was</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>hello. i am from poland. i uwielbiam was!</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=103&amp;1=default&amp;2=en&amp;3=" token="8IxLol-RCK2QfmlXRvmS1Zp3_qGocngfdI12BVy7jd0"></drupal-render-placeholder> </div> </article> <div class="indented"> <article data-comment-user-id="1" id="comment-104" about="/comment/104" typeof="schema:Comment" class="comment js-comment by-node-author"> <mark class="hidden" data-comment-timestamp="1543927047"></mark> <footer class="comment__meta"> <article typeof="schema:Person" about="/users/hoti" class="profile"> </article> <p class="comment__submitted"><span rel="schema:author">Submitted by <span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span> on Dec 04 2018</span> <span property="schema:dateCreated" content="2018-12-04T12:37:27+00:00" class="rdf-meta hidden"></span> </p> <p class="parent visually-hidden">In reply to <a href="/comment/103#comment-103" class="permalink" rel="bookmark" hreflang="en">uwielbiam was</a> by <span lang="" typeof="schema:Person" property="schema:name" datatype="">TheDap (not verified)</span></p> <a href="/comment/104#comment-104" hreflang="en">Permalink</a> </footer> <div class="content"> <h3 property="schema:name" datatype=""><a href="/comment/104#comment-104" class="permalink" rel="bookmark" hreflang="en">haha allways happy to help</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item">haha allways happy to help</div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=104&amp;1=default&amp;2=en&amp;3=" token="Hi0vDbW9YLQBsq24HB9m3StO776yQ05F1sYedZo5310"></drupal-render-placeholder> </div> </article> </div> <article data-comment-user-id="0" id="comment-107" about="/comment/107" typeof="schema:Comment" class="comment js-comment by-anonymous"> <mark class="hidden" data-comment-timestamp="1546279262"></mark> <footer class="comment__meta"> <article typeof="schema:Person" about="/user/0" class="profile"> </article> <p class="comment__submitted"><span rel="schema:author">Submitted by <span lang="" typeof="schema:Person" property="schema:name" datatype="">ltonropit (not verified)</span> on Dec 25 2018</span> <span property="schema:dateCreated" content="2018-12-25T16:51:48+00:00" class="rdf-meta hidden"></span> </p> <a href="/comment/107#comment-107" hreflang="en">Permalink</a> </footer> <div class="content"> <h3 property="schema:name" datatype=""><a href="/comment/107#comment-107" class="permalink" rel="bookmark" hreflang="en">Hi everyone. I need to help</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>I am ltonser. I need help. What can i do it?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=107&amp;1=default&amp;2=en&amp;3=" token="pc58SuPlL1cyFmEt5f6veN6PvB2IkTk_FO1GhL2Yo3Y"></drupal-render-placeholder> </div> </article> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=145&amp;2=comment&amp;3=comment" token="a33qdQaTba_r0l1vv_FwBZIgC6oqt3O6UNjiRBrveEo"></drupal-render-placeholder> </section> Fri, 15 Jan 2016 20:42:16 +0000 Hoti 145 at https://tech.feedyourhead.at Running LED on a Tiva-Board TM4C1294XL https://tech.feedyourhead.at/content/running-led-tiva-board-tm4c1294xl <span class="field field--name-title field--type-string field--label-hidden">Running LED on a Tiva-Board TM4C1294XL</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>For my studies I have to work with the Tiva-Board TM4C1294XL. I was quite lost when I tried to find examples in the internet. For all the poor souls who have to work with the tiva-board TM4C1294XL, I am going to publish the code I have to write on it. Here is some simple code for a runnig LED-light. If you push the USR1-button, it will change it's direction.</p> <pre> <code> #include <stdint.h> #include <stdbool.h> #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "drivers/pinout.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/sysctl.h" #include "inc/tm4c1294ncpdt.h" void WriteOut(uint8_t bitmask) { GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x0); GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x0); if(bitmask == 0) return; if( (bitmask &amp; 1) || (bitmask &amp; 16) ) { GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x2); } if( (bitmask &amp; 2) || (bitmask &amp; 32) ) { GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x1); } if( (bitmask &amp; 4) || (bitmask &amp; 64) ) { GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x10); } if( (bitmask &amp; 8) || (bitmask &amp; 128) ) { GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x1); } } int main(void) { volatile int delay = 700000; volatile int direction = 1; volatile uint8_t runner = 1; uint32_t config_strength, config_type; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1); GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x0); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4); GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x0); GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE,GPIO_PIN_0); GPIOPadConfigGet(GPIO_PORTJ_BASE,GPIO_PIN_0,&amp;config_strength,&amp;config_type); GPIOPadConfigSet(GPIO_PORTJ_BASE,GPIO_PIN_0,config_strength,GPIO_PIN_TYPE_STD_WPU); if(direction == 1) runner = 0; WriteOut(0); while(1) { if(GPIOPinRead(GPIO_PORTJ_BASE,GPIO_PIN_0) == 0) { if(direction == 0) direction = 1; else richtung = 0; } WriteOut(runner); SysCtlDelay(delay); if(direction == 0) { if(runner == 0) runner = 1; else runner = runner &lt;&lt; 1; } else { if(runner == 0) runner = 0x8; else runner = runner &gt;&gt; 1; } } } </code></pre> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Oct 01 2015</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tm4c1294xl" hreflang="en">TM4C1294XL</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/c" hreflang="en">C</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/electronic" hreflang="en">Electronic</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/microcontroller" hreflang="en">Microcontroller</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=114&amp;2=comment&amp;3=comment" token="M_b41FhfcGGV_51pqf4pLN8DiPzm8PwIWBx7oPidUEw"></drupal-render-placeholder> </section> Thu, 01 Oct 2015 07:21:14 +0000 Hoti 114 at https://tech.feedyourhead.at