Arduino serial menu

jeroendoggen/Arduino-serial-menu

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Arduino Serial Menu

Arduino library to show configuration menus over the serial port

  1. Download the source
  2. Place the SerialConfigMenu folder in your Arduino1.0+ «libraries» folder
  3. Open an example sketch: «file», «Examples», «SerialConfigMenu», «Menu_Default» or «MenuEmpty»
  4. Compile & upload code
  5. Monitor the serial port with minicom or any other ‘real’ terminal monitor (not the default Arduino serial monitor) (startup: «minicom -o»)
  • The ‘strings’ for the menu are placed in PROGMEM to minimize RAM usage
  • Every ‘menu’ is just a collection of these ‘strings’
  • After the menu is printed, the cursor returns to the first line
  • When the menu is printed again (when the loop restarts), exactly the same text is printed again, giving the impression of a static menu.

About

Arduino library to show user menus over the serial port

Источник

Serial Service Menu © GPL3+

Show status information, change NW credentials, ping your gateway, show sensor values or get more details by activating debugging…

Arduino MKR WiFi 1010
Will run on all SAMD21 Boards (MKRs) and probably also on all the other/older Arduinos…
× 1
Tactile Switch, Top Actuated
The ‘factory reset’ push button.
× 1
Arduino Web Editor
Because it’s the easiest way to get your IoT Project started fast :-)
putty — for Windows and Linux
Serial terminal client program, written by Simon Tatham, Alexandra Lanes, Ben Harris and Jacob Nevins
Serial USB Terminal — for Android Phones
Serial terminal client program, written by Kai Morich

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.

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.

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

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 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.

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!

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.

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.

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.

Источник

sonyhome/SerialMenu

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

An Efficient Serial Console Menu Library for Arduino

Anouncement post on the Arduino forum

Blog entry and discussion

This library allows you to define menus for the Arduino Serial console.

The menus are very simple to build. You just declare them in an array.

The menus are simple to run. A single call to a show() method displays them. A single call to the run() function inside loop() is all it takes to automatically monitor the user’s menu inputs and execute the appropriate callback function associated to the menu entry selected.

Multiple menus can be defined, and can be nested and called easily, just by calling the load() method.

The menus are non-blocking. Code only trigger when there is user input. This means run() returns immediately if there’s no activity, or just after calling the callback routine if there was user input. This allows programs to simultaneously go about the work you want them to do while responding to serial commands promptly, but with almost no overhead.

Furthermore because of how the menu library is implemented, the memory consumed for the menus, even big ones, is minimal.

  • Simple to declare a menu as a global variable
  • One call to display the menu
  • Easily support sub-menu hierarchies
  • Compact user code
  • Tiny SRAM data memory consumption
  • Menu text can be stored in SRAM or Flash (data or program memory)

Low memory overhead:

To demonstrate the efficiency of this library, it was added to one of the existing examples shipped with the Arduino IDE, and we compared the memory footprint to figure out the actual overhead.

This analysis is for the following configuration:

  • Example program: 07.Display -> barGraph
  • Platform: Arduino UNO
  • SerialMenu version 1.0 released Nov. 12 2019.

Overhead Results:

  • Low 5 Bytes of SRAM data memory overhead per menu line entry with strings stored in FLASH memory.
  • Fixed 43 Bytes of SRAM base cost for the library (of which 12B for the singleton).
  • Fixed 1150 Bytes of FLASH base cost for the library’s code.

Original code using Serial:

Note: We’ll leave this extra code in setup(), so as to not bias the cost of using the SerialMenu library. It will be our reference. The intent is to write to the Serial console so this overhead (1034B code, 191B data) is unavoidable unless we rewrite the default HardwareSerial library. We assume the reference program consumes 2120 bytes of FLASH and 220 bytes of SRAM before adding any menus in it. The reference program’s console output is:

Adding SerialMenu code:

Overhead: 814B code, 12B data If there’s no reference to SerialMenu there’s no overhead to include the library. If there is, as above, the overhead is from the creation of the SerialMenu singleton instance. It is a one time hit. As coded above, this just prints the library’s copyright which is stored in FLASH memory:

It is possible to disable printing unecessary text like the copyright with a macro, which further reduces memory consumption. We’ll use this mode to report our results:

Overhead: 662B code, 12B data This result seems reasonable. The singleton holds 2 pointers, a short and a byte (11B total). Now let’s add the function calls needed to run the menus. The code does nothing since we still have an empty menu.

Overhead: 1150B code, 43B data The 3 routines used linked extra code and claimed 32B of SRAM. I don’t know where that went.

Adding a menu with 2 entries:

Since the goal is to use the least SRAM data memory, we’ll declare a small menu with two entries, storing the text in FLASH memory via the PROGMEM keyword. Here’s the full modified program:

Overhead: 1304B code, 55B data The results are still coherent. We added two menu entries, each holding a function pointer (not in SRAM), a data pointer and a byte (5B). The menu is now functional, and the output is as follows, when typing A[enter] then B[enter]:

Be carefuly with memory constrained boards, running out of SRAM will lead to flaky code behavior. Keep menu text minimal as it could eat up memory. To alleviate memory pressure menus can be stored in Flash program memory using the PROGMEM keyword, instead of SRAM data memory. However, even Flash memory is limited.

Menu callback functions can be declared as separate functions or as lambda functions directly in the data structure with the menu data. Lambda notation is best for simple tasks like setting a global variable or calling another menu, as it keeps the code for a menu entry concise and within the menu entry definition. See the example. A lambda function syntax is written «[]()<>» where the code goes inside <> . The other elements «[]()» are not used here.

Copy this package in your Arduino’s «library» directory. For example on Mac this will be in «Documents/Arduino/libraries».

To test load and run the example from the Files menu: File -> Examples -> SerialMenu -> Demo Open your Serial console window in the IDE from the Tools menu: Tools -> Serial Monitor

You should see the demo menu, and interact with it.

Usage example 1:

Let’s create a simple menu which controls global values and calls a function to do some math.

Usage example 2:

Let’s create two menus which call each other, with a varying number of menu entries, some of them stored in Flash (PROGMEM), and some in SRAM.

The library by default will maximize functionality and verbosity. It is possible to define macros before the library’s inclusion, to disable some features and henceforce reduce the memory footprint.

About

An Arduino library to easily create menus on the serial console.

Источник

Adblock
detector