{"id":27413,"date":"2024-06-07T17:36:05","date_gmt":"2024-06-07T09:36:05","guid":{"rendered":"http:\/\/hazlina-backup-27413"},"modified":"2024-06-07T17:36:05","modified_gmt":"2024-06-07T09:36:05","slug":"bte-1522-programmibg-and-data-structure","status":"publish","type":"post","link":"\/hazlina-blog\/2024\/06\/07\/bte-1522-programmibg-and-data-structure\/","title":{"rendered":"BTE 1522 \u2013 Programming and Data Structure \u2013 Project Preparation"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Today&#8217;s BTE 1522 class was an exciting dive into the world of GPS technology and its integration with Raspberry Pi. We explored the essential concepts, from importing relevant Python modules for GPS functionality to circuit construction and function coding. This session is a crucial part of our project development series, providing students with hands-on experience in incorporating GPS modules into their Raspberry Pi projects.<\/p>\n<h3>Understanding GPS and Its Importance<\/h3>\n<p>Global Positioning System (GPS) is a satellite-based navigation system that provides geolocation and time information to a GPS receiver anywhere on or near the Earth. Integrating GPS into Raspberry Pi projects opens up numerous possibilities, such as tracking, navigation, and location-based services, which are pivotal in various applications like autonomous vehicles, drones, and IoT devices.<\/p>\n<h3>Circuit Construction for GPS Integration<\/h3>\n<p><strong>Components Needed:<\/strong><\/p>\n<ol>\n<li>Raspberry Pi<\/li>\n<li>GPS Module (e.g., NEO-6M)<\/li>\n<li>Connecting Wires<\/li>\n<li>Breadboard (optional)<\/li>\n<\/ol>\n<p><strong>Steps:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>Connecting the GPS Module:<\/strong><\/p>\n<ul>\n<li><strong>UART Communication:<\/strong> Connect the GPS module&#8217;s TX (transmit) pin to the Raspberry Pi&#8217;s RX (receive) pin and the GPS module&#8217;s RX pin to the Raspberry Pi&#8217;s TX pin. Additionally, connect the VCC pin to the 3.3V or 5V power supply (depending on your GPS module specifications) and the GND pin to the ground.<\/li>\n<li><strong>I2C Communication:<\/strong> If your GPS module supports I2C, connect the SDA (data) and SCL (clock) pins of the GPS module to the corresponding pins on the Raspberry Pi. Ensure the VCC and GND pins are also properly connected.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Powering Up:<\/strong> Power on the Raspberry Pi and ensure all connections are secure.<\/p>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-27428\" src=\"\/hazlina\/wp-content\/uploads\/2024\/06\/WhatsApp-Image-2024-06-07-at-10.57.12.jpeg\" alt=\"\" width=\"678\" height=\"640\" srcset=\"\/hazlina\/wp-content\/uploads\/2024\/06\/WhatsApp-Image-2024-06-07-at-10.57.12.jpeg 678w, \/hazlina\/wp-content\/uploads\/2024\/06\/WhatsApp-Image-2024-06-07-at-10.57.12-300x283.jpeg 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<h3>Coding for GPS Integration<\/h3>\n<p><strong>Python Modules:<\/strong><\/p>\n<ul>\n<li><code>gpsd<\/code>: A popular library for interfacing with GPS modules.<\/li>\n<li><code>serial<\/code>: A library for handling serial communication.<\/li>\n<\/ul>\n<p><strong>UART Communication:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>Installing Libraries:<\/strong><\/p>\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo apt-get install gpsd gpsd-clients python-gps<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<li>\n<p><strong>Python Code Example:<\/strong><\/p>\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">python<\/div>\n<\/div>\n<div>\u00a0<\/div>\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\"><span class=\"hljs-keyword\">import<\/span> gpsd<\/p>\n<p><span class=\"hljs-comment\"># Connect to the local gpsd<\/span><br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">gpsd.connect()<\/p>\n<p><span class=\"hljs-comment\"># Get GPS data<\/span><br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title function_\">get_gps_data<\/span>():<br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">    packet = gpsd.get_current()<br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">    latitude = packet.lat<br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">    longitude = packet.lon<br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">    time = packet.time<br \/>\n    <span class=\"hljs-keyword\">return<\/span> latitude, longitude, time<\/p>\n<p><span class=\"hljs-comment\"># Print GPS data<\/span><br \/>\nlat, lon, <\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">timestamp = get_gps_data()<br \/>\n<span class=\"hljs-built_in\">print<\/span>(<span class=\"hljs-string\">f\"Latitude: <span class=\"hljs-subst\">{lat}<\/span>, Longitude: <span class=\"hljs-subst\">{lon}<\/span>, Time: <span class=\"hljs-subst\">{timestamp}<\/span>\"<\/span>)<\/code><\/div>\n<\/div>\n<div dir=\"ltr\">\u00a0<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-27429\" src=\"\/hazlina\/wp-content\/uploads\/2024\/06\/WhatsApp-Image-2024-06-07-at-08.51.54.jpeg\" alt=\"\" width=\"738\" height=\"549\" srcset=\"\/hazlina\/wp-content\/uploads\/2024\/06\/WhatsApp-Image-2024-06-07-at-08.51.54.jpeg 738w, \/hazlina\/wp-content\/uploads\/2024\/06\/WhatsApp-Image-2024-06-07-at-08.51.54-300x223.jpeg 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/li>\n<\/ol>\n<p><strong>I2C Communication:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>Enabling I2C:<\/strong><\/p>\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">sudo raspi-config<br \/>\n<\/code><\/div>\n<\/div>\n<p>Navigate to &#8216;Interfacing Options&#8217; and enable I2C.<\/p>\n<\/li>\n<li>\n<p><strong>Python Code Example:<\/strong><\/p>\n<div class=\"dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">python<\/p>\n<div class=\"flex items-center\">\u00a0<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\"><span class=\"hljs-keyword\">import<\/span> smbus2<br \/>\n<span class=\"hljs-keyword\">import<\/span> time<\/p>\n<p>bus = smbus2.SMBus(<span class=\"hljs-number\">1<\/span>)<br \/>\naddress = <span class=\"hljs-number\">0x42<\/span>  <span class=\"hljs-comment\"># Replace with your GPS module's I2C address<\/span><br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title function_\">read_gps<\/span>():<br \/>\n    data = bus.read_i2c_block_data(address, <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">16<\/span>)<br \/>\n    <span class=\"hljs-keyword\">return<\/span> data<\/p>\n<p><span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">True<\/span>:<br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">    gps_data = read_gps()<br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\">    <span class=\"hljs-built_in\">print<\/span>(gps_data)<br \/>\n    time.sleep(<span class=\"hljs-number\">1<\/span>)<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ol>\n<h3>Communication Protocols<\/h3>\n<p><strong>UART (Universal Asynchronous Receiver-Transmitter):<\/strong><\/p>\n<ul>\n<li><strong>Pros:<\/strong> Simple to use, widely supported.<\/li>\n<li><strong>Cons:<\/strong> Limited to point-to-point communication.<\/li>\n<\/ul>\n<p><strong>I2C (Inter-Integrated Circuit):<\/strong><\/p>\n<ul>\n<li><strong>Pros:<\/strong> Supports multiple devices on the same bus, more flexible.<\/li>\n<li><strong>Cons:<\/strong> More complex than UART, requires addressing.<\/li>\n<\/ul>\n<h3>Key Learning Outcomes<\/h3>\n<ul>\n<li><strong>Circuit Construction:<\/strong> Students learned how to set up a GPS module with Raspberry Pi, ensuring correct connections for power, ground, and communication lines.<\/li>\n<li><strong>Coding Techniques:<\/strong> We explored Python coding for both UART and I2C communication protocols, highlighting the differences and use cases for each.<\/li>\n<li><strong>Real-Time Data Acquisition:<\/strong> Students gained practical skills in capturing and processing GPS data, which can be applied to various projects requiring geolocation capabilities.<\/li>\n<\/ul>\n<p>Integrating GPS functionality into Raspberry Pi projects offers a robust foundation for creating advanced IoT applications and location-based services. Today&#8217;s class provided a comprehensive understanding of the hardware setup and coding techniques necessary to harness GPS data effectively. As we move forward, these skills will be crucial for the final project development phase, enabling students to implement sophisticated and innovative solutions.<\/p>\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" class=\"wp-image-27411\" src=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_1000278814097662343442880-1024x768.jpg\" alt=\"\" srcset=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_1000278814097662343442880-1024x768.jpg 1024w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_1000278814097662343442880-300x225.jpg 300w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_1000278814097662343442880-768x576.jpg 768w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_1000278814097662343442880-1200x900.jpg 1200w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_1000278814097662343442880.jpg 2000w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<p>&nbsp;<\/p>\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" class=\"wp-image-27410\" src=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959423489320703038334050-1024x768.jpg\" alt=\"\" srcset=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959423489320703038334050-1024x768.jpg 1024w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959423489320703038334050-300x225.jpg 300w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959423489320703038334050-768x576.jpg 768w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959423489320703038334050-1200x900.jpg 1200w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959423489320703038334050.jpg 2000w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<p>&nbsp;<\/p>\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" class=\"wp-image-27412\" src=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959335079379459433315880-1024x768.jpg\" alt=\"\" srcset=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959335079379459433315880-1024x768.jpg 1024w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959335079379459433315880-300x225.jpg 300w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959335079379459433315880-768x576.jpg 768w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959335079379459433315880-1200x900.jpg 1200w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0959335079379459433315880.jpg 2000w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<p>&nbsp;<\/p>\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" class=\"wp-image-27409\" src=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0958197978168124743854888-1024x768.jpg\" alt=\"\" srcset=\"\/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0958197978168124743854888-1024x768.jpg 1024w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0958197978168124743854888-300x225.jpg 300w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0958197978168124743854888-768x576.jpg 768w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0958197978168124743854888-1200x900.jpg 1200w, \/hazlina\/wp-content\/uploads\/2024\/06\/20240607_0958197978168124743854888.jpg 2000w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s BTE 1522 class was an exciting dive into the world of GPS technology and its integration with Raspberry Pi. We explored the essential concepts, from importing relevant Python modules for GPS functionality to circuit construction and function coding. This session is a crucial part of our project development series, providing students with hands-on experience &hellip; <a href=\"\/hazlina\/2024\/06\/07\/bte-1522-programmibg-and-data-structure\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;BTE 1522 &#8211; Programming and Data Structure &#8211; Project Preparation&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[13],"class_list":["post-27413","post","type-post","status-publish","format-standard","hentry","category-information","tag-academia-python-prog"],"_links":{"self":[{"href":"\/hazlina-blog\/wp-json\/wp\/v2\/posts\/27413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/hazlina-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/hazlina-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/hazlina-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"\/hazlina-blog\/wp-json\/wp\/v2\/comments?post=27413"}],"version-history":[{"count":0,"href":"\/hazlina-blog\/wp-json\/wp\/v2\/posts\/27413\/revisions"}],"wp:attachment":[{"href":"\/hazlina-blog\/wp-json\/wp\/v2\/media?parent=27413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/hazlina-blog\/wp-json\/wp\/v2\/categories?post=27413"},{"taxonomy":"post_tag","embeddable":true,"href":"\/hazlina-blog\/wp-json\/wp\/v2\/tags?post=27413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}