Skip to content

Search the documentation

Kit
Firmware

Numbers on the 7-segment — Smart Home

The little red 3-digit display counts through four numbers, again and again: 1, then 22, then 333, then 0. One second each.

This is the first thing to try on a Smart Home board, because the display needs nothing plugged in and nothing set up — if these numbers appear, the board booted, your program was sent, and the display works.

This is one project for both firmware versions: when MoBot opens it, the blocks write the code for the firmware of your Smart Home.

The blocks of this example, from top to bottom.
Click the picture to view it larger.Open full sizeThe same program written as Python is further down this page, in The Python code.
Read the program as text
  • MoBot Start
  • Print to serial "7-segment test starting"
  • repeat forever
    • Display Number 1 on 7-Segment
    • wait 1 seconds
    • Display Number 22 on 7-Segment
    • wait 1 seconds
    • Display Number 333 on 7-Segment
    • wait 1 seconds
    • Display Number 0 on 7-Segment
    • wait 1 seconds
    • Set digit 0 segments : a 1 b 0 c 0 d 1 e 0 f 0 g 1 dp 0
    • wait 1 seconds
  • A Smart Home board (ESP32-S3) with the 3-digit 7-segment display on it.
  • A USB cable.
  1. Open 01-seven-segment.mobot in MoBot.
  2. Plug the board in and pick its port.
  3. Press Send to Device.
  4. Watch the red display.
  • [MOBOT] 7-segment test starting appears once in the serial monitor.

  • The red display then shows, one second apart, forever:

    shows why
    1 one digit, pushed to the right
    22 two digits
    333 all three digits full
    0 back to the start
  • On the fifth step the first digit (the left one) shows three bars, ≡, for one second. The other two digits keep what they showed before.

If the display stays dark but the serial line appeared, the program is running and the display is the problem. If nothing appears at all, the program did not reach the board.

The last block in the loop is Set digit 0 segments : a 1 d 1 g 1. Each digit of the display is made of seven little bars, called a to g, and a dot, dp. Put 1 next to a letter to light that bar and 0 to leave it dark.

Here a is the top bar, g the middle one and d the bottom one, so the first digit draws three horizontal bars, like this: ≡.

The block above it, Display Number on 7-Segment, is the easy way to show a number. Use Set digit … segments when you want to draw something that is not a number.

block what it does
iot_print Sends a line to the serial monitor.
repeat_forever Everything inside runs over and over.
iot_7segvar Shows a whole number on the 3-digit display.
wait Pauses, in seconds.
iot_7seg Lights chosen segments of one digit.

The same blocks write different Python for each firmware, and MoBot picks the one that fits the robot you use. The 2.x tab is for reference. This is a reading copy: editing it changes nothing, so change the blocks instead. The name map lists the names that changed.

01-seven-segment.firmware-3.main.py
# Numbers on the 7-segment — iot (firmware 3.0)
#
# This is what MoBot puts on a robot running firmware 3.0 as main.py when you open
# 01-seven-segment.mobot and press Send to Device. It is GENERATED from the blocks;
# editing this file changes nothing. Edit the blocks instead.
# The firmware 2.x version is 01-seven-segment.main.py.
from machine import Pin
import time
print("[MOBOT]", '7-segment test starting')
while True:
home.number_display.show_number(1)
time.sleep(1)
home.number_display.show_number(22)
time.sleep(1)
home.number_display.show_number(333)
time.sleep(1)
home.number_display.show_number(0)
time.sleep(1)
home.number_display.set_digit(0, ['A', 'D', 'G', ])
time.sleep(1)
  • Change 333 to your age.
  • Make the waits 0.2 and watch the numbers race.
  • Try 1234 in one of the Display Number blocks. The display only has three digits, so it cannot show four — a good thing to discover on purpose.