Project Overview
This week I worked with output devices, building on the MQ-3 scent sensor input device from
Week 8 to create a complete input-to-output system for my
final project: a "digital nose" capable of sensing and differentiating incense aromas. I integrated a simple screen/display as an output device to visually predict and display what scent is being detected in real-time. The system reads sensor data from the MQ-3 input device and outputs predictions to a terminal-style display, creating a complete sensing and feedback loop. Central to this work is the mathematical model of the
Genji-Mon pattern, which provides the foundational framework for organizing and classifying scent predictions based on traditional Genji Ko incense sequences.
The Output Device: Simple Screen/Display
I implemented a simple screen/display output device to visualize the scent predictions from the MQ-3 sensor. The display shows a terminal-style interface that presents real-time predictions of what scent is being detected. The output device connects to the SAMD21 microcontroller via serial communication, receiving processed sensor data and displaying formatted predictions. This simple screen setup provides immediate visual feedback about the detected scents, making the sensing system more interactive and user-friendly.
Input-to-Output System Integration
Building on the MQ-3 input device from Week 8, I created a complete input-to-output pipeline. The system works by:
1. Input Stage: The MQ-3 sensor (from Week 8) continuously reads analog signals representing gas concentrations
2. Processing Stage: The SAMD21 microcontroller processes the analog sensor data, converts it to digital values, and runs pattern recognition algorithms to identify scent patterns
3. Output Stage: The processed predictions are sent to the display output device, which shows a terminal-style visualization of the predicted scent in real-time
This creates a complete feedback loop where the input device (sensor) feeds data to the output device (screen), enabling real-time scent detection and visualization.
Display Implementation
The output device implementation uses a simple screen connected via USB/Serial to display terminal-style predictions. The display shows:
- Real-time sensor readings from the MQ-3 input device
- Predicted scent classifications based on sensor patterns, organized using the Genji-Mon mathematical model
- Genji Ko sequence identification (mapped to bell number partitions)
- Confidence levels for each prediction
- Mathematical model parameters (bell number partition index, sequence mapping)
- Timestamp and sensor status information
The terminal interface provides a clean, text-based visualization that makes it easy to see what the system is detecting. The output updates in real-time as new sensor data comes in from the input device, and the Genji-Mon mathematical model ensures that predictions are displayed in a structured, culturally meaningful format. This creates a responsive feedback system that bridges traditional Japanese incense ceremony sequences with modern sensor technology.
The Genji-Mon Mathematical Model and Pattern Recognition
Mathematical analysis of Genji Mon pattern showing the underlying geometric principles and bell number relationships. This mathematical model from Week 1 provides the foundational framework for organizing scent predictions into Genji Ko sequences in the output device display.
Central to this week's output device implementation is the mathematical model of the Genji-Mon pattern, which provides the structural framework for organizing scent predictions. The Genji-Mon (源氏紋) pattern has deep mathematical foundations based on bell number relationships, as documented in
Week 1's CAD work. This mathematical structure enables the system to map sensor data to traditional Genji Ko incense sequences.
Mathematical Foundation:
The Genji-Mon pattern is mathematically structured using bell numbers, which represent the number of ways to partition a set. In the context of traditional Genji Ko incense ceremonies, this mathematical model maps to the 6 different incense sequences that can be identified. The bell number relationship provides a combinatorial framework that organizes the possible scent classifications systematically.
Pattern Recognition Algorithm:
The system uses the clustering and pattern recognition data collected from Week 8's input device testing, combined with the Genji-Mon mathematical model. Based on the sensor response patterns that were identified during input device validation, the system maps detected scents to the Genji Ko incense sequences using the mathematical structure. The output device displays these predictions, showing classifications like:
- "Genji Ko Sequence 1" with confidence percentage (mapped to bell number partition 1)
- "Genji Ko Sequence 2" with confidence percentage (mapped to bell number partition 2)
- "Genji Ko Sequence 3" with confidence percentage (mapped to bell number partition 3)
- ... (up to 6 different sequences)
- "Unknown/Ambient" when patterns don't match known Genji Ko sequences
The prediction algorithm compares incoming sensor data from the input device against the learned patterns from Week 8, then uses the Genji-Mon mathematical model to map the sensor response to the appropriate Genji Ko sequence classification. This mapping is then output to the display screen, creating a bridge between traditional Japanese incense ceremony sequences and modern sensor-based detection.
Mathematical Model Implementation:
The bell number relationships in the Genji-Mon pattern provide a natural way to organize the 6 different incense sequences. Each detected scent pattern is analyzed and classified according to its position in the mathematical structure, ensuring that the output device displays predictions that are both scientifically accurate and culturally meaningful. This mathematical model ensures consistency in classification and provides a systematic framework for expanding the system to recognize additional scent types in the future.
Programmatic Generation of Genji-Mon Patterns
To draw Genji-mon programmatically, we use a standard recursive algorithm to generate all possible partitions for a set of five elements. This mathematical foundation enables the system to systematically organize scent classifications. The algorithms and mathematical models described below are based on the work of Oran Looney in his comprehensive analysis of Genji-kō mathematics and programmatic generation.
Recursive Partition Algorithm:
def partitions(s: Set[int]) -> Iterator[List[Set[int]]]:
"""Yield all partitions of a set as they are generated."""
if not s:
yield []
return
first = next(iter(s))
rest = s - {first}
for partition in partitions(rest):
yield [{first}] + partition
for i in range(len(partition)):
new_partition = (
partition[:i] +
[partition[i] | {first}] + partition[i+1:]
)
yield new_partition
However, the partition alone does not suffice to fully characterize a Genji-mon. While we must draw overlapping groups at different heights to avoid ambiguity, there is still a free choice about which groups we make taller. After studying the chart of traditional Genji-mon, two rules became clear:
1.
Groups should be as tall as possible.
2.
Groups entirely inside other groups should be lower and appear to nest inside the outer group.
This is implemented as a simple brute-force cost-based optimizer, because that made it easy to experiment with different rules:
def optimal_genjiko_for_partition(
partition: List[Set[int]]
) -> List[Tuple[float, Set[int]]]:
"""
Given a partition, find the optimal Genji-kō layout by minimizing a cost
function.
"""
best_cost = math.inf
best_genjiko = None
HEIGHTS = [1.0, 0.8, 0.6]
# Generate all possible combinations of heights
for height_combo in itertools.product(HEIGHTS, repeat=len(partition)):
genjiko_candidate = [
(height, group)
for height, group
in zip(height_combo, partition)
]
# Skip invalid configurations
if not validate_genjiko(genjiko_candidate):
continue
# Encourage larger heights
cost = -sum(height for height, _ in genjiko_candidate)
for height1, group1 in genjiko_candidate:
for height2, group2 in genjiko_candidate:
# Large penalty for higher inner group height
if is_nested_within(group1, group2) and height1 > height2:
cost += 1
# keep track of the best solution so far
if cost < best_cost:
best_cost = cost
best_genjiko = genjiko_candidate
return best_genjiko
Genji-mon Order:
The Genji-mon patterns were not arranged in any particularly logical order. While there is an overall trend from many to fewer groups, there are cases where the order is clearly arbitrary. However, the association between the 52 patterns and chapter titles for chapters 2-53 of the Tale of Genji seems consistent for centuries. The order of the chapters is mostly consistent across sources, so the Genji-mon are organized in chapter order following traditional sources.
Special Cases:
There are four special cases where the algorithmic "optimal" layout fails to reproduce the traditional design. These require manual specification:
# Suma: {1, 3, 4} should be lower than {2, 5}
df.at[10, "Layout"] = [ (0.8, {1, 3, 4}), (1.0, {2, 5}) ]
# Hatsune: {1, 3} should be lower than {2, 4}
df.at[21, "Layout"] = [ (0.8, {1, 3}), (1.0, {2, 4}), (1.0, {5}) ]
# Yugiri: {1, 4} should be lower than {3, 5}, and {2} even lower.
df.at[37, "Layout"] = [ (0.8, {1, 4}), (0.6, {2}), (1.0, {3, 5}) ]
# Nioumiya: {1, 2, 4} should be lower than {3, 5}
df.at[40, "Layout"] = [ (0.8, {1, 2, 4}), (1.0, {3, 5}) ]
Historical Genji-Kō Output:
Historical output showing algorithmically generated Genji-mon patterns using the recursive partition algorithm and optimization function. This demonstrates the systematic generation of all possible Genji-Kō patterns organized according to the mathematical model.
This mathematical framework provides the foundation for mapping sensor data to Genji Ko sequences in the output device. The recursive partition algorithm generates all possible classifications, and the optimization function ensures that the displayed sequences follow traditional Genji-mon layout principles.
Mathematical Model Attribution:
The algorithms, mathematical models, and code implementations for programmatic generation of Genji-mon patterns are based on the work of Oran Looney in his article "The Art and Mathematics of Genji-Kō" published in November 2024. The recursive partition algorithm, optimization function, and analysis of special cases are derived from his comprehensive mathematical treatment of Genji-kō notation and pattern generation.
Source: Looney, Oran. "The Art and Mathematics of Genji-Kō." https://www.oranlooney.com/post/genji-ko/ (November 26, 2024).
System Architecture
The complete system architecture connects input and output devices:
Hardware Components:
- MQ-3 Gas Sensor (Input Device - from Week 8)
- SAMD21 Microcontroller (Processing)
- Display Screen/Serial Monitor (Output Device)
- USB Connection (Data Communication)
Software Pipeline:
1. Sensor reading loop (Input Device)
2. ADC conversion and data processing
3. Pattern matching using Week 8's clustering data
4. Genji-Mon mathematical model application (bell number mapping to Genji Ko sequences)
5. Classification assignment to Genji Ko sequence
6. Format output for display with mathematical model parameters
7. Send to output device (Screen)
8. Display terminal visualization showing Genji Ko sequence predictions
Future Development:
We are currently working on a combined PCB design that integrates both the input (MQ-3 sensor) and output (display) devices on a single board. While this integrated design is still in development, we are documenting the input and output devices separately for clarity in Week 8 and Week 9. The combined PCB will eventually streamline the system by reducing the number of separate components and connections needed.
This architecture demonstrates how input and output devices work together to create an interactive sensing system.
Images
Reference Sensor to PCB Board Design (Week 8 Foundation)
Reference board with SAMD21 microcontroller and MQ-3 input sensor used as design foundation for the Week 8 input device. This reference board validated the sensor concept before fabricating the custom PCB.
Close-up view of reference board showing component layout and input device circuit design details
PCB Design Process
PCB editor showing the complete board layout with SAMD21 microcontroller, MQ-3 input sensor connections, and component placement. This design was the foundation for the input device PCB from Week 8.
Completed MQ-3 input sensor PCB with SAMD21 microcontroller from Week 8 - ready for component population and input device testing. This board serves as the input foundation for the Week 9 output device system.
Gas Sample Measurement and Analysis
Real-time sensor data collection from reference board showing analog readings and response patterns from the MQ-3 sensor. The graph displays measured gas sample responses for different aromatic sources (incense, alcohol, clean air), demonstrating distinct patterns for each source type.
AI clustering analysis results showing distinct patterns in sensor responses - demonstrating potential for incense classification. The clustering analysis validates that different aromas produce distinguishable patterns, which form the basis for the Genji-Kō sequence mapping in the output device.
Combined Input-Output PCB (Work in Progress)
New PCB design combining both input (MQ-3 sensor) and output (display) devices on a single board. This integrated design is currently in development - for now, we are documenting the input and output devices separately, but this shows the future direction of the system.
PCB Details: Display Side and Sensor Side
Display side of the combined PCB showing the output device components and connections
Sensor side of the combined PCB showing the MQ-3 input device and related sensor circuitry
Challenges and Solutions
One of the main challenges was synchronizing the input device data with the output device display. The MQ-3 sensor from Week 8 produces analog readings that need to be processed and formatted before being sent to the display. I had to ensure that:
- The sampling rate of the input device matched the refresh rate of the output device
- The data processing didn't introduce delays that would make the display feel unresponsive
- The terminal output formatting was clear and readable
- The prediction algorithm could run in real-time without blocking the display updates
I solved this by implementing a buffered data processing approach where sensor readings from the input device are collected in a buffer, processed asynchronously, and then formatted for display output. This ensures smooth updates on the output device while maintaining real-time responsiveness.
Testing and Validation
I tested the complete input-to-output system by exposing the MQ-3 input device (from Week 8) to different scents and observing the output device predictions. The system successfully:
- Read sensor data from the input device in real-time
- Processed the data and generated predictions
- Displayed predictions on the output device screen
- Updated predictions as different scents were introduced
- Showed appropriate confidence levels for each prediction
The output device provided clear visual feedback that matched the expected scent classifications, validating that the input-to-output pipeline works correctly.
Reflection
This week's work on output devices brought together the input device from Week 8 to create a complete interactive system, with the mathematical model of the Genji-Mon pattern serving as the foundational framework. Working with a simple screen/display as an output device demonstrated how output devices can provide valuable feedback and make sensing systems more usable. The terminal-style visualization made it easy to see what the system was detecting in real-time, turning the abstract sensor data into meaningful information organized through the mathematical structure.
The integration of the Genji-Mon mathematical model was particularly significant. The bell number relationships provide a natural combinatorial framework for organizing the 6 different Genji Ko incense sequences, creating a systematic way to map sensor responses to traditional classifications. This mathematical foundation ensures that the output device displays predictions that are both scientifically rigorous and culturally meaningful, bridging the gap between traditional Japanese incense ceremony sequences and modern sensor-based detection technology.
The integration of input and output devices showed how different components work together to create a complete system. The MQ-3 input device captures environmental data, the microcontroller processes it using the Genji-Mon mathematical model, and the display output device presents it in a human-readable format organized by Genji Ko sequences. This creates a feedback loop where the system can provide immediate information about what it's sensing, all structured through the mathematical framework of the Genji-Mon pattern.
Building on Week 8's input device work and Week 1's mathematical analysis of the Genji-Mon pattern, this week's output device implementation completes the sensing and feedback pipeline. The simple screen setup provides a foundation that can be expanded with more sophisticated displays, graphical interfaces, or other output modalities. Combined with the input device from Week 8 and the mathematical model from Week 1, this creates a working prototype of the digital nose system that can sense scents and display predictions organized through traditional Genji Ko sequences.
This assignment emphasized the importance of mathematical models in organizing output device displays. The Genji-Mon pattern's bell number structure provides a natural way to systematically classify and display scent predictions, making the output more meaningful and culturally connected. Without the mathematical model, the predictions would be arbitrary classifications - with it, they connect to centuries of Japanese incense ceremony tradition. The terminal-style interface provides a simple but effective way to visualize the system's predictions, demonstrating how mathematical models can significantly enhance both the functionality and cultural relevance of output devices.
Acknowledgments:
The mathematical algorithms and programmatic generation methods for Genji-mon patterns are based on the work of Oran Looney in his article "The Art and Mathematics of Genji-Kō" (
https://www.oranlooney.com/post/genji-ko/). The recursive partition algorithm, optimization function, and analysis of special cases used in this project are derived from his comprehensive mathematical treatment of Genji-kō notation and pattern generation.
Note: This assignment documentation website was created with assistance from Cursor AI.
Attachments
Links