Button Debouncing Upgrade with SCPI Communication

This document introduces button debounce techniques combined with Red Pitaya SCPI control.
You’ll see how to:
  • Use UART (wired serial) or Wi-Fi to communicate with Red Pitaya
  • Combine hardware + software debounce for clean button inputs
  • Drive Red Pitaya’s onboard LED0 via SCPI

1) Prerequisites

  • Red Pitaya with SCPI server running
    • Start it from web UI (Development → SCPI → RUN)
    • Or via SSH:
      • systemctl start redpitaya_scpi
  • Arduino IDE 2.x installed
  • Hardware:
    • Pushbutton
    • 10 kΩ resistor (pull-down)
    • 0.1 µF capacitor (RC hardware debounce)

2) UART Example (Button Debounce → LED0)

Wiring
  • Arduino TX → Red Pitaya RX
  • Arduino RX → Red Pitaya TX
  • Shared GND
  • Logic at 3.3 V
  • Button with pull-down resistor and capacitor for hardware debounce
Code
#include <Arduino.h> #include "SCPI_RP.h" #if defined(ARDUINO_ARCH_AVR) #include <SoftwareSerial.h> SoftwareSerial uart(8, 9); // RX=8, TX=9 for UART SCPI #endif scpi_rp::SCPIRedPitaya rp; uint8_t led_state = 1; void setup() { #if defined(ARDUINO_ARCH_AVR) uart.begin(RED_PITAYA_UART_RATE); rp.initStream(&uart); #elif defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD) || \ defined(ARDUINO_ARCH_SAM) Serial1.begin(RED_PITAYA_UART_RATE); rp.initStream(&Serial1); #endif rp.dio.reset(); // Reset all DIOs } void loop() { rp.dio.state((scpi_rp::EDIOPin)(led_state), 1); // Turn LED on delay(1000); rp.dio.state((scpi_rp::EDIOPin)(led_state), 0); // Turn LED off led_state++; if (led_state == 8) led_state = 0; // Loop back }

3) Wi-Fi Example (Button Debounce → LED0)

Setup arduino_secrets.h
#define SECRET_SSID "YourWiFiSSID" #define SECRET_PASS "YourWiFiPassword" #define SECRET_RP_IP "192.168.1.42" // or rp-xxxxxx.local #define SECRET_RP_PORT 5025
Code
#include "wifiSCPI.h" #include "arduino_secrets.h" // WiFi + Red Pitaya settings WifiSCPI rp; const int buttonPin = 2; int stableState = HIGH; int lastReading = HIGH; unsigned long lastDebounce = 0; const unsigned long debounceDelay = 50; // ms void setup() { Serial.begin(115200); pinMode(buttonPin, INPUT_PULLUP); // Connect to Wi-Fi and Red Pitaya rp.begin(SECRET_SSID, SECRET_PASS, SECRET_RP_IP, SECRET_RP_PORT); // Configure LED0 as output rp.scpi("DIG:PIN:DIR LED0,OUT"); } void loop() { int reading = digitalRead(buttonPin); if (reading != lastReading) { lastDebounce = millis(); } if ((millis() - lastDebounce) > debounceDelay && reading != stableState) { stableState = reading; // LOW = button pressed rp.scpi(String("DIG:PIN LED0,") + (stableState == LOW ? "1" : "0")); } lastReading = reading; }

4) Debounce Strategy

  • Hardware debounce:
    • 10 kΩ pull-down resistor + 0.1 µF capacitor smooth out button bounce
  • Software debounce:
    • millis()based timer ensures only clean transitions are acted upon
    • Avoids blocking delays

5) Visual Verification

Use Red Pitaya’s Oscilloscope app to probe the button node:
  • Raw button signal (bouncy edges)
  • Hardware-debounced signal (smoother)
  • Final software-debounced toggling
This lets you compare real hardware vs. clean SCPI-driven LED toggling.

6) Troubleshooting

  • UART not working
    • Ensure correct TX/RX crossover and 3.3 V logic
    • Use Serial1 (hardware UART) where available; avoid high-baud SoftwareSerial
  • Wi-Fi connection fails
    • Verify SSID/password in arduino_secrets.h
    • Test Red Pitaya IP with ping
  • LED0 does not toggle
    • Confirm SCPI server is running (systemctl status redpitaya_scpi)
    • Try port 5025 or 5000 depending on OS version
  • Oscilloscope app + SCPI conflicts
    • Avoid running heavy web apps while using SCPI (they share FPGA/DSP resources)