Hybrid classes this week.
BTE1522
DRE2213
The world is digital, but life is analog..
Hybrid classes this week.
BTE1522
DRE2213
Let’s explore learning programming by troubleshooting Codes 😀 – Flags and Scoring Systems in Python
Today’s coding session was all about debugging and enhancing a game we’ve been developing step by step. We dove into Act 4, 5, 6 and 7, focusing on how to fix some key issues in the game logic—specifically how to properly handle scoring during collisions between the player and enemies.
PBL – ‘The Problem’
We already had a working player and enemy system in the game. The player can move left and right, while an enemy drops down from the top of the screen. The challenge was ensuring the player’s score only increased by one upon a collision with the enemy. Instead, the score was skyrocketing with every game frame where the player touched the enemy, adding several points instead of just one.
This type of issue is common when developing games, where collisions can occur over multiple frames. But we only want the score to increment once per collision event. To fix this, we introduced an important concept: the flag.
Introducing Flags in Python
In programming, a flag is a boolean variable (True/False) used to indicate whether a certain condition has been met. For our game, we needed a flag to signal whether a collision between the player and enemy had already occurred. This would prevent the score from increasing continuously while the player and enemy rectangles overlap.
Using a Flag to Control Scoring
Here’s how we used the flag –
collision_occurred
, which is initially set to False
. This flag keeps track of whether the collision has already happened.collision_occurred
is True
or False
.
False
and a collision happens, the score increments by 1, and the flag is set to True
. This prevents further increments until the enemy resets.True
, no further points are added, even if the player remains in contact with the enemy.False
, allowing for another score increment during the next collision.p/s Score Board is being implemented this year. One of the ways to monitor students progress in class
BTE1522
DRE2213
In Week 2 of the BTE1522 DRE2213 course, the focus was on fundamental programming concepts, specifically data types and control statements in Python. These are critical building blocks for developing logical structures within any programming language and are key to enabling students to design functional applications.
int
): Whole numbers, like 1, 2, or 100.float
): Numbers with decimal points, like 3.14 or 5.0.str
): Text data, enclosed in quotes, like “Hello, World!”.bool
): True or False values, used for conditional logic.Activity 1-3: Player Creation and Movement
Students applied their understanding of data types and control statements through practical coding exercises. In Activities 1-3, they created a basic player character and programmed its movement across the game window.
The coding exercise allowed students to implement:
Moving to the Second Phase – Five Challenges
After completing the initial activities, students moved to a more challenging phase involving code modifications and analysis. They were tasked with modifying and analyzing code to address five distinct challenges, each designed to deepen their understanding of data types and control statements.
Challenge 1: Modify Movement with Control Statements
Objective – Students were introduced to control statements such as if, elif, and else. They modified the code to allow the player to move based on specific conditions, such as different key presses resulting in different player actions.
Challenge 2: Boundary Control with Conditional Statements
Objective – In this challenge, students explored boundary detection using if and else statements. The goal was to prevent the player from moving outside the game window. This reinforced their understanding of how conditions can control flow in a program.
Challenge 3: Change Player’s Color with Data Types
Objective – Students were introduced to the concept of variables and data types such as lists and tuples. The challenge was to change the player’s color based on certain conditions, like the player reaching specific coordinates.
Challenge 4: Score and Time Tracking with Variables
Objective – Students explored the use of variables and loops to add a scoring system and time limit. They learned how to create a variable that increments when the player performs specific actions and how to manage game time using a while loop.
Challenge 5: Advanced Activity: Collision Detection
Objective – The final challenge involved practicing control structures and Boolean data types to detect when the player collided with the screen edges. This challenge required students to think critically about game dynamics and how to implement collision logic.
Pedagogical Approaches in the Exercise
To ensure a thorough understanding, two pedagogical approaches were used throughout the five challenges:
Week 2 was an essential part of the course as it introduced fundamental programming concepts like data types and control statements in Python. Through interactive activities and challenges, students not only learned to implement these concepts but also developed problem-solving skills by engaging in code modification and analysis. These exercises laid a strong foundation for the more advanced topics to come in the course.
Nurul Oct 15th
DRE2213
BTE1522
A 4-days workshop crafted for academicians from Polytechnics Malaysia.
I recently conducted a comprehensive 4-day workshop to introduce participants (among academicians from Polytechnics in Malaysia) to both fundamental and advanced topics, offering hands-on activities that showcased the powerful applications of AI, electronics, and programming.
Thank you Pn Azlyn for coordinating the communication and facilitating the process :).
Below is a summary of the activities we conducted over the course of this workshop.
Day 1 Foundations of AI, Python, and Raspberry Pi
The workshop kicked off with an introduction to AI and the Raspberry Pi microprocessor. We started with a fun ice-breaker activity, Introduction BINGO, where participants got to know each other. Afterward, we delved into the fundamental concepts of hardware and electronic components, ensuring everyone was comfortable with the physical aspects of working with a Raspberry Pi.
Key Topics Covered –
Day 2 Control Statements, Communication, and Sensors
We began Day 2 by introducing participants to Python control statements, providing the backbone for controlling the hardware components with Python scripts. This session included practical activities focused on various communication protocols like I2C and SPI, commonly used for sensor integration.
Key Activities and Topics –
Hands-on Activities –
Day 3 Exploring Sensors and Camera Controls
On Day 3, we moved into more complex sensor and camera integration. Participants worked hands-on with various sensors to collect and process real-world data.
Key Sensors Covered –
Key Highlights
Looking Forward
This workshop is just the beginning. The potential of Raspberry Pi combined with Python programming offers limitless possibilities, from creating AI-powered projects to building real-world applications. Participants left equipped with the skills and confidence to continue their journey in AI and embedded systems development.
Conclusion
In just four days, participants transitioned from having no experience with Raspberry Pi or Python to developing their own AI-based projects. This course laid a strong foundation for understanding hardware, software, and AI in a hands-on, engaging way. The combination of sensors, control statements, and camera-based projects showcased the immense power of integrating AI and Python with Raspberry Pi.
Stay tuned for more workshops that push the boundaries of AI and embedded programming!
I hope everyone had enjoyed the course as much as I did in facilitating it.
Nurul (Oct 3rd, 2024)
Day 4
Day 3
Day 2
Day 1
Misc
In today’s class – BTE 1522 – Innovation Python Programming and Raspberry Pi, we engaged in a dynamic and interactive learning session that combined elements of Gallery Walk and Reciprocal Teaching. This approach not only fostered collaboration and deeper understanding but also enhanced students’ ability to explain and defend their projects. Here’s a breakdown of how the session unfolded and the learning theories behind it.
Activity Overview
1 – Project Development
Students were divided into groups (1 through 5).
Each group developed a project using on Raspberry Pi, integrating sensors like BME280 & cameras, building databases, and creating dashboards.
2 – Reciprocal Teaching with a Twist
Instead of presenting their own work, each group was tasked with presenting the project of another group. For example, Group 2 (Angelina & Syarah) presented the work done by Group 1 (Amir, Azhad, Aiman).
This approach required students to thoroughly understand projects created by other groups. By presenting and understanding projects from other groups, students applied their Python coding knowledge to analyze and interpret how different groups implemented solutions using Raspberry Pi. This hands-on experience allowed them to see real-world applications of Python in sensor integration, data handling, and project implementation on the Raspberry Pi platform. It reinforced their learning by showing them diverse approaches to coding, problem-solving, and integrating hardware components like sensors, cameras, and GPS modules into functional systems.
3 – Gallery Walk Elements
After Group 1 presents their project on the Environmental Monitoring and Imaging System, the session transitions into an interactive phase. Students from Groups 3, 4, 5, and 6 ask one question each about the presented project. These questions delve into various aspects of the system, such as the integration of sensors like the BME280 for environmental data collection, the methodologies employed in Python programming to process and visualize this data, and the techniques utilized for imaging purposes.
This structured Q&A session serves multiple purposes. First, it allows students from other groups to gain deeper insights into the technical details and methodologies employed by Group 1. By asking pertinent questions, students from Groups 3, 4, 5, and 6 not only expand their understanding of different project components but also evaluate the comprehensiveness and innovation of Group 1’s work.
For Group 1, this session becomes an opportunity to demonstrate their expertise and depth of knowledge regarding their project. By articulating clear and detailed responses to the questions posed by their peers, Group 1 showcases their understanding of Python programming techniques applied to sensor integration, data processing, and system implementation. They also highlight their proficiency in problem-solving and innovation within the context of environmental monitoring and imaging systems.
This approach fosters a collaborative learning environment where students engage critically with each other’s work, exchange ideas, and enhance their technical and communication skills. It aligns with the assignment topics by emphasizing the application of Python programming in real-world IoT (Internet of Things) projects involving environmental monitoring, precision agriculture, GPS tracking, and photography with weather data integration.
Evaluation Criteria
Reciprocal Teaching
By having students present projects they did not create, we leveraged the principles of reciprocal teaching. This method encourages active learning, critical thinking, and the ability to teach others, which in turn reinforces their own understanding.
Gallery Walk
Incorporating a Q&A session akin to a gallery walk allowed students to engage with multiple projects, ask insightful questions, and provide constructive feedback. This technique promotes active engagement, observational learning, and peer-to-peer interaction.
Peer Teaching
This hybrid approach facilitated peer teaching, where students learned from each other by presenting and questioning different projects. Peer teaching is known to enhance comprehension and retention of material as students explain concepts to their peers.
Collaborative Learning
Working in groups to understand and present different projects encouraged collaboration. Collaborative learning helps develop teamwork skills, enhances problem-solving abilities, and fosters a sense of community within the class.
Benefits of the Approach
To all the BTE1522 students (Sem 1 2024 2025), thank you very much for your active participation throughout the semester. I hope you’ve enjoyed the classes as much as I do =).
Nurul – June 16th 2024
All the best everyone
Today’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.
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.
Components Needed:
Steps:
Connecting the GPS Module:
Powering Up: Power on the Raspberry Pi and ensure all connections are secure.
Python Modules:
gpsd
: A popular library for interfacing with GPS modules.serial
: A library for handling serial communication.UART Communication:
Installing Libraries:
sudo apt-get install gpsd gpsd-clients python-gps
Python Code Example:
import gpsd
# Connect to the local gpsd
gpsd.connect()
# Get GPS data
def get_gps_data():
packet = gpsd.get_current()
latitude = packet.lat
longitude = packet.lon
time = packet.time
return latitude, longitude, time
# Print GPS data
lat, lon,
timestamp = get_gps_data()
print(f"Latitude: {lat}, Longitude: {lon}, Time: {timestamp}")
I2C Communication:
Enabling I2C:
sudo raspi-config
Navigate to ‘Interfacing Options’ and enable I2C.
Python Code Example:
import smbus2
import time
bus = smbus2.SMBus(1)
address = 0x42 # Replace with your GPS module's I2C address
def read_gps():
data = bus.read_i2c_block_data(address, 0, 16)
return data
while True:
gps_data = read_gps()
print(gps_data)
time.sleep(1)
UART (Universal Asynchronous Receiver-Transmitter):
I2C (Inter-Integrated Circuit):
Integrating GPS functionality into Raspberry Pi projects offers a robust foundation for creating advanced IoT applications and location-based services. Today’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.
Today we explored SSH (Secure Shell) and data visualization using the Raspberry Pi platform. This is the final session before students embark on their final projects, providing them with essential skills in remote control and data acquisition.
SSH Connection with Raspberry Pi – We began by establishing an SSH connection to our Raspberry Pi using Putty, a widely-used SSH client. Through SSH, students learned how to remotely control their Raspberry Pi from their local machines, enabling seamless interaction with the Pi’s command-line interface. Navigational commands such as cd, ls, pwd, and mkdir were explored, empowering students to navigate the file system, create directories, and manage files effortlessly.
Data Visualization with Adafruit and BME280 -The session also featured a demonstration of data visualization using the Adafruit platform and the BME280 sensor. Students gained hands-on experience in acquiring environmental data such as temperature, humidity, and pressure using the BME280 sensor, a vital component for IoT (Internet of Things) applications. By visualizing this data, students could better understand real-world applications of sensor data and its significance in various projects.
Remote Python Program Execution -A key highlight of today’s activities was the execution of Python programs remotely via SSH. Students learned how to run Python scripts on their Raspberry Pi from their local machines, enabling them to execute code, perform data analysis, and control hardware components without direct physical access to the Pi. Commands such as nano for text editing and cat for displaying file contents further enriched their understanding of remote file management.
Exploring System Information:
To wrap up the session, we delved into exploring system information commands such as uname -a, df -h, and free -h. These commands provided insights into system specifications, disk space usage, and memory utilization, essential for monitoring and optimizing Raspberry Pi performance.
I look forward to the upcoming project phase, I am confident you are well-prepared to could apply their this knowledge and skills in developing innovative Raspberry Pi-based solutions.
Nurul
May 24th