Difference between revisions of "Raspberry Pi and Basic Electronics"

From csn
Jump to navigation Jump to search
m (Reverted edits by Seit (talk) to last revision by David)
Tag: Rollback
 
(63 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
The purpose of this lab is to introduce you to some very basic electronics and how we can integrate the Raspberry Pi. Please view this as a taster of a much larger area. The assumption is that you have already completed [[Install Raspbian get connected and basic networking]].
 
The purpose of this lab is to introduce you to some very basic electronics and how we can integrate the Raspberry Pi. Please view this as a taster of a much larger area. The assumption is that you have already completed [[Install Raspbian get connected and basic networking]].
  
== Turning on an LED ==
+
Note that while wiring up the Raspberry Pi. Please make sure you switch it off to reduce the possibility of you shorting anything out.
  
So in this first activity, I will show you how you can use Python code to turn on an LED in a Raspberry Pi. Start by watching the following video on breadboards: https://www.youtube.com/watch?v=fq6U5Y14oM4
+
[[File:RPI3_Pinout.png|right|thumb|x400px|alt=A Raspberry Pi 3 Pinout|A Raspberry Pi 3 Pinout]]
  
So first we will do the wiring: carefully inspect the pinout of the Raspberry Pi below. This is the Pinout for the Raspberry Pi 3.
+
== Getting the packages ==
  
[[File:RPI3_Pinout.png|centre|thumb|x400px|alt=A Raspberry Pi 3 Pinout|A Raspberry Pi 3 Pinout]]
+
To get started, it is important that we have the Python packages that will allow us to manipulate the pins on the Raspberry Pi. For future-proofing, are standardizing all code on Python 3. So to complete this lab, you will need to install some packages:
  
 +
sudo apt update
  
 +
Then
  
 +
sudo apt install python3-pip
  
 +
After this:
  
==== The Python3 code ===
+
sudo apt install python3-rpi.gpio
  
<pre>
+
== Turning on an LED ==
#!/usr/bin/python3
 
  
import RPi.GPIO
+
So in this first activity, I will show you how you can use Python code to turn on an LED in a Raspberry Pi. Start by watching the following video on breadboards: https://www.youtube.com/watch?v=fq6U5Y14oM4. First, we will do the wiring: carefully inspect the pinout of the Raspberry Pi below. This is the Pinout for the Raspberry Pi 3.  
import time
 
  
GPIO.setmode(GPIO.BCM)
 
GPIO.setwarnings(False)
 
GPIO.setup(18,GPIO.OUT)
 
  
print("LED on")
+
Pick out one of your LEDs. Note that one side is longer than then other. The longer side is positive (red) and the shorter side is negative (black).
GPIO.output(18,GPIO.HIGH)
 
time.sleep(2)
 
print("LED off")
 
GPIO.output(18,GPIO.LOW)
 
</pre>
 
  
== Wiring up the Pi and LEDs ==
+
[[File:LEDposnev.png|right|thumb|x100px|alt=LED Diagram https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity|Raspberry Pi Header: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity]]
  
In the code above we have set the script to use GPIO port 26 (37) and then use any ground port of the Raspberry Pi in our example, we will use port 38.
+
=== Physical wiring ===
  
The code above will turn on the port when 1 is written and turn off the LED when 0 is written.
+
With this in mind, I want you to use a black, female to male, wire to connect from the ground Pin 6 on the Raspberry Pi, to the negative line attached to the shorter side of the LED.
  
 +
Now I want you to get a resistor and run the resistor from the positive line of the LED to a separate line I then want you to connect the circuit by running a red, female to male connection between the Raspberry Pi's GPIO 18 pin to join with this resistor.
  
[[File:GPIOHeaders.jpg|center|thumb|x400px|alt=Raspberry Pi Header https://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/|Raspberry Pi Header: https://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/]]
+
It may be better to try to copy the diagram below and then re-read the steps above for understanding.
  
Connect these header pins to a breadboard with jumper wires.
+
[[File:LEDwiring.png|right|thumb|x450px|alt=LED wiring | LED wiring]]
Then connect the LED to the breadboard ensuring that the polarity of the LED is correct.
 
LEDs have to be connected in the correct way, the longer lead is the positive side and the shorter lead is the negative side.
 
  
[[File:LEDposnev.png|center|thumb|x200px|alt=LED Diagram https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity|Raspberry Pi Header: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity]]
+
=== The Python3 code ===
  
 +
Now we will write the code to turn on the GPIO 18 Pin to switch on the light.
  
Now run the script again and connect using nRF connect and see if the LEDs will now turn on and off.
+
Open your favourite text editor on the Raspberry Pi:
  
  sudo python3 LEDscript.py
+
  nano led_light.py
  
 +
Then insert the following code.
  
The wiring should resemble one of the diagrams below. Note that there is one output from the MOSFET to the fan and there are two inputs into the MOSFET from the Raspberry Pi. The reason is that the GPIO pins are not capable of producing the amount of current for turning the fan. A MOSFET is an electronic gate. We can use the GPIO Pin to turn the device on and off, while the power source may come from something external. If required we could turn a 240V circuit on and off in this manner.
+
<pre>#!/usr/bin/python3
  
[[File:wiring_pi123.png|centre|thumb|x400px|alt=How to wire the Raspberry Pi and mount the fan, Fan and MOSFET|How to wire the Raspberry Pi, Fan and a commercial MOSFET ]]
+
import RPi.GPIO as GPIO
 +
import time
  
If it is difficult to see the pins on the raspberry pi that is in use then you may refer to the diagram below.
+
GPIO.setmode(GPIO.BCM)
 +
GPIO.setwarnings(False)
 +
GPIO.setup(18,GPIO.OUT)
  
[[File:pins_in_use123.png|centre|thumb|x200px|alt=Pins in use|Pins in use]]
+
print("LED on")
 +
GPIO.output(18,GPIO.HIGH)
 +
time.sleep(2)
 +
print("LED off")
 +
GPIO.output(18,GPIO.LOW)
 +
</pre>
  
Feel free to ask your instructor to check your cabling before moving on. Once you think your cabling is correct, you can attach the fan to the raspberry pi using the plastic standoff.
+
[[File:traffic_lights.jpeg|right|thumb|x500px|alt=Traffic Light System | Traffic light system]]
  
== Basic code to operate the fan ==
+
==== Challenge ====
  
Open up a text file, by clicking on the raspberry symbol in the top left, going to accessories,and slecting the ''text editor''. Paste in or type the following code. Name the file fan.py and save it in the folder called pi.
+
You should have a pack of LED lights and resistors. Can you write code to implement a basic traffic light system? As a further task can you read about the breadboard's rails (see: https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard/all) and then minimise the wiring to make this traffic light system work.
  
import RPi.GPIO as GPIO
+
Save the code and then run it with:
import time
 
GPIO.setmode(GPIO.BCM)
 
GPIO.setwarnings(False)
 
GPIO.setup(17,GPIO.OUT)
 
print "Fan on"
 
GPIO.output(17,GPIO.HIGH)
 
time.sleep(1)
 
print "Fan off"
 
GPIO.output(17,GPIO.LOW)
 
  
To run this program, you will need to open a terminal. Click on the black box at the top of the screen with a >_
+
python3 led_light.py
  
You can then run the code in the terminal with the command:
+
Make sure that your code loops infinitely through the traffic lights by using a while loop.
  
python fan.py
+
== Inputs that cause outputs ==
  
If the fan does not turn, double check your cabling and ensure that the battery pack is switched on.
+
In this next section, we will get use the existing lighting system but we rather than a simple traffic light, we will use lights to represent the varying temperatures of the CPU.  
 
 
Can you modify this code so that the fan will turn on for 60 seconds?
 
 
 
== Controlling the fan based on environmental conditions ==
 
  
 
We would like the operation of the fan to turn on to cool the CPU on your mini computer. The following command will show you the current temperature of your CPU
 
We would like the operation of the fan to turn on to cool the CPU on your mini computer. The following command will show you the current temperature of your CPU
Line 94: Line 84:
 
  /opt/vc/bin/vcgencmd measure_temp
 
  /opt/vc/bin/vcgencmd measure_temp
  
Read the following code and see if you can work out what is going on. Open a new file, paste the code below and save it as cooling_system.py
+
For me this reports:
 +
 
 +
temp=32.0'C
  
 +
But the value will vary. What we want to do is get this value 32 into your python code.
 
<pre>
 
<pre>
 +
#!/usr/bin/python3
 +
 
import RPi.GPIO as GPIO
 
import RPi.GPIO as GPIO
 
import time
 
import time
Line 106: Line 101:
 
GPIO.setmode(GPIO.BCM)
 
GPIO.setmode(GPIO.BCM)
 
GPIO.setwarnings(False)
 
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
+
GPIO.setup(18,GPIO.OUT)
print "Fan test"
+
GPIO.setup(24,GPIO.OUT)
GPIO.output(17,GPIO.HIGH)
+
 
 +
print("LED test")
 +
GPIO.output(18,GPIO.HIGH)
 +
GPIO.output(24,GPIO.HIGH)
 
time.sleep(1)
 
time.sleep(1)
print "Fan test complete switching off"
+
GPIO.output(18,GPIO.LOW)
GPIO.output(17,GPIO.LOW)
+
GPIO.output(24,GPIO.LOW)
 +
print("LED test done")
 +
 
 +
try:
 +
    while True:
  
temp = os.popen('vcgencmd measure_temp').readline()
+
        temp = os.popen('vcgencmd measure_temp').readline()
print temp
+
        print(temp)
temp= temp.replace("temp=","").replace("'C\n","")
+
        temp= temp.replace("temp=","").replace("'C\n","")
print temp
+
        print(temp)
  
while True:
+
        if float(temp) > 40:
    temp = os.popen('vcgencmd measure_temp').readline()
+
            print("Temperature over 40C Warning LED on")
    print temp
+
            GPIO.output(24,GPIO.HIGH)
    temp= temp.replace("temp=","").replace("'C\n","")
+
            time.sleep(2)
    print temp
+
            GPIO.output(24,GPIO.LOW)
    if float(temp) > 40:
+
       
        print "Temperature over 40C fan on"
+
        else:
        GPIO.output(17,GPIO.HIGH)
+
            print("Temperature below 40C System Normal LED on")
        time.sleep(2)
+
            GPIO.output(18,GPIO.HIGH)
        print "Fan off"
+
            time.sleep(2)
        GPIO.output(17,GPIO.LOW)
+
            GPIO.output(18,GPIO.LOW)
    else:
+
finally:
        print "Temperature below 40C fan off"
+
    GPIO.output(18,GPIO.LOW)
        GPIO.output(17,GPIO.LOW)
+
    GPIO.output(24,GPIO.LOW)
        time.sleep(2)
 
 
</pre>
 
</pre>
  
 
Run the code, in a terminal with:
 
Run the code, in a terminal with:
  
  python cooling_system.py
+
  python temperature_monitoring.py
  
 
=== Generating CPU load ===
 
=== Generating CPU load ===
Line 144: Line 145:
  
 
<pre>
 
<pre>
 +
#!/usr/bin/python3
 +
 
n = 100000
 
n = 100000
 
p = 2
 
p = 2
Line 152: Line 155:
 
             break
 
             break
 
     else:
 
     else:
         print p,
+
         print(p),
print 'Done'
+
print("Done")
 
</pre>
 
</pre>
  
Line 160: Line 163:
 
  python primes.py
 
  python primes.py
  
You should run it in a separate window, and you should be able to watch the temperature of the CPU increasing. You can stop the program with Ctrl+c, and the temperature should drop.
+
You should run it in a separate window. To do this you could use tmux or a second ssh session. You should be able to watch the temperature of the CPU increasing. You can stop the program with Ctrl+c, and the temperature should drop.
 +
 
 +
=== Challenge ===
 +
 
 +
Modify the code and the wiring so that there are three levels and three different colours that will be displayed, so work out the code and the circuit for low, medium and high temperatures.
 +
 
 +
== Using the Fan ==
 +
 
 +
=== Trying to power through GPIO ===
 +
 
 +
Let's start by plugging your fan straight into your Raspberry Pi, Joining the black wire to the ground (pin 9) shown in diagram Xyz and the red wire to GPIO 17 as shown in the same diagram. Refer to the picture of my cabling as well.
 +
 
 +
[[File:pins_in_use123.png|centre|thumb|x200px|alt=Pins in use to power fan through GPIO| Pins in use to power fan through GPIO]]
 +
 
 +
[[File:Attempt_to_power_through_GPIO.jpeg|centre|thumb|x500px|alt=My cabled fan to power fan through GPIO| To power fan through GPIO]]
 +
 
 +
Then, use the code below to try to run the fan.
 +
 
 +
<pre>
 +
#!/usr/bin/python3
 +
 
 +
import RPi.GPIO as GPIO
 +
import time
 +
 
 +
GPIO.setmode(GPIO.BCM)
 +
GPIO.setwarnings(False)
 +
GPIO.setup(17,GPIO.OUT)
 +
print("Fan on")
 +
GPIO.output(17,GPIO.HIGH)
 +
time.sleep(1)
 +
print("Fan off")
 +
GPIO.output(17,GPIO.LOW)
 +
</pre>
 +
 
 +
This should not work. Why? Because the maximum power draw from a GPIO pin is 16 mA.
 +
 
 +
=== Trying to power through the 5v ===
 +
 
 +
We can, however, power straight through the 5V Pin. Plug your fan straight into the 5V and GND as shown in the picture below.
 +
 
 +
[[File:pins_in_use5v.png|centre|thumb|x200px|alt=Pins in use to power fan through 5v| Pins in use to power fan through 5v]]
 +
 
 +
[[File:Attempt_to_power_through_5v.jpeg|centre|thumb|x500px|alt=Powering the fan directly through 5v| Powering fan directly through 5v]]
 +
 
 +
So note that this works, and we didn't even need any code. The problem is that we have no capacity to control this. This 5V pin is continuous, it is the power that is coming over the USB into the Raspberry Pi, but we cannot switch it on and off. For most electronics that have a reasonable power draw, we would like the ability to turn it on and off.
 +
 
 +
=== Using a MOSFET ===
 +
 
 +
MOSFETS provide us with the capacity to switch on and off a power source. In this activity, we will draw the power from the 5v Raspberry power supply that we just used but for practical purposes, we could have been drawing the power from 12 or 48 volts or more and just using the GPIOs as a switch.
 +
 
 +
The code we will use is the same as above:
 +
<pre>
 +
#!/usr/bin/python3
 +
 
 +
import RPi.GPIO as GPIO
 +
import time
 +
 
 +
GPIO.setmode(GPIO.BCM)
 +
GPIO.setwarnings(False)
 +
GPIO.setup(17,GPIO.OUT)
 +
print("Fan on")
 +
GPIO.output(17,GPIO.HIGH)
 +
time.sleep(1)
 +
print("Fan off")
 +
GPIO.output(17,GPIO.LOW)
 +
</pre>
 +
 
 +
Turn your Raspberry Pi off and cable according to the images below.
 +
 
 +
[[File:pins_in_use_for_mosfet.png|centre|thumb|x200px|alt=Pins in use to power fan through MOSFET| Pins in use to power fan through MOSFET]]
 +
 
 +
[[File:Attempt_to_power_through_MOSFET.jpeg|centre|thumb|x500px|alt=My cabled fan to power fan through MOSFET| To power fan through MOSFET]]
 +
 
 +
Make sure that your MOSFET and Raspberry Pi is cabled correctly and that you can switch it on and off using the code above before moving on.
 +
 
 +
== Pulling it all together ==
 +
 
 +
I would like you to combine all of the activities to create a thermal management and notification scheme for your Raspberry Pi. I would like you to combine the code and electronics that you have been shown to create a system that will provide a visual warning of the CPU temperature. In addition, there will also be a feedback look where we will selectively switch on the fan as well at certain temperature thresholds. For extra credit, you can pulse the fan on and off at mid-temperature ranges.
 +
 
 +
[[File:Final_RPi_Cooling.jpeg|centre|thumb|x500px|alt=My final RPi Cooling solution|My final RPi Cooling solution]]
 +
 
 +
Have a careful look at my very makeshift fan holder and electronics wiring. You may be able to do better or just sit the fan on the desk so it blows across the CPU. Use the prime number calculating code provided earlier to generate CPU load.
 +
 
 +
Watch the fan flick on, cool the CPU down and then power off.

Latest revision as of 02:12, 5 October 2022

The purpose of this lab is to introduce you to some very basic electronics and how we can integrate the Raspberry Pi. Please view this as a taster of a much larger area. The assumption is that you have already completed Install Raspbian get connected and basic networking.

Note that while wiring up the Raspberry Pi. Please make sure you switch it off to reduce the possibility of you shorting anything out.

A Raspberry Pi 3 Pinout
A Raspberry Pi 3 Pinout

Getting the packages

To get started, it is important that we have the Python packages that will allow us to manipulate the pins on the Raspberry Pi. For future-proofing, are standardizing all code on Python 3. So to complete this lab, you will need to install some packages:

sudo apt update

Then

sudo apt install python3-pip

After this:

sudo apt install python3-rpi.gpio

Turning on an LED

So in this first activity, I will show you how you can use Python code to turn on an LED in a Raspberry Pi. Start by watching the following video on breadboards: https://www.youtube.com/watch?v=fq6U5Y14oM4. First, we will do the wiring: carefully inspect the pinout of the Raspberry Pi below. This is the Pinout for the Raspberry Pi 3.


Pick out one of your LEDs. Note that one side is longer than then other. The longer side is positive (red) and the shorter side is negative (black).

Physical wiring

With this in mind, I want you to use a black, female to male, wire to connect from the ground Pin 6 on the Raspberry Pi, to the negative line attached to the shorter side of the LED.

Now I want you to get a resistor and run the resistor from the positive line of the LED to a separate line I then want you to connect the circuit by running a red, female to male connection between the Raspberry Pi's GPIO 18 pin to join with this resistor.

It may be better to try to copy the diagram below and then re-read the steps above for understanding.

LED wiring
LED wiring

The Python3 code

Now we will write the code to turn on the GPIO 18 Pin to switch on the light.

Open your favourite text editor on the Raspberry Pi:

nano led_light.py

Then insert the following code.

#!/usr/bin/python3

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)

print("LED on")
GPIO.output(18,GPIO.HIGH)
time.sleep(2)
print("LED off")
GPIO.output(18,GPIO.LOW)
Traffic Light System
Traffic light system

Challenge

You should have a pack of LED lights and resistors. Can you write code to implement a basic traffic light system? As a further task can you read about the breadboard's rails (see: https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard/all) and then minimise the wiring to make this traffic light system work.

Save the code and then run it with:

python3 led_light.py

Make sure that your code loops infinitely through the traffic lights by using a while loop.

Inputs that cause outputs

In this next section, we will get use the existing lighting system but we rather than a simple traffic light, we will use lights to represent the varying temperatures of the CPU.

We would like the operation of the fan to turn on to cool the CPU on your mini computer. The following command will show you the current temperature of your CPU

/opt/vc/bin/vcgencmd measure_temp

For me this reports:

temp=32.0'C

But the value will vary. What we want to do is get this value 32 into your python code.

#!/usr/bin/python3

import RPi.GPIO as GPIO
import time
import os
import sys
import signal
import subprocess

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)

print("LED test")
GPIO.output(18,GPIO.HIGH)
GPIO.output(24,GPIO.HIGH)
time.sleep(1)
GPIO.output(18,GPIO.LOW)
GPIO.output(24,GPIO.LOW)
print("LED test done")

try: 
    while True:

        temp = os.popen('vcgencmd measure_temp').readline()
        print(temp)
        temp= temp.replace("temp=","").replace("'C\n","")
        print(temp)

        if  float(temp) > 40:
            print("Temperature over 40C Warning LED on")
            GPIO.output(24,GPIO.HIGH)
            time.sleep(2)
            GPIO.output(24,GPIO.LOW)
        
        else:
            print("Temperature below 40C System Normal LED on")
            GPIO.output(18,GPIO.HIGH)
            time.sleep(2)
            GPIO.output(18,GPIO.LOW)
finally:
    GPIO.output(18,GPIO.LOW)
    GPIO.output(24,GPIO.LOW)

Run the code, in a terminal with:

python temperature_monitoring.py

Generating CPU load

We want to generate load on the CPU; paste the following code into a new text file.

#!/usr/bin/python3

n = 100000
p = 2

for p in range(2, n+1):
    for i in range(2, p):
        if p % i == 0:
            break
    else:
        print(p),
print("Done")

Same as before save it. You can call this primes.py as it will calculate all the prime numbers between 2 and 100,000. As before ensure it has execute permissions then run it with:

python primes.py

You should run it in a separate window. To do this you could use tmux or a second ssh session. You should be able to watch the temperature of the CPU increasing. You can stop the program with Ctrl+c, and the temperature should drop.

Challenge

Modify the code and the wiring so that there are three levels and three different colours that will be displayed, so work out the code and the circuit for low, medium and high temperatures.

Using the Fan

Trying to power through GPIO

Let's start by plugging your fan straight into your Raspberry Pi, Joining the black wire to the ground (pin 9) shown in diagram Xyz and the red wire to GPIO 17 as shown in the same diagram. Refer to the picture of my cabling as well.

Pins in use to power fan through GPIO
Pins in use to power fan through GPIO
My cabled fan to power fan through GPIO
To power fan through GPIO

Then, use the code below to try to run the fan.

#!/usr/bin/python3

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
print("Fan on")
GPIO.output(17,GPIO.HIGH)
time.sleep(1)
print("Fan off")
GPIO.output(17,GPIO.LOW)

This should not work. Why? Because the maximum power draw from a GPIO pin is 16 mA.

Trying to power through the 5v

We can, however, power straight through the 5V Pin. Plug your fan straight into the 5V and GND as shown in the picture below.

Pins in use to power fan through 5v
Pins in use to power fan through 5v
Powering the fan directly through 5v
Powering fan directly through 5v

So note that this works, and we didn't even need any code. The problem is that we have no capacity to control this. This 5V pin is continuous, it is the power that is coming over the USB into the Raspberry Pi, but we cannot switch it on and off. For most electronics that have a reasonable power draw, we would like the ability to turn it on and off.

Using a MOSFET

MOSFETS provide us with the capacity to switch on and off a power source. In this activity, we will draw the power from the 5v Raspberry power supply that we just used but for practical purposes, we could have been drawing the power from 12 or 48 volts or more and just using the GPIOs as a switch.

The code we will use is the same as above:

#!/usr/bin/python3

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
print("Fan on")
GPIO.output(17,GPIO.HIGH)
time.sleep(1)
print("Fan off")
GPIO.output(17,GPIO.LOW)

Turn your Raspberry Pi off and cable according to the images below.

Pins in use to power fan through MOSFET
Pins in use to power fan through MOSFET
My cabled fan to power fan through MOSFET
To power fan through MOSFET

Make sure that your MOSFET and Raspberry Pi is cabled correctly and that you can switch it on and off using the code above before moving on.

Pulling it all together

I would like you to combine all of the activities to create a thermal management and notification scheme for your Raspberry Pi. I would like you to combine the code and electronics that you have been shown to create a system that will provide a visual warning of the CPU temperature. In addition, there will also be a feedback look where we will selectively switch on the fan as well at certain temperature thresholds. For extra credit, you can pulse the fan on and off at mid-temperature ranges.

My final RPi Cooling solution
My final RPi Cooling solution

Have a careful look at my very makeshift fan holder and electronics wiring. You may be able to do better or just sit the fan on the desk so it blows across the CPU. Use the prime number calculating code provided earlier to generate CPU load.

Watch the fan flick on, cool the CPU down and then power off.