Skip to content

Options.md

Trent M. Wyatt edited this page Apr 21, 2025 · 1 revision

Options

Ready to tweak Bang to fit your Arduino’s command-line domination? This page covers the configuration options for Bang, letting you fine-tune Serial-USB communication, arduino_exec.py, and the Bang class for your ! (shell), & (sketch uploads), and @ (macro) commands. From baud rates to macro setups, these settings keep your Arduino lean and mean while maximizing flexibility. Let’s crank up the power and make Bang your own!

Overview

  • Purpose: Configure Bang’s behavior on Arduino and host.
  • Components:
    • Arduino Side: Bang class stream setup (single/dual streams).
    • Host Side: arduino_exec.py options (baud rate, serial port, macro dictionary).
  • Key Options:
    • Serial baud rate (default: 38400).
    • Serial port selection.
    • Single vs. dual stream setup.
    • Predefined macros in arduino_exec.py.

Configuration Options

1. Serial Baud Rate

  • Description: Sets the Serial-USB communication speed between Arduino and host.

  • Default: 38400 baud.

  • Arduino Side:

    • Set in sketch:

      void setup() {
          Serial.begin(38400); // Change to 9600, 115200, etc.
          while (!Serial) ;
      }
  • Host Side:

    • Match in arduino_exec.py:
      • macOS/Linux:

        sudo python3 arduino_exec.py -p /dev/cu.usbserial-00100 -b 38400
      • Windows:

        sudo python3 arduino_exec.py -p COM3 -b 38400

        Run PowerShell as administrator.

    • Use -b to change (e.g., -b 9600).
  • Tip: Ensure Arduino and arduino_exec.py use the same baud rate.

2. Serial Port

  • Description: Specifies the Serial-USB port for Arduino-host communication.

  • Default: Depends on system (e.g., /dev/cu.usbserial-00100 on macOS/Linux, COM3 on Windows).

  • Arduino Side:

    • Set in Arduino IDE (Tools > Port) or sketch for dual streams:

      SoftwareSerial cmd_serial(10, 11); // RX, TX for FTDI module
      Bang bang(cmd_serial, Serial);
      cmd_serial.begin(38400);
  • Host Side:

    • Set in arduino_exec.py:
      • macOS/Linux:

        sudo python3 arduino_exec.py -p /dev/cu.usbserial-00100 -b 38400
      • Windows:

        sudo python3 arduino_exec.py -p COM3 -b 38400

        Run PowerShell as administrator.

    • Find port:
      • macOS/Linux: ls /dev/cu.* or ls /dev/tty.*.
      • Windows: Check Device Manager for COM ports.

3. Single vs. Dual Streams

  • Description: Configures whether Bang uses one stream (Serial) or two (e.g., SoftwareSerial + Serial).

  • Default: Single stream (Bang bang(Serial);).

  • Single Stream:

    #include <Bang.h>
    Bang bang(Serial); // Commands and output via Serial
  • Dual Streams (e.g., with FTDI module):

    #include <SoftwareSerial.h>
    SoftwareSerial cmd_serial(10, 11); // RX, TX
    Bang bang(cmd_serial, Serial); // Commands via cmd_serial, output via Serial
  • Tip: Use dual streams for separate command/output channels, but single stream is simpler.

4. Predefined Macros

  • Description: Sets initial macros in arduino_exec.py’s in-memory macros dictionary.

  • Default: Empty dictionary (macros = {}).

  • Configuration:

    • Add to arduino_exec.py:

      macros = {
          'play': 'osascript -e "tell application \"Music\" to play"',
          'pause': 'osascript -e "tell application \"Music\" to pause"',
          'weather': 'curl wttr.in?format=3'
      }
  • Dynamic Management:

    • Add: BANG("@add_macro:reboot:reboot").
    • Delete: BANG("@delete_macro:reboot").
    • List: BANG("@list_macros").
  • Note: Macros reset on arduino_exec.py restart (no file-based storage).

  • Tip: Predefine common macros to save Arduino commands.

Applying Changes

  • Arduino:
    • Update sketch with new baud rate or stream setup.
    • Upload via Arduino IDE (Tools > Upload).
  • Host:
    • Stop arduino_exec.py (Ctrl+C).
    • Edit for macros or options.
    • Restart:
      • macOS/Linux:

        sudo python3 arduino_exec.py -p /dev/cu.usbserial-00100 -b 38400
      • Windows:

        sudo python3 arduino_exec.py -p COM3 -b 38400

        Run PowerShell as administrator.

Troubleshooting

  • Baud Mismatch: Ensure Arduino and arduino_exec.py use the same baud rate.
  • Wrong Port: Verify port in Arduino IDE and arduino_exec.py.
  • Macro Reset: Redefine macros after restarting arduino_exec.py.
  • See Troubleshooting for more fixes.

Next Steps

  • Check Performance for optimizing Bang.
  • Explore Examples for configured sketches.
  • See FAQ for option questions.

Back to Home | Next: Performance

Clone this wiki locally