Scripts to Drive Wearable Computing – InApps is an article under the topic Software Development Many of you are most interested in today !! Today, let’s InApps.net learn Scripts to Drive Wearable Computing – InApps in today’s post !

Key Summary

This article from InApps Technology, authored by Phu Nguyen, explores the use of Linux scripts to automate tasks on Raspberry Pi and similar nano-Linux devices (e.g., CHIP, BeagleBone) for wearable computing, specifically the author’s Steampunk Conference Badge (Gen-5). It emphasizes scripts as simple, powerful automation tools for enhancing functionality in physical computing projects. Key points include:

  • Role of Scripts:
    • Purpose: Automate sequences of commands or programs, acting as “time or keystroke savers” for tasks on devices like the Raspberry Pi.
    • Simplicity: Most scripts are short (a few lines), though they can include complex logic, input handling, or programming features.
  • Use Case 1: Big Data from Small Devices:
    • Scenario: Combining a Raspberry Pi 3 with an Arduino Pro Mini to read analog/digital data in real-time, perform calculations, and send data for display (e.g., on a gauge) or to the cloud.
    • Script Example:
      • Configures the serial port (/dev/ttyS0) using the stty command to set parameters.
      • Uses cat /dev/ttyS0 to read and display data on the console.
      • Requires setting executable permissions (chmod +x).
      • A variant script (capture-usb.sh) reads from /dev/ttyUSB0 for USB ports.
    • Benefit: Simplifies data streaming between microcontroller and Pi, enabling real-time processing.
  • Use Case 2: Switching Displays (TFT LCD to HDMI):
    • Scenario: The Gen-5 badge uses a 3.5″ TFT LCD touchscreen but can switch to an HDMI monitor for presentations (e.g., running LibreOffice slides).
    • Scripts:
      • To HDMI: Moves the 99-fbdev.conf file (configures X server for LCD) out of /etc/X11/xorg.conf.d and reboots to default to HDMI.
      • To TFT: Restores 99-fbdev.conf to the directory and reboots to use the TFT LCD.
      • Dual Display: Use <Ctrl><Alt><F2> to access a console on HDMI while TFT shows the desktop, or <Ctrl><Alt><F1> for TFT console with HDMI desktop; <Alt><F7> switches back.
    • Benefit: Enables flexible display switching for wearable-to-desktop transitions.
  • Use Case 3: Running a Processing Sketch:
    • Scenario: Automates a Processing language sketch (e.g., an analog gauge) using data from an Arduino Pro Mini without the Processing IDE.
    • Script:
      • Navigates to the Processing directory.
      • Configures the serial port with stty.
      • Runs the sketch via Java, using –present for full-screen mode or –run for a desktop window on HDMI.
    • Benefit: Reuses script components (e.g., stty from capture-tty.sh) for efficient automation of graphical outputs.
  • Key Takeaways:
    • Simplicity and Reuse: Scripts leverage existing commands/programs, avoiding complex custom programs and reusing code snippets for efficiency.
    • Power of Raspberry Pi: As a full Linux machine, it supports robust automation for wearable computing tasks.
    • Unix Philosophy: Stringing together small, focused scripts aligns with the *nix approach to modular automation.
  • InApps Insight:
    • InApps Technology leverages scripting and platforms like Raspberry Pi, integrating React Native, ReactJS, Microsoft’s Power Platform, and Azure, using Power Fx for low-code solutions and Azure Durable Functions for scalable workflows.
    • Combines Node.js, Vue.js, GraphQL APIs (e.g., Apollo), and Azure to deliver innovative solutions, targeting startups and enterprises with Millennial-driven expectations.
Read More:   The Challenges of Making Video Games for Cats – InApps 2022

Read more about Scripts to Drive Wearable Computing – InApps at Wikipedia

You can find content about Scripts to Drive Wearable Computing – InApps from the Wikipedia website

Do you use scripts with your Raspberry Pi?

I don’t see very much attention paid to using scripts, with the various nano-Linux devices like the Raspberry Pi, CHIP or BeagleBone. Scripts are a tremendous automation tool and let you execute a string of commands or programs, in sequence.

Although Linux scripts can get complicated — with logic, input and other regular programming features — most are just small, simple, “time or keystroke savers” usually containing only a handful of lines.

Today’s discussion covers a few scripts that I use on my own creation, the Steampunk Conference Badge (the “Gen-5” edition).

Big Data from Small Devices

A very practical example of using the power of Linux scripts in a physical computing situation is when combining a microcontroller with the Raspberry Pi. An external Arduino Pro Mini, gives you the ability to read analog and digital data in real-time do a few calculations, then send a data stream out the serial line. The Raspberry Pi can then suck in the data and display it on a gauge, control an output pin or ship the data up to the Cloud.

Why not just connect, the Pro-Mini’s serial line to the Raspberry Pi 3 and read the data with a quick “cat /dev/ttyS0“? Not so fast. Likely you’ll need to set the serial port configuration, on the Raspberry Pi, before data starts flowing. Combining the two, gets the job done.

The first line just sets the path to the Bash shell interpreter. Then there are a couple of comments, including the file name and script functions. Next, is the “stty” command to properly set the serial port (/dev/ttyS0) parameters. Lastly, execute the “cat” command to print the values on the console screen.

Read More:   How to Install Rust – Tutorial with detail instructions

Before being able to run the script, the permissions need to be changed so it’s executable.

Then, run the script with the following line.

I also built a similar script to read the USB port, by simply copying the file, renaming it (to capture-usb.sh) and changing the port to /dev/ttyUSB0.

How about changing a Raspberry Pi’s behavior after a reboot?

Bounce between the TFT LCD and HDMI Monitor

My Gen-5 conference badge has a 3.5″ TFT color touchscreen. It works great for promo videos, displaying gauges and other normal wearable tasks.

I always thought it would be cool to show up for one of my tech talks, remove my badge from around my neck, hook it up to the projector, plug in the keyboard/mousepad and run my slides using LibreOffice. The badge has a Raspberry Pi 3 and is a full-blown Linux machine, after all.

Making my dream come true of a wearable notebook turned out to be pretty straightforward, using a pair of scripts.

I originally set up the micro-machine for the 3.5″ TFT color LCD touchscreen using the custom Adafruit image. There’s a file called 99-fbdev.conf, that’s used to configure the X server for the LCD framebuffer. When that file is present in the /etc/X11/xorg.conf.d directory, you’ll get a little desktop on the LCD.

Without the file in /etc/X11/xorg.conf.d, it’ll default to the desktop appearing on a connected HDMI monitor. The scripts shuffle the file around and do a reboot to put the desktop on the appropriate screen.

Here’s a script to switch to the HDMI monitor, from the LCD screen.

The Desktop Appearing on the HDMI Monitor

And, here’s the one to switch back to the 3.5″ TFT display.

The Desktop Appearing on the 3.5″ TFT LCD Display

Also, you can use both displays at once. Say you have the desktop on the TFT display with the HDMI monitor connected.

Type a <ctrl> <alt> F2 to bring up a console on the HDMI monitor. Type an <alt> F7 to make the TFT active again.

Likewise, if you have the desktop on the HDMI monitor, you can type a <ctrl> <alt> F1 to bring up a console on the TFT display. Type an <alt> F7 to get back to the HDMI desktop.

Recycle to Make a Processing Sketch Work

Remember, when we built an analog gauge using data from the Arduino Pro Mini and a sketch from the Processing language? You might also recall that we had to use the stty command to configure the serial port.

I also found out that you can run a Processing sketch without going into the Processing IDE. Why not put the two together and run a cool, graphical Processing sketch from the command line, using a script. In this example, the sketch is in the standard Processing sketchbook directory. You can add in the #!/bin/bash and comments if you’d like.

It’s necessary to run Java from the processing directory, so the first line moves you there. Next, we configure the serial port with the “stty” command. Finally, the gauge shows up on the primary display (:0) using a call to Java and the gauge3 sketch name. The “–present” option, called presentation mode, runs the script in full-screen mode. To make the gauge show up in a regular desktop window (probably on the HDMI monitor), substitute “–run” in place of “–present”.

Processing Gauge in a Desktop Window on the HDMI Display

Note that we can take parts of old scripts, like the “sudo tty” line from capture-tty.sh and use them in new scripts. Be sure to reuse parts from previous efforts, whenever possible.

Wrap up

These are just a few of the wondrous things you can do with scripts. The Pi is an extremely capable Linux machine. It’s made for automation and can do many jobs at once.

String together existing commands or programs in a script and keep it simple: It’s a lot easier than writing a huge, whiz-bang program that does everything, from scratch. Take advantage of this fundamental principle of the *nix way of doing things.

Source: InApps.net

Rate this post
As a Senior Tech Enthusiast, I bring a decade of experience to the realm of tech writing, blending deep industry knowledge with a passion for storytelling. With expertise in software development to emerging tech trends like AI and IoT—my articles not only inform but also inspire. My journey in tech writing has been marked by a commitment to accuracy, clarity, and engaging storytelling, making me a trusted voice in the tech community.

Let’s create the next big thing together!

Coming together is a beginning. Keeping together is progress. Working together is success.

Let’s talk

Get a custom Proposal

Please fill in your information and your need to get a suitable solution.

    You need to enter your email to download

      Success. Downloading...