Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
be40da1
Add new projects: Binary Calculator and Judgement Game; introduce Ras…
XQuestCode Mar 20, 2025
4960e28
Add new guides for Raspberry Pi control flow and potentiometer usage;…
XQuestCode May 29, 2025
21ba3be
Merge branch 'raspberry-pi-tasks' of https://github.com/XQuestCode/th…
omckeon Jul 7, 2025
3e78664
Remove unwanted files
omckeon Jul 7, 2025
ef1313e
Update Part 0 Raspberry Pi pages
omckeon Jul 10, 2025
6f1b78e
Simplify the P0C3 Raspberry Pi guided activity.
omckeon Jul 10, 2025
70f3493
Add attributions for RPi images in P0C2
omckeon Jul 11, 2025
8702c58
Update blink LED diagram and add attribution
omckeon Jul 11, 2025
f1d2712
Update Pi installation page to add links for more information about c…
omckeon Jul 14, 2025
8041b51
Update P0C3 Gpio pages
omckeon Jul 14, 2025
54e7c07
Update file names to fix order in sidebar to have raspberry pi at the…
omckeon Jul 14, 2025
b487e64
P1C1 - Add initial 7-segment display content to overview section
omckeon Jul 15, 2025
e49224c
Update circuits diagrams to make it easier for moving to the 7-segmen…
omckeon Jul 15, 2025
f7b0c7e
Update diagram and move simplified pinout to guided tour
omckeon Jul 15, 2025
4425935
Initial plan for P1C1 guided tour
omckeon Jul 15, 2025
0762478
Move pages into control flow chapter - reading GPIO pin focus
omckeon Jul 15, 2025
8678487
P1C1 - Add in plan for gpio test your knowledge activity.
omckeon Jul 15, 2025
633d4b3
Update P1C1 Overview for GPIO
omckeon Jul 17, 2025
c3e098e
Move button press pages back to P1C1
omckeon Jul 17, 2025
75a9e6c
Update P1C1 overview pages
omckeon Jul 18, 2025
5919d54
Update P1C1 GPIO guided tour pages
omckeon Jul 18, 2025
171aa0f
Move 7-segment pages to P2C2
omckeon Jul 18, 2025
56aa91e
Rename pages
omckeon Jul 18, 2025
5b2763b
Update 7-seg pages
omckeon Jul 18, 2025
ccaacd0
Fix broken links
omckeon Jul 18, 2025
d9542a4
Merge branch 'main' of https://github.com/splashkit/the-programmers-f…
omckeon Jul 18, 2025
eba3ace
Add note with link to guided activity
omckeon Jul 21, 2025
9438e95
Remove part 2 file changes
omckeon Jul 21, 2025
d01cca9
Merge branch 'main' of https://github.com/splashkit/the-programmers-f…
omckeon Jul 21, 2025
c9377bf
Update dot points on GPIO Pins overview page
omckeon Jul 21, 2025
aa088cf
Merge branch 'main' of https://github.com/splashkit/the-programmers-f…
omckeon Jul 22, 2025
ef76a14
Add GpioPinValue to gpio methods page
omckeon Jul 22, 2025
60efe99
Merge branch 'main' of https://github.com/splashkit/the-programmers-f…
omckeon Jul 23, 2025
48b1227
Simplify binary calculator activity page (initial version) and rename…
omckeon Jul 23, 2025
83b30eb
Minor updates for binary converter activity
omckeon Jul 23, 2025
181cc85
Finalise Binary converter activity
omckeon Jul 23, 2025
a858a87
Update graffle file to match file in main
omckeon Jul 23, 2025
a33588d
Merge branch 'main' of https://github.com/splashkit/the-programmers-f…
omckeon Jul 23, 2025
ba731a6
Simplify and tidy up Part 0 pages to remove the excess chatGPT style …
omckeon Jul 23, 2025
1693eb0
Finalise GPIO guided tour activity
omckeon Jul 24, 2025
ff00f54
Merge branch 'main' of https://github.com/splashkit/the-programmers-f…
omckeon Jul 24, 2025
7fbdae9
Update to include "digital" in P1C1 GPIO guided activity
omckeon Jul 24, 2025
59b4c30
Remove additional files from part 1
omckeon Jul 24, 2025
2c179f3
Remove missed file
omckeon Jul 24, 2025
7a6f66a
Remove unused blink led gif
omckeon Jul 24, 2025
6e2a3b5
Fix image to actually be png file
omckeon Jul 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Raspberry Pi!
sidebar:
attrs:
class: pi
---

The Raspberry Pi is an affordable, yet surprisingly powerful, "pocket-sized" computer designed to help you explore coding, electronics, and digital systems.

![Raspberry Pi](./images/raspberrypi.png)
<div class="caption">Image from <a href="https://learn.littlebirdelectronics.com.au/guides/getting-started-with-the-raspberry-pi-4">Little Bird Electronics</a></div>

Despite its small size, the Raspberry Pi is a **fully functional computer** capable of running a Linux-based operating system, such as Raspberry Pi OS (a variant of Debian). This means you get the full experience of coding with a Unix system, combined with the fun of interacting with physical hardware components such as LEDs, buttons, joystick modules and more!

:::note

The Raspberry Pi is not required to learn the coding concepts covered in this book, but with it, you'll get some unique learning opportunities:

- **Hands-On Fun:** You get to see the results of your code come alive — lighting up LEDs, moving motors, or even playing sounds!
- **Explore Embedded Systems:** Discover how code interacts with real-life gadgets and electronics and gain more understanding of how software and hardware can work together.
- **Creative Exploration:** Tinker with sensors, buttons, and displays to create fun projects such as controlling the LEDs on a 7-segment display using inputs from a sensor or your code commands.
- **Easy to Start:** Even if you’re new to programming, the Raspberry Pi offers a gentle introduction with plenty of support when you get stuck.

:::

:::tip[Official Documentation]

The official **[Raspberry Pi Documentation](https://www.raspberrypi.com/documentation/)** includes a variety of useful guides, such as setting up your Raspberry Pi, configuring settings, accessing your Pi remotely, and much more.

:::
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Use Your Raspberry Pi
sidebar:
attrs:
class: pi
---

Inside the [Raspberry Pi](/book/part-0-getting-started/2-computer-use/0-panorama/05-raspberry-pi), it has a CPU (the brain), RAM (its short-term memory), and various ports like HDMI and USB.

But the real magic happens with its GPIO pins!

## Understanding the GPIO Pins

![Raspberry Pi 40-pin header](https://www.raspberrypi.com/documentation/computers/images/GPIO-Pinout-Diagram-2.png)
<div class="caption">Image © Raspberry Pi Ltd, licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> (CC BY-SA)</div>

The **General Purpose Input/Output (GPIO)** pins give you a physical interface between your Raspberry Pi and external hardware components. Here’s how you can use them:

- **Input Mode:**
You can attach sensors (temperature and light sensors) or other input devices such as a joystick, to the pins to allow the Raspberry Pi to read signals from these sensors to understand its environment, or control a player in a game.

- **Output Mode:**
Connect LEDs, motors, buzzers, and more! With a bit of code, you can make an LED blink, a motor spin, or even create sound effects.

- **Digital and PWM Signals:**
Some pins work in a digital on/off mode (perfect for simple tasks), while others support Pulse Width Modulation (PWM), which lets you control the speed of a motor or the brightness of an LED by varying the power output.

With the GPIO pins as your bridge between software and hardware, you can build exciting programs that respond to real-world events!

<!-- Note: The line below is left out for now, but can be added back in eventually once motors and more sensors have been included in activities. -->
<!-- By the end of this book, you could even build a robot that can navigate and react to its surroundings, using motors and sensors. -->

:::note[Getting Started: Set up Your Raspberry Pi]

Before you start exploring the Raspberry Pi activities in this book, you will need to get your Raspberry Pi up and running. We have step-by-step guides for this:

- [Set up my Raspberry Pi](/book/appendix/0-installation/2-3-setup-pi/)

This page includes instructions for setting up the Raspberry Pi OS (including downloading the OS, installing it on your microSD card, and initial configuration) as well as installing the software tools you will need.

*You can skip to [3. Set up Raspberry Pi OS](/book/appendix/0-installation/2-3-setup-pi/#3-setup-raspberry-pi-os) if you have already done the initial OS installation.*

- [Build my Raspberry Pi](/book/appendix/0-installation/2-2-pi-computer)

This page includes information about the Raspberry Pi hardware as well as optional instructions to help you build a small portable setup.

:::

:::tip

*Take your time during setup* and don’t be afraid to explore! Every step (or misstep) is a learning opportunity that will build up your skills and understanding.

:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
---
title: Hello LED Blinking
sidebar:
attrs:
class: pi
---

import { Accordion, AccordionItem } from 'accessible-astro-components'
import { Steps } from "@astrojs/starlight/components";

Welcome to our fun, step-by-step guide on how to blink a physical LED using SplashKit on your Raspberry Pi! In this tutorial, you'll learn how to set up your hardware, write simple code to turn your LED on and off multiple times, as well as how to run your project. Get ready to see your LED come to life!

## Hardware Setup

### Components

To build the simple LED circuit shown below (in real life), here's what you need:

- **LED:** Can be any color.
*Remember: the longer leg is the anode (+), the shorter is the cathode (-).*
- **220 Ω Resistor:** This protects the LED by limiting the current.
- **Breadboard and Jumper Wires:** For making temporary connections.
- **Raspberry Pi:** With a GPIO pin (we'll use GPIO Pin 11) and a Ground (GND) pin.

:::note[Just getting started with circuits?]

These sections include links with more information about the circuit components:

<details>
<summary>LEDs and Resistors:</summary>

- [LEDs (Introduction to Raspberry Pi Pico guide)](https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/7)
- [Resistors (Introduction to Raspberry Pi Pico guide)](https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/6)
- [Resistors for LED Circuits](https://eepower.com/resistor-guide/resistor-applications/resistor-for-led/)

</details>
<details>
<summary>Breadboards and Jumper Wires:</summary>

- [How to Use a Breadboard for Electronics and Circuits](https://www.sciencebuddies.org/science-fair-projects/references/how-to-use-a-breadboard)
- [What is inside a breadboard?](https://www.sciencebuddies.org/science-fair-projects/references/how-to-use-a-breadboard#inside-breadboard)
- [How are the holes connected?](https://www.sciencebuddies.org/science-fair-projects/references/how-to-use-a-breadboard#holes)
- [What is a breadboard diagram?](https://www.sciencebuddies.org/science-fair-projects/references/how-to-use-a-breadboard#breadboard-diagram)
- [What are jumper wires and what kind should I use?](https://www.sciencebuddies.org/science-fair-projects/references/how-to-use-a-breadboard#jumper-wires)

</details>
:::

### Wiring Instructions

![Led Blink Circuit](./images/blinkledcircuit.png)
<div class="caption">Image created with <a href="https://fritzing.org/">Fritzing</a></div>

<Steps>

1. **Put the LED and resistor onto the breadboard:**

Place the resistor across the center channel of the breadboard, or across any two separate rows.

Then place the LED across two rows (as shown in the breadboard diagram above), with the cathode (short leg) on the same row as one end of the resistor.

2. **Attach the ground wire:**

Attach a jumper wire from the other end of the resistor to a GND pin.
*(This is the black wire connected to pin 6 in the diagram above.)*

3. **Connect the LED to the GPIO Pin:**

Attach a jumper wire from the LED’s anode (long leg) to GPIO Pin 11.
*(This is the blue wire connected to pin 11 in the diagram above.)*

</Steps>

:::caution[Safety Note:]
Always double-check your connections and ground yourself before handling the circuit to avoid static discharge or accidental damage.
:::

## Software Setup

To set up the software side of this project, you can follow the steps below:

<Steps>

1. ### Create a new C# project

Open your terminal and create a new C# console project:

```shell
mkdir LedBlink
cd LedBlink
dotnet new console
dotnet add package SplashKit
code .
```

2. ### Write the code

Copy the code below, then replace the contents of your `Program.cs` file with this code:

```csharp
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Initialise the GPIO system
RaspiInit();

// Define the LED pin (using physical Pin 11)
GpioPin ledPin = GpioPin.Pin11;

// Set the LED pin to output mode
RaspiSetMode(ledPin, GpioPinMode.GpioOutput);

// Blink 1: Turn LED ON, wait, then OFF
RaspiWrite(ledPin, GpioPinValue.GpioHigh);
Delay(500); // LED ON for 500 ms
RaspiWrite(ledPin, GpioPinValue.GpioLow);
Delay(500); // LED OFF for 500 ms

// Blink 2: Turn LED ON, wait, then OFF
RaspiWrite(ledPin, GpioPinValue.GpioHigh);
Delay(500);
RaspiWrite(ledPin, GpioPinValue.GpioLow);
Delay(500);

// Blink 3: Turn LED ON, wait, then OFF
RaspiWrite(ledPin, GpioPinValue.GpioHigh);
Delay(500);
RaspiWrite(ledPin, GpioPinValue.GpioLow);
Delay(500);

// Clean up the GPIO system
RaspiCleanup();
```

:::note
You will learn more about SplashKit's Raspberry Pi code in Part 1, but for now you can just copy/paste this code without needing to know the details just yet.
:::

3. ### Start the "pigpiod" Daemon

Underneath SplashKit we use the [Pigpio library](https://abyz.me.uk/rpi/pigpio), specifically its
daemon. To interface with this daemon, it must be running.

:::tip[Daemons]
A daemon is a background process that runs continuously, waiting for requests to
perform some action. In this case, the daemon is waiting for requests to change the state of the
GPIO pins. This allows us to run multiple programs that interact with the GPIO pins.
:::

To start the `pigpiod` daemon, run the following command:

```shell
sudo pigpiod
```

To stop the daemon from running, you can use the command:

```shell
sudo killall pigpiod
```

:::note[Pigpiod Error Message]

If the `pigpiod` daemon is not running, you will the following error message in your terminal:

```shell
ERROR [default] Pigpio error: bad connect.
```

:::

4. ### Build and run the project

Use the following command to build and run the program:

```shell
dotnet run
```

</Steps>

## Expected Outcome

When you run the program, your physical LED connected to GPIO Pin 11 should blink on and off three times. Each "on" state lasts for 500 milliseconds followed by an "off" state for 500 milliseconds. Once the sequence is complete, the program cleans up the GPIO settings and exits.

![Led Blinking](./images/LedBlinkSlow.gif)

Enjoy watching your LED blink and have fun tinkering with your Raspberry Pi projects!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.