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: Radio Tilt Control

Cybersecurity: Radio Tilt Control

How the Tilt Radio Tests Work

How radio_transmit_tilt_test Works

The project starts with importing modules. Since this project only measures tilt and transmits, it does not need to include the cyberbot extension.

The project uses radio set group to set the channel, message queue, and message length. As explained in the Cybersecurity: Radio Basics tutorial, the channel defaults to 7, but can be adjusted to an integer from 0 to 255. Classrooms typically assign pairs of students to different channels to avoid crosstalk. The sender and receiver have to be on the same channel for communication to work. 

Next, pause (1000) gives the editor time to establish the serial connection with the micro:bit before it has to display text from the micro:bit.

The main loop starts with statements from display_tilt_direction_with_leds that take the accelerometer x and y measurements and calculate/display the LED tilt direction needle. There are extra serial write statements for “Send:” and an empty line. Since the LEDs display the direction of the tilt like a compass needle, the direction variable’s name is changed to needle here.

Next, the x, y, and needle values are added to a dictionary named dictionary. This step is important because it reduces the work the receiver has to do. The receiver can just get the values that correspond to the ‘x’, ‘y’, and ‘needle’ keys.

After dictionary is populated, all that remains is to convert it to a string, send it through the radio, and delay 0.5 s before repeating the forever loop.

How radio_receive_tilt_test Works

The project starts in much the same way as the radio_transmit_tilt_test.

The main loop starts by copying any data the radio might have received to a variable named rLongString. When on radio receive() returns none, the project skips everything in the if rLongString… statement and continues waiting for a signal. When on radio receive() returns a string from the transmitter micro:bit, all the statements in the if rLongString… statement get executed. First, convert string (rLongString) to dictionary converts the string that was received back to a dictionary. Then dictionary search sets the x, y, and needle variables using the ‘x’, ‘y’, and ‘needle’ keys. 

Now, that the receiver has variables with the transmitter micro:bit’s measurements, it can display them in the terminal and with the LEDs. As with the transmitter, these statements are similar to what’s in display_tilt_direction_with_leds with extra serial write line statements for “Receive:” and an empty line, the variable for displaying the tilt direction is needle instead of cardinal direction.


Printer-friendly version
Radio-Receive Tilt
Prev
Tilt Control Forward & Backward
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress