กลับไปหน้ารวมไฟล์
serial-service-menu-c68718-en.md

Motivation

When I handover Arduino IoT projects to friends I realize that I need to address the following requirements:

  • Various network credentials must be changeable by others without an IDE. Here some examples: SSID/Key for WiFi, APN/Pin/UN/PW for GSM, APP_EUI/KEY for LoRa-WAN, etc.)
  • A Hostname byside the THING_ID would be useful.
  • The Serial-Line is slow by design and therefore I avoid printing out unnecessary information's. But in kind of troubles it must be possible to activate serial debugging. And of course, without restarting the Arduino - to avoid that the reboot temporary fix a problem...
  • Get some general status information's out of the Arduino.

Requirements

I use various Arduino MKRs (WiFi, LoRa, GSM) because of their IoT functions. The following solutions are possible for all the MKR variants...

Storage

The SAMD21G18 Microcontroller has an on-board flash with 256KB capacity. This is more than enough to store everything for my projects. No extra hardware is needed.

There is one important fact to know: The flash will be completely erased when you upload a new Sketch. So, the settings get lost in this case. Not a showstopper for my projects. But maybe for yours!!!

The ATECC508 Chip was also a possible storage place. But because only three Slots with 72 Bytes are free - it is not a good choice for me.

User Interface

To keep it simple I selected the USB Port to interact with the user. This port is available on all Arduino's and serial terminal client programs (putty) are free available on nearly all computers and mobile devices.

To protect from unauthorized access, the serial line must be secured with a password!

Recover from lost password

If the password will be forgotten, a button to reset the flash to factory defaults is required.

The Solution

I have called it Serial Service Menu - view the video to see how it behaves...

take a look...

The communication is done by using Arduino's Micro-B USB Port yes, the same you use for uploading your sketch. In fact, a virtual RS232 serial communication channel was used.

If you like to connect your mobile device, you need an OTG (On the Go) Ready Smartphone and an OTG adapter cable. It is the short cable directly connect to my phone. This Cable signals the phone that it should behave as a USB host and not like a USB Client which it normally does. As Host you can connect USB Devices like a USB Stick into your phone or get use of virtual USB COM Ports as we need here.

The Serial Service Menu used with my Smartphone

The Arduino acts as Terminal Server and on the other side the PC/MAC/Mobile-Phone needs to run a Terminal Client program. This client used the virtual COM Port which appears when you connect the Arduino to your PC.

The virtual COM Port on my Windows 10 PC

I recommend using putty as terminal client for PCs and Linux systems. For Android Phones I recommend the Serial USB Terminal App from Kai Morich. It's in the Play-Store. Because I am not an Apple user I cannot recommend terminal client apps for MACs or iPhones - sorry. But there are good programs available for the Apple world too!

Beside the Arduino MKR you only need a push button for the factory reset function. This is necessary when the user losts his password! The factory reset button was only checked once during the Arduino startup (void setup()) so you can also reuse an already existing button from your project!

The Sketch

See the section CODE below for the complete Arduino sketch. I have documented a lot inside the code. But let me explain some details right away:

1. I have connected and used one SHT35 Temperature and Humidity Sensor to demonstrate a possible task/job for the MKR. This has nothing to do with the Serial Service Menu, it is just an example.

2. The SHT35 values are presented by the Arduino IoT Dashboard, again just for demonstration purposes.

3. There is also a dashboard button to reset the Arduino from remote. Maybe this is also interesting for you...

Arduino IoT Dashboard

When you push the "RestartCpu" button you can reboot your Arduino MKR from remote. You can watch the restart by entering the debug mode on the Serial Service Menu...

restart from dashboard

I also wrote three flowcharts for the three main code parts in the sketch. You will find them below. Use them together with the notes inside the sketch to get familiar...

EXPANDED TECHNICAL DETAILS

Embedded Diagnostic HMI

This project provides a professional "Service Menu" accessible via the Serial monitor, allowing for on-the-fly configuration of Arduino parameters.

  • Terminal Command Parser: The Arduino listens for specific character-based commands (e.g., M1 for Manual Mode, S500 for Sensitivity 500). The firmware uses a non-blocking serialEvent() loop to parse these inputs without interrupting the main sensor logic.
  • Cross-Platform Compatibility: Fully tested with Putty (Windows/Linux) and Serial USB Terminal (Android), enabling users to calibrate their hardware from a laptop or a smartphone on-site.

Dynamic Persistence

  • EEPROM Save/Load: Settings adjusted via the menu are automatically saved to the Arduino's internal EEPROM, ensuring the hardware maintains its calibrated state even after a power cycle.

ข้อมูล Frontmatter ดั้งเดิม

title: "Serial Service Menu"
description: "Show status information, change NW credentials, ping your gateway, show sensor values or get more details by activating debugging…"
author: "andreas_waldherr"
category: "Lab Stuff"
tags:
  - "cli"
  - "usb"
  - "menue"
views: 13717
likes: 7
price: 299
difficulty: "Intermediate"
components:
  - "1x Tactile Switch, Top Actuated"
  - "1x Arduino MKR WiFi 1010"
tools: []
apps:
  - "1x putty - for Windows and Linux"
  - "1x Serial USB Terminal - for Android Phones"
  - "1x Arduino Web Editor"
downloadableFiles:
  - "https://create.arduino.cc/editor/andreas_waldherr/7e7538ef-fada-478a-a738-4f243d67db18"
  - "https://create.arduino.cc/editor/andreas_waldherr/7e7538ef-fada-478a-a738-4f243d67db18"
documentationLinks: []
passwordHash: "fc8c7cc45b671741799f0e1ce0db99be955d34cbf241265ae92be349a16b106d"
encryptedPayload: "U2FsdGVkX19Kiqk7nwixmt/SQbHOBUxUvxeLJEdCnrIP0eIgqAtO1UGHT2yRVA5s51rOGA131jXbNKI2cxelENM0H+iJVZqCjF/NDMuDsXJ068PkYcw7tF6VHAMQvIeZqXZ5gmIxu891OJPPHE78RZ6BWpHE4B0stXWEqkK2wlDhdHNeDA+VblvwX23X1Z6wE9hpWd6vgy/uqdLldl/xgg=="
seoDescription: "Manage Arduino via Serial Service Menu: View status, change NW credentials, ping gateway, monitor sensor values, and enable debugging."
videoLinks:
  - "https://www.youtube.com/embed/FHtuD-bYGQo"
  - "https://www.youtube.com/embed/WzM3w_v0xng"
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/serial-service-menu-c68718_cover.jpg"
lang: "en"