Author Archives: Shafeeque Olassery Kunnikkal

  1. Unveiling the Anavi Sensor Dashboard: Your Open-Source Environmental Monitor

    Leave a Comment

    Introduction: Bridging the Gap Between Hardware and Insight

    In an increasingly connected world, understanding our immediate environment is more important than ever. Whether for home automation, smart agriculture, or simply personal curiosity, real-time data about temperature, humidity, pressure, and light can empower better decisions. Introducing the Anavi Sensor Dashboard – a robust, customizable, and user-friendly desktop application built with Python and PyQt5, designed to bring your Anavi Technology sensor data to life.

    This dashboard transforms raw sensor readings into actionable insights, providing real-time visualizations, historical trends, and customizable alerts. It’s not just a monitoring tool; it’s a foundation for a deeper understanding of your surroundings, crafted with flexibility and expandability in mind.

    What is the Anavi Sensor Dashboard? A Deep Dive

    The Anavi Sensor Dashboard is a desktop application that interfaces with Anavi Technology’s sensor PHATs (Peripheral Hardware Attached on Top) for Raspberry Pi. It provides a rich graphical user interface (GUI) to:

    • Real-time Sensor Monitoring: Get instant readings of various parameters like temperature, humidity, atmospheric pressure, and ambient light. It specifically displays live data from connected HTU21D (Temperature, Humidity), BMP180 (Temperature, Pressure), and BH1750 (Light) sensors.
    • Visualize Historical Data: Explore trends over time with dynamic plots that can be customized to show data from the last few minutes to “All Data” collected. It offers dedicated plots for each sensor metric, with a global time range control for historical data.
    • Set Personalized Alerts: Define high and low thresholds for each sensor metric. The application provides visual and auditory cues when values fall outside your specified safe ranges.
    • Customize Your Experience: Choose from multiple gauge types (Standard, Compact, Digital, Analog, Progress Bar) and a wide array of styles (Flat, Shadowed, Raised, Inset, Heavy Border, Clean, Deep Shadow, Outline, Vintage, Subtle, Fresh, Bright, Bold) to tailor the display to your preference. It features full QSS (Qt Style Sheet) theming, including pre-configured Blue and Emerald Forest themes.
    • Log Data Reliably: All sensor readings are logged to local files, ensuring you have a persistent record of your environmental data. The logging system supports daily rotation and limits on file size and number of rotations to prevent excessive disk usage.
    • Modular Architecture: The application boasts a modular architecture, making it easily expandable with support for new sensors and UI elements.
    • Persistent Settings: Your preferences and sensor configurations are automatically saved and restored across application sessions.

    Prerequisites: Getting Started with Your Anavi Dashboard

    Hardware Requirements

    To run the Anavi Sensor Dashboard, you’ll need the following hardware components:

    • Raspberry Pi: A Raspberry Pi 4 Model B is recommended for optimal performance, especially with the graphical interface and data processing. Other Raspberry Pi models (e.g., Raspberry Pi 3 Model B+ or newer) may also work.
    • MicroSD Card: Minimum 16GB (Class 10 or faster) for the Raspberry Pi’s operating system and data storage.
    • Power Supply: A stable 5.1V, 3.0A USB-C power supply (for Raspberry Pi 4).
    • Internet Connection: Required for initial setup and software installation.
    • ANAVI Infrared pHAT: This board typically includes an onboard BH1750 Light Sensor.
    • Optional External Sensors via I2C: The application also supports external sensors like HTU21D (Temperature, Humidity) and BMP180 (Temperature, Pressure) if connected to your Raspberry Pi via the I2C interface.

    Software Requirements

    The Anavi Sensor Dashboard is built on the Python ecosystem. Here’s what you’ll need to install:

    • Python 3: Ensure Python 3 is installed (you can check with python3 --version).
    • Pip: Python’s package installer (sudo apt install python3-pip).
    • PyQt5: For the graphical user interface (sudo apt install python3-pyqt5 python3-pyqt5.qtsvg).
    • Matplotlib: For data plotting (sudo apt install python3-matplotlib).
    • NumPy: For numerical operations (sudo apt install python3-numpy).
    • smbus2 / I2C tools: For I2C communication with sensors (sudo apt install i2c-tools python3-smbus).
    • Pillow: For image processing, if required by certain UI elements or themes (pip3 install Pillow).

    Enabling I2C on your Raspberry Pi: This is crucial for sensor communication. You can enable it via the Raspberry Pi configuration tool:

    sudo raspi-config
    # Navigate to Interface Options -> I2C -> Select Yes
    sudo reboot
    

    Optional: Verify I2C sensors are detected: After rebooting, you can check if your I2C sensors are recognized:

    i2cdetect -y 1
    

    Expected sensor addresses: 0x40 (HTU21D), 0x77 (BMP180), 0x23 (BH1750).

    Installation Guide: Getting Up and Running

    Follow these steps to set up the Anavi Sensor Dashboard on your Raspberry Pi:

    Clone the Repository:git clone https://github.com/gr4ytips/Anavi.git

    cd InfraredpHAT

    Install Python Dependencies: You can install all necessary Python libraries using the requirements.txt file provided in the repository:pip3 install -r requirements.txt
    (Alternatively, you can install them manually if preferred, as listed in the Software Requirements section).

    Ensure I2C is Enabled: If you haven’t already, make sure the I2C interface is enabled on your Raspberry Pi as described in the Hardware Requirements section:

    sudo raspi-config # Interface Options -> I2C -> Yes sudo reboot

    Running the Application: Usage

    Once you have completed the installation and prerequisites, launch the application from the InfraredpHAT directory.

    python3 main.py
    

    The application will launch, displaying tabs for the dashboard, sensor details, settings, and more.

    Key Functionalities in Detail

    Real-time Monitoring & Dashboard

    The Dashboard provides an at-a-glance overview of your environment. Each sensor metric has its own Sensor Display Widget, showing the current value and its unit. A dynamic plot allows you to select which metric to view and over what time range, giving immediate visual feedback on recent changes.

    Detailed Sensor Analysis

    For a more granular view, the Sensor Details Tab dedicates larger Sensor Display Widget instances to each individual metric. Alongside these, dedicated Matplotlib Widget plots provide historical data for each sensor type (e.g., all HTU21D metrics on one plot, all BMP180 metrics on another). A global time range selector allows you to zoom into specific periods across all detail plots.

    Customizable UI: Themes and Gauges

    The Settings Tab is where the magic of customization happens.

    • Themes: You can switch between various pre-defined themes (like your blue_theme.qss and emerald_forest_theme.qss, plus the 14 new ones). These themes aren’t just for colors; they define the entire look and feel of the application elements, from buttons and text inputs to scroll bars and tab widgets.
    • Gauge Types & Styles: For each sensor display, you can choose from a variety of visual representations:
      • Standard/Compact: Classic circular or bar gauges.
      • Digital: A retro seven-segment display font for values.
      • Analog (Basic/Full): Mimicking traditional dial gauges with needles and scales.
      • Progress Bar (Horizontal/Vertical): Clear bar graphs. Each gauge type also supports different visual “styles” (e.g., Flat, Shadowed, Inset) for further aesthetic refinement.

    Threshold-based Alerts

    You can define low and high thresholds for each sensor metric in the Settings. When a sensor reading crosses these thresholds, the corresponding Sensor Display Widget will visually change (e.g., its border might turn red, its fill color might become critical), and an optional auditory alert can be triggered to draw your attention.

    Robust Data Logging

    All incoming sensor data is timestamped and written to log files in the Sensor_Logs/ directory. The application utilizes a Rotating File Handler to manage log file size, ensuring that logs don’t consume excessive disk space. Old logs are automatically archived or rotated, keeping your system tidy.

    Dynamic Plotting with Matplotlib

    The Matplotlib Widget is a custom PyQt5 widget that embeds a Matplotlib graph. It allows for dynamic updating of sensor data plots. You can interact with the plots, view legends (which are toggleable for individual series), and select different time ranges to analyze trends.

    Persistent Settings Management

    All your preferences – from selected themes and gauge types to alert thresholds and data logging options – are saved to config.ini using config parser. This ensures your customizations persist across application restarts.

    User Interface (UI Preview): A Visual Tour

    Here, you would typically insert screenshots or GIFs of your application in action. These visual aids will greatly enhance the blog post.

    Dashboard View

    Sensor Details View

    Plot View

    Settings and Configuration Tabs

    Credits & Licensing

    This application’s initial framework and a significant portion of its core logic were generated by Gemini, a large language model by Google. It has since been meticulously modified, enhanced, and refined by gr4ytips, who has integrated specific Anavi sensor functionalities, implemented advanced UI customizations, and ensured robust data handling.

    Creative License

    This work is licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0) license.

    You are free to:

    • Share — copy and redistribute the material in any medium or format
    • Adapt — remix, transform, and build upon the material for any purpose, even commercially.

    Under the following terms:

    • Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made.

    Liability

    This software is provided “as is”, without any warranty—express or implied. Use at your own risk. The authors and contributors shall not be held liable for any claims, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

    Warning

    • Double-check GPIO/I2C wiring to avoid hardware damage.
    • Use a stable power supply.
    • Ensure all software dependencies are installed.
    • Sensor data is raw and uncalibrated.
    • For long-term use, consider backups and watchdogs.

    Disclaimer

    This application is for monitoring only. Not for use in critical or life-sustaining systems.

    What’s Next for the Anavi Sensor Dashboard?

    This application is a living project, with potential for future enhancements based on user feedback and new Anavi hardware. Possible future features could include:

    • Network/Cloud Integration: Sending data to online platforms for remote monitoring and long-term storage.
    • Web Interface: A web-based interface for accessing the dashboard from any device on your local network.
    • More Sensor Support: Expanding compatibility to other Anavi PHAT sensors.
    • Advanced Data Analysis: Implementing more sophisticated data processing and predictive analytics.
    • User Management: For multi-user environments.

    Encourage you to explore the code, customize it further, and contribute to its development! Your feedback and contributions are always welcome.

    Thank you for exploring the Anavi Sensor Dashboard!

  2. Part 4: Enabling JTAG in Firmware and Using It with OpenOCD

    Leave a Comment

    Overview

    Once you’ve discovered your JTAG pins using JTAGenum, you might want to enable them in your own firmware, or use them with a tool like OpenOCD for real debugging. This part shows how to:

    1. Enable JTAG pins explicitly in your firmware (via STM32CubeMX or code)
    2. Maintain those pin functions across reboots
    3. Set up OpenOCD to use your confirmed pinout

    Why Enable JTAG in Firmware?

    On many STM32 boards, including the Black Pill:

    • The default firmware does not enable JTAG.
    • Even if pins are physically accessible, they may be set as GPIO by code.
    • If JTAG is disabled or overridden, tools like JTAGenum or OpenOCD will not connect.

    When is this needed?

    • If you’re writing your own application firmware and want to debug it via JTAG.
    • If you want your board to always be JTAG-accessible for recovery or testing.
    • If you’re building educational tools or lab setups.

    Enabling JTAG Using STM32CubeMX

    The easiest way to enable JTAG at firmware level is to configure it in STM32CubeMX:

    Steps:

    1. Open STM32CubeMX
    2. Load or create a project for STM32F411CE (or your chip)
    3. In the Pinout view:
      • Right-click on pins PA15, PB3, and PB4
      • Set them to SYS_JTDI, SYS_JTDO-SWO, and SYS_JTRST respectively
    4. Go to System Core → SYS in the Configuration panel
    5. Set Debug to Full SWJ (JTAG-DP + SW-DP)
    6. Generate code (HAL-based or LL) and open in STM32CubeIDE or your IDE

    Optional: In the generated main.c, do not change the mode of the configured pins — let the HAL handle it.


    Enabling JTAG Manually in Firmware (Bare Metal)

    If you prefer direct register-level setup:

    // Enable AFIO and remap JTAG
    RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
    AFIO->MAPR &= ~(AFIO_MAPR_SWJ_CFG);  // Clear bits
    AFIO->MAPR |= 0x00000000;            // Full JTAG enabled
    
    // Set pin modes (e.g., for PA15, PB3, PB4)
    GPIOA->CRH |= (0b1011 << 28); // PA15: AF Push-pull, 50MHz
    GPIOB->CRL |= (0b1011 << 12); // PB3: AF Push-pull, 50MHz
    GPIOB->CRL |= (0b1011 << 16); // PB4: AF Push-pull, 50MHz
    

    This ensures that JTAG pins are not accidentally reconfigured by your own firmware.


    Using OpenOCD with Discovered JTAG Pins

    Now that JTAG is confirmed and enabled, you can use OpenOCD to connect.

    Example: Custom OpenOCD Interface Config (with FTDI or Tigard)

    Create a config file blackpill-jtag.cfg:

    interface ftdi
    ftdi_vid_pid 0x0403 0x6010
    transport select jtag
    
    ftdi_layout_signal nTRST -data 0x01 -noe 0x02
    ftdi_layout_signal TCK   -data 0x04 -noe 0x08
    ftdi_layout_signal TMS   -data 0x10 -noe 0x20
    ftdi_layout_signal TDI   -data 0x40 -noe 0x80
    ftdi_layout_signal TDO   -input 1
    
    adapter_khz 1000
    

    Then run:

    openocd -f blackpill-jtag.cfg -f target/stm32f4x.cfg
    

    If the pin mappings are correct and JTAG is enabled, you should see:

    Info : JTAG tap: stm32f4.cpu tapped
    Info : stm32f4.cpu: hardware has 6 breakpoints, 4 watchpoints
    

    Final Thoughts

    • Discovering pins is just the first step.
    • For persistent and reliable use of JTAG, enable it in firmware and know how to configure your debugger.
    • This empowers you to build resilient workflows for debugging, testing, and even hardware forensics.

    That wraps up Part 4.

  3. Part 3: Interpreting Results from JTAGenum and Confirming JTAG Pins

    Leave a Comment

    Overview

    Now that you’ve wired your STM32 Black Pill to an Arduino running JTAGenum and captured output via PuTTY, it’s time to make sense of the data. This part walks you through interpreting FOUND! lines, verifying the detected pins, and locking down a reliable JTAG configuration for future debugging.


    Step 9: Understanding the Output Format

    JTAGenum tries every possible combination of pins assigned to common JTAG roles: TDI, TDO, TMS, TCK, and nTRST. When a valid combination is found, it prints a line like:

    FOUND!  ntrst:DIG_4 tck:DIG_6 tms:DIG_7 tdo:DIG_3 tdi:DIG_2  IR length: 34
    

    Here’s what it means:

    • DIG_x refers to the Arduino digital pin number.
    • IR length: 34 indicates the Instruction Register (IR) length detected on the JTAG scan chain — and confirms that a valid TAP controller responded.

    IR lengths like 4, 5, or 34 are common on STM32 microcontrollers.


    Reviewing Real Examples from Your Scan

    Let’s break down some actual outputs observed from the Black Pill while in DFU mode:

    Detected JTAG Configurations:

    Example A:

    FOUND!  ntrst:DIG_4 tck:DIG_6 tms:DIG_7 tdo:DIG_3 tdi:DIG_2  IR length: 34
    

    Example B:

    FOUND!  ntrst:DIG_5 tck:DIG_6 tms:DIG_7 tdo:DIG_3 tdi:DIG_2  IR length: 34
    

    Example C:

    FOUND!  ntrst:DIG_8 tck:DIG_6 tms:DIG_7 tdo:DIG_3 tdi:DIG_2  IR length: 34
    

    All three are valid. The only difference is the nTRST pin. This tells you:

    • TDI = D2
    • TDO = D3
    • TMS = D7
    • TCK = D6
    • nTRST = D4 or D5 or D8 — possibly optional or floating

    Tip: If you’re only using 4-wire JTAG (TCK, TMS, TDI, TDO), you can ignore nTRST. But including it can improve scan reliability.


    Mapping Detected Pins Back to STM32

    Let’s assume your earlier connections from Arduino to STM32 were:

    Arduino PinSTM32 Pin
    D2PA15
    D3PB3
    D4PB4
    D5PB13
    D6PB14
    D7PB15
    D8PA12

    Then, based on the confirmed working detection:

    • TDI = PA15
    • TDO = PB3
    • TMS = PB15
    • TCK = PB14
    • nTRST = PB4 or PB13 or PA12 (D4, D5, or D8)

    Result: You’ve successfully mapped the JTAG pins without knowing them in advance — using only multimeter tests, brute-force probing, and observation.


    Verifying JTAG Pins with Other Tools (Optional)

    To confirm these pin assignments beyond JTAGenum:

    • Use a debugger like Tigard, J-Link, or ST-Link wired to those pins.
    • Use OpenOCD with a custom interface config using those exact pins.
    • Perform a memory read or chip ID query to confirm real access.

    Summary: Final Working JTAG Pin Mapping

    JTAG SignalArduino PinSTM32 Pin
    TDID2PA15
    TDOD3PB3
    nTRSTD4/D5/D8PB4/PB13/PA12
    TCKD6PB14
    TMSD7PB15

    This is a stable configuration to use with any JTAG tool or debugger for STM32F411CE.


    Final Thoughts

    • Even if the factory firmware disables JTAG, DFU mode preserves debug pin functionality.
    • JTAGenum is a powerful tool that lets you discover pinouts with no documentation.

Categories

Tags

Archives