Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity with AI and micro:bit

Cybersecurity with AI and micro:bit

micro:bit Remote Code Updates

In this activity, you will follow along as a chatbot is guided through writing two application scripts: one for a sender micro:bit and for receiver micro:bit modules.  The sender application allows you to type a script into the serial monitor. Then, after typing run, the sender radio-broadcasts the script to any available micro:bit receivers.  The receiver application receives and executes any scripts they receive over the radio.   You will also test the scripts and consider beneficial and malicious ways in which it could be used.

Application Development Conversation

  • Read through the conversation below, to see how the chatbot was prompted.  The … lines indicate where the script iterations were omitted. Final scripts will be on the next page.

User

Write two scripts for two micro:bit modules.  The first module’s script should allow the user to input a string in the terminal.  It should then send that string over the radio to the second micro:bit.  The second micro:bit should receive that string over its radio, and execute it as Python statements.

ChatGPT

Certainly! To achieve this communication between two micro:bits using radio communication, you can use the radio module that comes with the micro:bit MicroPython library. Below are the scripts for the two micro:bit modules.

…

 

User

Let’s up the buffer in both scripts to 250 characters.

ChatGPT

Certainly! To increase the buffer size for both scripts, you can modify the scripts as follows:

…

In these modified scripts, I’ve added display.scroll messages to provide prompts and indicate when a message has been sent or received. These messages will scroll on the micro:bit’s LED display. Make sure to upload these updated scripts to your micro:bits.

 

User

Adjust this to be entirely terminal based.

ChatGPT

If you want the interaction to be entirely text-based in the terminal without using the micro:bit LED display, you can modify the scripts accordingly. Below are the adjusted scripts:

…

In this modification, the receiver script accumulates the lines of the script until it receives the command “run.” When “run” is received, it executes the accumulated script line by line using the exec function. After execution, it clears the script lines to prepare for the next set of input. This way, you can enter multi-line scripts and execute them by sending the “run” command.

 

User

Could both scripts be adjusted to support indentation?

ChatGPT

Certainly! To support indentation in Python scripts, you can adjust the receiver script to properly handle indentation. Here are the modified scripts:

…

See Module 1: Sender and Module 2: Receiver in the Scripts section.

….

In this modification, the receiver script now properly adjusts the indentation by comparing the leading spaces of each line with the current indentation level. It appends lines to the script accordingly, taking into account the indentation.

 


Printer-friendly version
Sender and Receiver Scripts
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress