๐Ÿ’ก Level 1 โ€“ Fundamentals

Project 1.1: "Serial Interaction"

ย 

๐Ÿš€ Project 1.1 โ€“ Serial interaction

๐ŸŽฏ What youโ€™ll learn

  • โœ… Goal 1: Print text from your robot to the computer.
  • โœ… Goal 2: Read text typed on the computer.
  • โœ… Goal 3: Use a variable in a simple decision.

Key ideas

  • Serial communication: A chat between your robot and your computer.
  • Variable: A box that stores a word or number.
  • Decision: The robot chooses based on what you type.

๐Ÿงฑ Blocks glossary (used in this project)

  • Serial print: Robot shows a message on your computer.
  • Serial read: Robot reads what you type in the serial window.
  • Variable set: Save a value with a name (like โ€œchoiceโ€).
  • if / elif / else: Make a decision.
  • Loop while true: Repeat steps forever (not needed here, but handy later).

๐Ÿงฐ What you need

Part How many? Pin connection
D1 R32 1 USB cable (30 cm)
  • ๐Ÿ”Œ Wiring tip: Only USB cable for this project.
  • ๐Ÿ“ Pin map snapshot: No pins used.

โœ… Before you start

  • USB: Cable plugged in.
  • Serial: Monitor open.
  • Test print: Run this first.
import machine                 # Load base library to start
print("Clu-Bots Ready!")                # Show start message on the serial screen

๐ŸŽฎ Microprojects (5 mini missions)

๐ŸŽฎ Microproject 1.1.1 โ€“ Hello Clu-Bots

  • Blocks used:
    • Serial print
  • Block sequence:
import machine                 # Load base library
print("Hello Clu-Bots")           # Print a friendly message to the serial screen
  • Reflection: Your robot can speak to you through the serial screen.
  • Challenge: Change โ€œHello Clu-Botsโ€ to your name or a fun phrase.

๐ŸŽฎ Microproject 1.1.2 โ€“ Ready message

  • Blocks used:
    • Serial print
  • Block sequence:
import machine                 # Load base library
print("Ready!")                # Print a start signal so you know the code is running
  • Reflection: A start signal helps you verify communication.
  • Challenge: Add a second line: โ€œLetโ€™s go!โ€

๐ŸŽฎ Microproject 1.1.3 โ€“ Echo command

  • Blocks used:
    • Serial print
    • Serial read
    • Variable set
  • Block sequence:
import machine                      # Load base library
print("Type a command:")            # Ask the user for a word or phrase
command = input()                   # Read the userโ€™s input into variable 'command'
print("You typed:", command)        # Show the exact input back to the user
  • Reflection: Your robot can listen and repeat what you type.
  • Challenge: Try numbers, words, and short phrases; see the echo.

๐ŸŽฎ Microproject 1.1.4 โ€“ Simple decision

  • Blocks used:
    • Serial read
    • Variable set
    • if / else
    • Serial print
  • Block sequence:
  • ย 
import machine                      # Load base library
print("Type 1 or other:")           # Ask the user to choose
choice = input()                    # Read the choice and store in 'choice'
if choice == "1":                   # If the user typed the number 1
    print("Hello")                  # Respond with Hello
else:                               # For any other input
    print("Bye")                    # Respond with Bye
  • Reflection: Decisions change the robotโ€™s behavior.
  • Challenge: Add โ€œ2โ€ as a second choice with a special message.

๐ŸŽฎ Microproject 1.1.5 โ€“ Tiny menu

  • Blocks used:
    • Serial print
    • Serial read
    • Variable set
    • if / elif / else
  • Block sequence:
import machine                      # Load base library
print("Menu: 1=Hello, 2=Bye")       # Show the simple menu
choice = input()                    # Read the userโ€™s selection
if choice == "1":                   # Option 1 selected
    print("Hello")                  # Print Hello
elif choice == "2":                 # Option 2 selected
    print("Bye")                    # Print Bye
else:                               # Any other input
    print("Invalid choice")         # Inform about invalid option
  • Reflection: Menus guide the robotโ€™s actions step by step.
  • Challenge: Add โ€œ3=Surprise!โ€ with your own custom message.

โœจ Main project โ€“ Interactive serial menu

๐Ÿ”ง Blocks steps (with glossary)

  • Blocks used:

    • Serial print: Show menu options
    • Serial read: Get the userโ€™s choice
    • Variable set: Save the choice
    • if / elif / else: Decide the response
  • Block sequence:

import machine                              # Load base library
print("Menu: 1=Hello, 2=Bye, 3=Surprise")   # Show the full menu
choice = input()                            # Read the userโ€™s selection
if choice == "1":                           # If 1 is chosen
    print("Hello")                          # Respond with Hello
elif choice == "2":                         # If 2 is chosen
    print("Bye")                            # Respond with Bye
elif choice == "3":                         # If 3 is chosen
    print("Surprise!")                      # Respond with Surprise
else:                                       # If input is anything else
    print("Invalid choice")                 # Inform that the choice is not valid

๐Ÿ“– External explanation

  • What it teaches: How robots can read your input and react with different messages.
  • Why it works: The program compares your input to conditions (if/elif/else) and prints the matching response.
  • Key concept: Decisions in code control what the robot does next.

โœจ Story time

  • Mission hook: Imagine your robot is taking orders like a friendly waiter. You choose from the menu, and it serves the right message every time.

๐Ÿ•ต๏ธ Debugging (2 common problems)

๐Ÿž Debugging 1.1.A โ€“ Nothing on screen

  • Problem: No text appears.
  • Clues: Serial monitor is closed or not focused.
  • Broken code:
print("Hello Clu-Bots")            # This prints, but you wonโ€™t see it without serial open
  • Fixed code:
print("Hello Clu-Bots")            # Open the serial monitor before running
  • Why it works: The serial window must be open to show messages.
  • Avoid next time: Always open serial first and look for โ€œReady!โ€.

๐Ÿž Debugging 1.1.B โ€“ Choice not recognized

  • Problem: You typed 2 but didnโ€™t see โ€œByeโ€.
  • Clues: Extra spaces or different characters.
  • Broken code:
choice = input()                # If you typed a space or symbol, it wonโ€™t match "2"
if choice == "2":
    print("Bye")
  • Fixed code:
choice = input()                # Type exactly 1, 2, or 3 (no spaces)
if choice == "2":               # Exact match triggers the correct response
    print("Bye")
  • Why it works: Exact string matching is required.
  • Avoid next time: Type exactly the option number.

โœ… Final checklist

  • Screen: I saw โ€œReady!โ€ at the start.
  • Action: I printed and read messages.
  • Change: My menu choice changed the result.

๐Ÿ“š Extras

  • ๐Ÿง  Student tip: Add โ€œ4=Jokeโ€ and print a funny line.
  • ๐Ÿง‘โ€๐Ÿซ Instructor tip: Watch for closed serial windows and exact input matching.
  • ๐Ÿ“– Glossary: Serial, Variable, if/else, Menu.
  • ๐Ÿ’ก Mini tips: Keep messages short; always test with โ€œReady!โ€ first.
On this page