Coding on your Raspberry Pi
Thonny
- The following section assumes that you have set up the operating system on your Raspberry Pi and are housing the GUI through VNC viewer.
- Now that we have an introductory understanding of coding with Python, we are going to start incorporating some electronics into it with the Raspberry Pi. Below are three coding projects, each with answers and extensions, if you would like to test yourself.
- For each of these, we will develop our code within Thonny. Thonny is a Python IDE (Integrated Development Environment) designed specifically for beginners with a simple debugger and an easy way to create new scripts.
- Below is a screenshot that highlights what the Thonny window looks like:

- Up here are the main options for the code we've written. We can (In order):
- Create a New blank File
- Open a File
- Save the current File
- Run the current File
- Run in Debug mode (The next 3 images relate to debugging mode which is basically manually going through the code to test at each step. Don't stress too much about these features as it is normally for larger projects and we will cover them later)
- Stop the current script, only works when the solution is running
- This section here is where we do our coding. Anything we write here will be executed when we press the green start button at the top of the screen
- This section is dedicated to our outputs. Anything we print in our code will appear down here. We can also write single lines of code here to be executed, such as “print(12*2)” which will print 24 below.
GPIO Pins
- For the following projects on the Raspberry Pi, we will primarily use the GPIO pins to attach all our inputs and outputs.
- GPIO stands for “General Purpose Input & Output” and is used for an assortment of external peripherals, from LEDs to buttons and ultrasonic sensors. Each pin has a specific purpose with the core ones being:
- 5v / 3.3v power - Provides either 5 or 3.3 voltage
- Ground - Provides a ground to a circuit (For reference a circuit must have a power source and a ground pin in order to form a current)
- GPIO pins - These are pins that we access in our code, while a 5v pin will always output 5v, we can set the current of these GPIO pins on and off using code. We can also receive Input on these pins, with certain pins being compatible with specific types of input/output. For example, we can transmit data (TXD) on GPIO 14 and receive data on GPIO 15 (RXD). These two are important for components such as ultrasonic sensors (view below).
- Below is a general map that shows how the pins are organised on our Raspberry Pi. Feel free to reference this image when doing wiring to ensure you get the correct setup.
