126.96.36.199 Packet Tracer – SBC Actuate With Python (Instructor Version)
Become proficient using Python to program Packet Tracer’s SBC device.
Background / Scenario
Python is wide-spread, robust and easy to programming language that runs on several different computer platforms. Packet Tracer 7.1 takes advantage of this and implements Python-supported IoT devices.
In this Packet Tracer activity you will program the Packet Tracer 7.1’s SBC device using Python. The goal is to allow a coffee maker to start brewing coffee when someone enters the kitchen (movement is detected). A countertop lamp will also turn on.
- Packet Tracer 7.1 or newer.
Part 1: Adding and Connecting the Necessary Devices
You will start with an empty work space. Add the following devices to Packet Tracer’s work space:
a. A SBC device can be found under Components >> Boards >> SBC-PT.
b. A Coffee Maker can be found under End Devices >> Home >>Appliance.
c. A Counter Top Lamp can be found under End Devices >> Home>> Light.
d. A Motion Sensor can be found under Components >> Sensors >> Motion Sensor
e. Change the names of the devices to match the diagram.
f. Using IoT Custom Cable, connect the devices to the PT-SBC board. The IoT Custom Cable can be found under Connections.
Use the following table to find the correct ports:
Part 2: Programming the SBC
The SBC mimics real-world single board computers such as the Raspberry Pi.
One of the advantages of SBC-PT is that it can be programmed with Python.
a. Click on the SBC and select the Programming tab.
Is there any code pre-loaded in the SBC?
The contents of the Programming tab are divided into two main parts. The left pane displays all the files containing the programs created by you. The right pane displays the contents of the file currently selected on the left portion. Click the New button above the left pane to create a new file. Name it main.py and select Empty – Python for the template type. Click Create. The left pane should now list your new file, main.py.
b. On the left pane, select main.py and click Open; the Open button is located immediately above the left pane. The right pane is now ready to receive the code for your main.py program.
c. Using the right pane, write a program to instruct the SBC to turn on the Coffee Maker and the Light when motion is detected by the Motion Detector.
Part 3: Testing
To test your code, first run the main.py by clicking Run. Then press the ALT key while moving the mouse over the Motion Sensor. This should signify movement to Packet Tracer which will be captured by the PTMotion Sensor. Once movement is detected, a HIGH digital signal is sent to the SBC which in turn, turns on the coffee maker and the light. Messages also appear in the console of the SBC.
Did the Coffee Maker turn on?
Did the light turn on?
What changes would have to be made in the SBC if the motion detector was moved to port D5?
What PT-SBC port, if any, should be used to connect an analog sensor?