... | ... | @@ -2,50 +2,183 @@ |
|
|
|
|
|
### Estimated Time: 1 Hour
|
|
|
|
|
|
_01-Some description of the lab and what they will learn_
|
|
|
# Micro::Bit Lock-Pick Activity
|
|
|
|
|
|
### Estimated Time: 1 Hour
|
|
|
|
|
|
# Table of Contents
|
|
|
* [Description](#description)
|
|
|
* [Skills Needed and Learned](#skills)
|
|
|
* [Materials](#materials)
|
|
|
* [Getting Familiar](#getting-familiar)
|
|
|
* [Setup](#setup)
|
|
|
* [Next Steps](#exploration)
|
|
|
|
|
|
### Step 0: The Basics
|
|
|
<p id="top"></p>
|
|
|
## Description
|
|
|
<p id="description"></p>
|
|
|
You are a secret agent tasked with recovering stolen information from a secure
|
|
|
lock box. But there's a problem, there is no physical key to the lock box. You
|
|
|
learn that the criminal uses a cryptographic electronic key to unlock this box
|
|
|
and sends that key over the radio. Your mission is to attempt to guess the secret
|
|
|
key and retrieve the information from the box. There will be 3 lock boxes with
|
|
|
progressively harder keys that you must discover. Through this process you will
|
|
|
discover how electronic keys work similar to many real-world situations
|
|
|
(i.e. office building key cards). This scenario is also designed to make you
|
|
|
think about radio signals and how their wireless nature lends to easy eavesdropping of information.
|
|
|
|
|
|
## Prerequisite Skills
|
|
|
<p id="skills"></p>
|
|
|
Some familiarity with either Make::Blocks or MicroPython languages for the MicroBit.
|
|
|
* Micro::Bit Coding Options
|
|
|
* [Click here to code with JavaScript/Blocks] (https://makecode.microbit.org)
|
|
|
* [Click here to code with MicroPython](https://python.microbit.org)
|
|
|
* Lock-Pick Basics
|
|
|
* _02-include some references here about lock picking that are short and sweet_
|
|
|
|
|
|
|
|
|
### Step 1: Gather Materials
|
|
|
* Micro::Bit (1 per person / 2 per team)
|
|
|
* Micro-USB Cable
|
|
|
* Battery Pack (Equivalent to two AA batteries)
|
|
|
* Lock-Pick Station
|
|
|
|
|
|
### Step 2: Get Familiar With Lock-Picks
|
|
|
_03-talk about the most important lock-pick concept they need to know about super concisely_
|
|
|
|
|
|
_04-include the most absolute most basic code example you can think of_
|
|
|
|
|
|
* [Click here for JavaScript/Blocks Web IDE] (https://makecode.microbit.org)
|
|
|
* [Click here for MicroPython Web IDE](https://python.microbit.org)
|
|
|
|
|
|
## Learned Skills
|
|
|
* Servo Motor Basics
|
|
|
* [Click here for information on servo motors](https://learn.adafruit.com/adafruit-motor-selection-guide/rc-servos)
|
|
|
* [Click here for Micro::Bit servo basics](https://makecode.microbit.org/reference/pins#servos)
|
|
|
|
|
|
* Radio Signal Basics
|
|
|
* [Click here for information on radio signals](https://www.infoplease.com/encyclopedia/science-and-technology/computers-and-electrical-engineering/electrical-engineering/radio/transmission-and-reception-of-radio-waves)
|
|
|
* [Click here for Micro::Bit radio basics](https://makecode.microbit.org/reference/radio)
|
|
|
[[top](#top)]--[[up](#description)]
|
|
|
|
|
|
### Step 3: Download The Files
|
|
|
* Download (click on) the following file to get started: _05-include directory here (called LockPickLab.zip_
|
|
|
## Materials
|
|
|
<p id="materials"></p>
|
|
|
* One "super secure" lock box
|
|
|
* One MicroBit "key"
|
|
|
|
|
|
* Unzip LockPickLab.zip (right click on the LockPickLab.zip and select "extract all". Then, just pick where you want to save your copy of these files). Notice there are three folders/directories in LockPickLab:
|
|
|
* **HexFiles**: This folder/directory holds all of the .hex files, or files that are ready to be run on a Micro::Bit.
|
|
|
* **JavaScript**: This folder/directory holds all of the JavaScript code for the labs. This includes base code and completed code. The base code is code that you can start with instead of creating new projects from scratch. Completed code is code that members of the CEDAR lab completed that you can look at if you get stuck.
|
|
|
* **Python**: This folder/directory holds all of the Python code for the labs. This also includes base code and completed code.
|
|
|
## Getting Familiar
|
|
|
<p id="getting-familiar"></p>
|
|
|
We are going to be using two components of the MicroBit for this activity, the radio and the servo motor controlling capabilities of the MotoBit extension board. Click on the links below to see a short piece of example code related to these two components in both MicroPython and Javascript/Blocks.
|
|
|
|
|
|
![files_new](/uploads/db7d5badc4c093fab35c294881ace7e4/files_new.PNG)
|
|
|
<details>
|
|
|
<summary>
|
|
|
<a>Control Servo(Javascript)</a>
|
|
|
</summary>
|
|
|
<img src="/uploads/4160109e7227309a7f24af1b79e1143b/Screen_Shot_2018-06-28_at_10.23.21_AM.png"/>
|
|
|
</details>
|
|
|
|
|
|
### Step 4: Open your editor.
|
|
|
* For JavaScript/Blocks, you will use the Micro::Bit online editor: [MakeCode](https://makecode.microbit.org/). Here, you can switch back and forth between JavaScript and Blocks by clicking on the button/slider in the top center of the screen.
|
|
|
<details>
|
|
|
<summary>
|
|
|
<a>Control Servo(MicroPython)</a>
|
|
|
</summary>
|
|
|
<pre>
|
|
|
from microbit import *
|
|
|
|
|
|
![blocks](/uploads/7061a5064100caa0790c714bdb1182c1/blocks.PNG)
|
|
|
# Helper class provided by the helpful folks at microbit-playground
|
|
|
class Servo:
|
|
|
|
|
|
"""
|
|
|
A simple class for controlling hobby servos.
|
|
|
Args:
|
|
|
pin (pin0 .. pin3): The pin where servo is connected.
|
|
|
freq (int): The frequency of the signal, in hertz.
|
|
|
min_us (int): The minimum signal length supported by the servo.
|
|
|
max_us (int): The maximum signal length supported by the servo.
|
|
|
angle (int): The angle between minimum and maximum positions.
|
|
|
Usage:
|
|
|
SG90 @ 3.3v servo connected to pin0
|
|
|
= Servo(pin0).write_angle(90)
|
|
|
"""
|
|
|
|
|
|
def __init__(self, pin, freq=50, min_us=600, max_us=2400, angle=180):
|
|
|
self.min_us = min_us
|
|
|
self.max_us = max_us
|
|
|
self.us = 0
|
|
|
self.freq = freq
|
|
|
self.angle = angle
|
|
|
self.analog_period = 0
|
|
|
self.pin = pin
|
|
|
analog_period = round((1/self.freq) * 1000) # hertz to miliseconds
|
|
|
self.pin.set_analog_period(analog_period)
|
|
|
|
|
|
def write_us(self, us):
|
|
|
us = min(self.max_us, max(self.min_us, us))
|
|
|
duty = round(us * 1024 * self.freq // 1000000)
|
|
|
self.pin.write_analog(duty)
|
|
|
self.pin.write_digital(0) # turn the pin off
|
|
|
|
|
|
def write_angle(self, degrees=None):
|
|
|
degrees = degrees % 360
|
|
|
total_range = self.max_us - self.min_us
|
|
|
us = self.min_us + total_range * degrees // self.angle
|
|
|
self.write_us(us)
|
|
|
|
|
|
Servo(pin16).write_angle(0) # Turn motor once
|
|
|
Serve(pin16).write_angle(95) # Turn motor again
|
|
|
</pre>
|
|
|
</details>
|
|
|
<details>
|
|
|
<summary>
|
|
|
<a>Control Radio(Javascript)</a>
|
|
|
</summary>
|
|
|
<img src="/uploads/658c560344f0785d1928ba9073bf15f0/Screen_Shot_2018-06-28_at_10.21.02_AM.png"/>
|
|
|
</details>
|
|
|
<details>
|
|
|
<summary>
|
|
|
<a>Control Radio(MicroPython)</a>
|
|
|
</summary>
|
|
|
<pre>
|
|
|
from microbit import *
|
|
|
import radio
|
|
|
|
|
|
radio_group = 1 #number of radio frequency to use
|
|
|
radio.on()
|
|
|
radio.config(power=7,channel=radio_group)
|
|
|
radio.send("Hello")
|
|
|
</pre>
|
|
|
</details>
|
|
|
[[top](#top)]--[[up](#materials)]
|
|
|
|
|
|
## Setup
|
|
|
<p id="setup"></p>
|
|
|
1. Decide which language you would like to use for this project and navigate to the project code listed in either [the python folder](https://uwcedar.io/community/cowpokes/tree/master/03_Lockpick/Python) of the supplied code or [the javascript/blocks folder](https://uwcedar.io/community/cowpokes/tree/master/03_Lockpick/Javascript).
|
|
|
2. Load your online IDE of choice with the code for the basic-lockbox program. If you have not already read or watched our tutorials on [programming in python or blocks, or on copying the code onto the MicroBit, please check out our <a href="https://uwcedar.io/Apical_Meristems/COWPOKES/wikis/instructions-home" target="_blank">instructions wiki</a>.
|
|
|
3. Flash the basic-lockbox code onto the MicroBit included in the lockbox. Then repeat the process for the code for basic-key, but flash this code onto the MicroBit you will use as the key.
|
|
|
|
|
|
Below is listed sections of code for a very basic lockbox that can be opened multiple ways. First, pressing the A/B buttons will unlock the box (not very secure but remember this is our starter box). Secondly, this box will also open if the binary encoding of the number 5 ("0101") is sent over the radio using radio channel 1.
|
|
|
![Screenshot_from_2018-06-27_13-06-14](/uploads/ed23be241af0b50c4db559a5d3265b65/Screenshot_from_2018-06-27_13-06-14.png)
|
|
|
Here we see the beginning of the program, where the microbit initializes the radio group("channel"), then tells the lock to move to position 0, and finally shows us the sprite "No".
|
|
|
```javascript
|
|
|
//initial setup of the block
|
|
|
radio.setGroup(1)
|
|
|
let position = 0
|
|
|
pins.digitalWritePin(DigitalPin.P16, position)
|
|
|
basic.showIcon(IconNames.No)
|
|
|
```
|
|
|
Now, in order to unlock the box using the buttons we must tell the microbit to listen for the "On-Click" event that triggered every time the physical button is pushed. Since we initially set the position of our lock to 0, we say that pressing the button A will unlock the box by telling the lock to move to position 95 which is our unlocked position. ?What does the code for the B button which closes the box look like?
|
|
|
```javascript
|
|
|
//listen for a click event, then un/lock box
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
basic.showString("A")
|
|
|
position = 95
|
|
|
pins.servoWritePin(AnalogPin.P16, position)
|
|
|
basic.pause(100)
|
|
|
})
|
|
|
```
|
|
|
|
|
|
* For Python, you can use Mu ([click here to see Mu](https://codewith.mu/)) or the online editor ([click here to get to the online editor](http://python.microbit.org/v/1)).
|
|
|
And now we show the code responsible for listening for a key to come over the radio to unlock the box.
|
|
|
```javascript
|
|
|
//listen for a click event, then un/lock box
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
basic.showString("A")
|
|
|
position = 95
|
|
|
pins.servoWritePin(AnalogPin.P16, position)
|
|
|
basic.pause(100)
|
|
|
})
|
|
|
```
|
|
|
|
|
|
### Step 5: Flash the base code.
|
|
|
If you don't remember how to flash code to your Micro::Bit, see the instructions [here](how-to-flash).
|
|
|
[[top](#top)]--[[up](#getting-familiar)]
|
|
|
|
|
|
### Step 6: Programming!
|
|
|
_06-Step by step instructions_
|
|
|
## Next Steps
|
|
|
<p id="exploration"></p>
|
|
|
* Download and flash the code for either of the Hard Lockboxes, and try to write a key that will open them.
|
|
|
1. Hard-Lockbox1 requires two wireless keys. First key("0101") must be sent over radio group 2, and then the second key("1001") must be sent over radio group 5.
|
|
|
2. Hard-Lockbox2 expects the key("100110") but advances its radio group by 1 every 15 seconds until it reaches the maximum radio group and then begins again at zero. Good luck catching it!
|
|
|
* Were other people's keys opening your safe? Why is that? How do you prevent that?
|
|
|
* Can you think of a better way to secure your lockbox? If so, implement that in the language of your choosing and challenge your partners to crack it!
|
|
|
* Use both languages, either MicroPython for the lock box and Javascript/Blocks for the key or vice-versa.
|
|
|
|
|
|
### Step 7: Further Exploration
|
|
|
_07-2 or 3 thoughts for other things they could further their work with_ |
|
|
\ No newline at end of file |
|
|
[[top](#top)]--[[up](#setup)] |
|
|
\ No newline at end of file |