<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sadeep Ariyarathna on Medium]]></title>
        <description><![CDATA[Stories by Sadeep Ariyarathna on Medium]]></description>
        <link>https://medium.com/@sadeepari?source=rss-9c795fc83c70------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UDQBAYah4a5AUp9e</url>
            <title>Stories by Sadeep Ariyarathna on Medium</title>
            <link>https://medium.com/@sadeepari?source=rss-9c795fc83c70------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 19:53:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sadeepari/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[7 Segments Display with Raspberry Pi]]></title>
            <link>https://medium.com/@sadeepari/7-segments-display-with-raspberry-pi-a21780dbd972?source=rss-9c795fc83c70------2</link>
            <guid isPermaLink="false">https://medium.com/p/a21780dbd972</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[7-segment-display]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sadeep Ariyarathna]]></dc:creator>
            <pubDate>Sun, 04 Jun 2023 10:06:08 GMT</pubDate>
            <atom:updated>2023-06-04T10:06:08.398Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ryvhu_41yYybVfwU" /><figcaption>Photo by <a href="https://unsplash.com/@raymondhsu?utm_source=medium&amp;utm_medium=referral">Raymond Hsu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A 7-segment display is a type of electronic display device that can represent decimal numbers and some alphabetic characters. It consists of seven individually controllable segments arranged in a rectangular shape, with an additional eighth segment for displaying a decimal point.</p><p>To use a 7-segment display with a Raspberry Pi, you’ll need a few components and follow some steps.</p><p><strong>Components needed:</strong></p><ol><li>Raspberry Pi (any model)</li><li>Breadboard</li><li>7-segment display (common cathode or common anode)</li><li>Resistors (220 ohms is a common value)</li><li>Jumper wires</li><li>Power supply (for the Raspberry Pi and the 7-segment display)</li></ol><p><strong>Set up the hardware:</strong></p><ol><li>Connect the power supply to the Raspberry Pi.</li><li>Connect the common cathode (or common anode) pin of the 7-segment display to a ground pin on the Raspberry Pi.</li><li>Connect the individual segment pins of the display to the GPIO pins on the Raspberry Pi.</li><li>Connect a resistor to each segment pin and connect the other end of each resistor to a 3.3V or 5V pin on the Raspberry Pi, depending on the voltage requirements of your display.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zwFqpDyrQiUcUHaUbcKLQ.jpeg" /><figcaption>Schematic on <a href="https://microdigisoft.com/7-segment-display-interfacing-with-raspberry-pi/">Microdigisoft</a></figcaption></figure><p>Write the code:</p><ol><li>Create a new Python file and import the necessary modules:</li></ol><pre>import RPi.GPIO as GPIO <br>import time</pre><p>2. Set up the GPIO mode and define the segment PINs according to your wiring:</p><pre>GPIO.setmode(GPIO.BOARD)  <br>pins segments = [11, 12, 13, 15, 16, 18, 22] # Define segment</pre><p>3. Set up the GPIO pins as outputs:</p><pre>for segment in segments:     <br>  GPIO.setup(segment, GPIO.OUT)     <br>  GPIO.output(segment, GPIO.LOW)</pre><p>4. Define a dictionary to map numbers to their corresponding segments:</p><pre>numbers = {&#39;0&#39;: [1, 1, 1, 1, 1, 1, 0],     <br>&#39;1&#39;: [0, 1, 1, 0, 0, 0, 0],     <br>&#39;2&#39;: [1, 1, 0, 1, 1, 0, 1],     <br>&#39;3&#39;: [1, 1, 1, 1, 0, 0, 1],     <br>&#39;4&#39;: [0, 1, 1, 0, 0, 1, 1],     <br>&#39;5&#39;: [1, 0, 1, 1, 0, 1, 1],     <br>&#39;6&#39;: [1, 0, 1, 1, 1, 1, 1],     <br>&#39;7&#39;: [1, 1, 1, 0, 0, 0, 0],     <br>&#39;8&#39;: [1, 1, 1, 1, 1, 1, 1],     <br>&#39;9&#39;: [1, 1, 1, 0, 0, 1, 1],  <br>}   <br># Add mappings for other characters if needed </pre><p>5. Define a function to display a number on the 7-segment display:</p><pre>def display_number(number):     <br>  for i, segment in enumerate(segments):        <br>    GPIO.output(segment, numbers[number][i])</pre><p>6. Run the programme:</p><pre>display_number(6) # put the number you like. </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a21780dbd972" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Raspberry Pi Projects: Ultrasonic Sensing]]></title>
            <link>https://medium.com/@sadeepari/raspberry-pi-projects-ultrasonic-sensing-70ea8062a79f?source=rss-9c795fc83c70------2</link>
            <guid isPermaLink="false">https://medium.com/p/70ea8062a79f</guid>
            <category><![CDATA[ultrasonic-sensor]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Sadeep Ariyarathna]]></dc:creator>
            <pubDate>Sun, 28 May 2023 12:51:07 GMT</pubDate>
            <atom:updated>2023-05-28T12:51:07.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rmzmgPaHUPoR9ndk" /><figcaption>Photo by <a href="https://unsplash.com/@harrisonbroadbent?utm_source=medium&amp;utm_medium=referral">Harrison Broadbent</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The Raspberry Pi, a flexible and small single-board computer, has changed the face of DIY electronics and automation. When combined with an ultrasonic sensor, it opens up a world of possibilities for applications needing precise distance measurement. In this post, we’ll look at how to integrate ultrasonic sensors with Raspberry Pi and look at some of the potential uses of this powerful combo.</p><p><strong>Ultrasonic Sensor: HC — SR04</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fle_JvX04K9BnPwbIDGng.jpeg" /><figcaption>Ultrasonic Sensor on <a href="https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/">How to Mechatronics</a></figcaption></figure><p>Ultrasonic sensors work on the principle of sound waves. They emit high-frequency sound pulses and measure the time it takes for the pulses to bounce back after hitting an object. By calculating the time delay, the distance between the sensor and the object can be determined. Ultrasonic sensors are commonly used in robotics, automation, and security systems.</p><p><strong>Preparation</strong></p><p><em>Hardware</em></p><ul><li>Raspberry Pi (any model with GPIO pins)</li><li>HC-SR04 Ultrasonic Sensor Module</li><li>Jumper wires</li><li>Breadboard</li></ul><p><em>Software</em></p><ul><li>IDE ( Ex: Pycharm, Visual Studio Code)</li><li>Python3</li></ul><p><strong>Steps</strong></p><ul><li>Complete connections between Raspberry Pi and the Sensor</li></ul><blockquote>VCC to 5V power pin</blockquote><blockquote>GND to ground pin</blockquote><blockquote>Trig to a GPIO output pin (e.g., GPIO 16)</blockquote><blockquote>Echo to a GPIO input pin (e.g., GPIO 18)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*A8U80vD0ptVRjgZYqiT9-g.png" /><figcaption>Sensor Pin Out on <a href="https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf">Sparkfun</a></figcaption></figure><ul><li>Start a remote connection from your IDE to the Raspberry Pi. ( If you want to learn how to do it, <a href="https://medium.com/@sadeepari/access-raspberry-pi-with-ssh-in-pycharm-848df6d31e8a">Click here!</a> )</li><li>Install the Python GPIO library (if not already installed) using the package manager or use the command line. <a href="https://pypi.org/project/RPi.GPIO/">RPi. GPIO library</a></li></ul><pre>pip install RPi.GPIO</pre><ul><li>Create a new Python script and import the necessary libraries, including RPi.GPIO for GPIO control.</li></ul><pre>import RPi.GPIO as GPIO</pre><ul><li>Define the GPIO pins for the trigger and echo.</li></ul><pre>TRIGGER_PIN = 16<br>ECHO_PIN = 18</pre><ul><li>Initialize the GPIO pins and set their directions (input or output) accordingly.</li></ul><pre>GPIO.setmode(GPIO.BCM)<br><br>GPIO.setup(TRIGGER_PIN, GPIO.IN)<br>GPIO.setup(ECHO_PIN, GPIO.OUT)</pre><ul><li>Write a function to measure the distance using the ultrasonic sensor and GPIO pins.</li></ul><pre>GPIO.output(TRIGGER_PIN, GPIO.HIGH)<br><br>time.sleep(0.01) # this can be changed. <br># This is for the frquency to activating ultrasonic signal.  <br><br>GPIO.output(TRIGGER_PIN, GPIO.LOW)<br><br>pulse_start = time.time()<br>pulse_end = time.time()<br><br>while GPIO.input(ECHO_PIN) == GPIO.LOW: # save time when pulse idle<br>   pulse_start = time.time()<br><br>while GPIO.input(ECHO_PIN) == GPIO.HIGH: # save time when pulse stat<br>   pulse_end = time.time()<br><br>echotime = pulse_end - pulse_start # pulse duration<br><br># calculate distance<br>distance = (echotime * 34300)/2  <br>print(&quot;Distance: &quot;, distance)</pre><ul><li>Implement a loop to continuously read the distance and display it or perform further actions based on the measured value. The while loop will ensure the programme will run until the run condition is true.</li></ul><pre>while True:<br>    GPIO.output(TRIGGER_PIN, GPIO.HIGH)<br>    time.sleep(0.01)<br>    GPIO.output(TRIGGER_PIN, GPIO.LOW)<br><br>    pulse_start = time.time()<br>    pulse_end = time.time()<br><br>    while GPIO.input(ECHO_PIN) == GPIO.LOW:<br>       pulse_start = time.time()<br><br>    while GPIO.input(ECHO_PIN) == GPIO.HIGH:<br>       pulse_end = time.time()<br><br>    echotime = pulse_end - pulse_start <br>    distance = (echotime * 34300)/2<br>    print(&quot;Distance: &quot;, distance) </pre><p><strong>Conclusion</strong></p><p>Integrating an ultrasonic sensor with Raspberry Pi provides an excellent opportunity to develop projects involving distance measurement and beyond. By leveraging the versatility of Raspberry Pi and the accuracy of ultrasonic sensors, hobbyists and professionals alike can create innovative solutions across various domains.</p><p>Some of the fun projects like those below can help you to improve your coding skills as well as your creativity.</p><ul><li>Obstacle detection and avoidance for robots and autonomous vehicles.</li><li>Proximity sensing for automatic door opening systems.</li><li>Liquid level measurement in tanks or containers.</li><li>Presence detection for security systems.</li><li>Object tracking in computer vision applications.</li><li>Smart parking systems to detect vehicle occupancy.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70ea8062a79f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Access Raspberry Pi with SSH in PyCharm]]></title>
            <link>https://medium.com/@sadeepari/access-raspberry-pi-with-ssh-in-pycharm-848df6d31e8a?source=rss-9c795fc83c70------2</link>
            <guid isPermaLink="false">https://medium.com/p/848df6d31e8a</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[pycharm]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Sadeep Ariyarathna]]></dc:creator>
            <pubDate>Sun, 28 May 2023 12:48:49 GMT</pubDate>
            <atom:updated>2023-05-28T15:51:44.667Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H0rHLZSobo7fwRTF" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément Hélardot</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>By setting up the SSH configuration in PyCharm, you can conveniently edit, run, and debug code on your Raspberry Pi without leaving the PyCharm IDE. This integration provides a seamless development experience for Raspberry Pi projects.</p><ol><li>Install the necessary tools:</li></ol><ul><li>Install the Remote Development plugin in PyCharm. You can do this by going to “File” -&gt; “Settings” -&gt; “Plugins” and searching for “Remote Development”. Install and restart PyCharm if prompted.</li></ul><p>2. Set up an SSH configuration in PyCharm:</p><ul><li>Open PyCharm and create a new project or open an existing one.</li><li>Go to “File” -&gt; “Settings” -&gt; “Build, Execution, Deployment” -&gt; “Deployment”.</li><li>Click the “+” button to add a new deployment configuration.</li><li>Select “SFTP” from the dropdown menu.</li><li>Fill in the following details:</li><li>Name: Give a name to your deployment configuration.</li><li>SFTP host: Enter the IP address or hostname of your Raspberry Pi.</li><li>Port: Set the SSH port (default is 22).</li><li>User name: Enter the username to connect to your Raspberry Pi.</li><li>Auth type: Select “Key pair” or “Password” based on your SSH configuration.</li><li>Root path: Set the remote path to the root directory of your Raspberry Pi.</li><li>Click “OK” to save the configuration.</li></ul><p>3. Connect to the Raspberry Pi:</p><ul><li>In the PyCharm toolbar, click on the “Deployment” button (icon with an arrow pointing up).</li><li>Select the deployment configuration you created in the previous step.</li><li>PyCharm will establish an SSH connection to your Raspberry Pi.</li><li>Once connected, you can browse and edit files on your Raspberry Pi directly within PyCharm.</li></ul><p>4. Running code on the Raspberry Pi:</p><ul><li>To execute code on your Raspberry Pi, create a Python file in the PyCharm project.</li><li>Write your code as you would normally.</li><li>In the PyCharm toolbar, click on the “Run” button to run the code on your Raspberry Pi.</li><li>The output will be displayed in the PyCharm console.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=848df6d31e8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>