ATtiny212 Firmware for Distortion Pedal
7:25
Thought for 17 sec
Read K2 datasheet for pin configuration contact arrangement te.
Read U4 datasheet for pin configuration input output photorela.
Read U2 datasheet for pinout pin configuration ATtiny212 SOIC .
Read BOM.
Read schematic.
Read schematic.
Read schematic.
Read schematic.
Read schematic.
Found 1 results for Omron G6S-2F-DC5 datasheet pinout COM NC NO pins 3 4 5 8 9 10 bottom view.
Completed 3 design checks — found 141 issues.
EFFECT_OUT if PA6 is held HIGH. D2’s schematic orientation is correct: cathode/stripe to +5V, anode to RELAY_COIL_NEG.Schematic-Derived Pin Mapping
| Function | Schematic signal path | ATtiny212 pin | Arduino / megaTinyCore symbol | Direction | Active level | Notes |
|---|---|---|---|---|---|---|
| Footswitch input | FOOT_SW_NODE → U2 PA3 | physical pin 7 | PIN_PA3 | Input | Active LOW | Assumes the footswitch shorts this node to GND when pressed. Firmware enables internal pull-up. |
| Relay driver control | U2 PA1 → R4 4.7 kΩ → Q2 BASE; Q2 COLLECTOR → relay coil negative node / RELAY_COIL_NEG | physical pin 4 | PIN_PA1 | Output | Active HIGH at PA1 | PA1 HIGH drives Q2 on, pulling RELAY_COIL_NEG low and energizing the relay coil. PA1 LOW leaves relay off. |
| LED indicator | U2 PA2 → D1 pin 1; D1 pin 2 → R2 2.2 kΩ → +5V | physical pin 5 | PIN_PA2 | Output | Active LOW | LED appears wired from +5 V through R2/D1 into the MCU pin, so the MCU sinks current to turn it on. If the LED is physically reversed, change LED_ACTIVE_LEVEL to HIGH. |
| Anti-pop photorelay input | U2 PA6 → R3 1.2 kΩ → U4 A | physical pin 2 | PIN_PA6 | Output | Not used by requested function | Left off by this firmware unless you choose to add mute timing later. |
| UPDI / reset | U2 ~RESET~/PA0 → PA0/UPDI header/net | physical pin 6 | PIN_PA0 | Programming / reset | N/A | Do not use as a normal GPIO unless you intentionally disable UPDI/reset behavior. |
| Power | U2 VCC → +5V; U2 GND → GND | pins 1, 8 | N/A | Power | N/A | Logic supply is +5 V. |
distortion_relay_bypass_attiny212.ino:Cpp
/* Distortion Effect Pedal Relay Bypass Firmware MCU: ATtiny212 (U2, ATTINY212-SSN) Core: Arduino IDE + megaTinyCore Schematic-derived connections: FOOT_SW_NODE -> U2 PA3, physical pin 7, active LOW input with pull-up Relay driver input -> U2 PA1 through R4 to Q2 base RELAY_COIL_NEG -> Q2 collector / relay coil negative, pulled LOW when Q2 is ON LED indicator -> U2 PA2 to D1, with R2 to +5V; assumed active LOW Power-up state: Effect OFF / bypass / relay OFF / LED OFF */ #include <Arduino.h> // ─── Pin Definitions — from schematic ───────────────────────────── constexpr uint8_t FOOTSWITCH_PIN = PIN_PA3; // U2 PA3, physical pin 7, FOOT_SW_NODE constexpr uint8_t RELAY_DRIVE_PIN = PIN_PA1; // U2 PA1, physical pin 4, drives Q2 base via R4 constexpr uint8_t LED_PIN = PIN_PA2; // U2 PA2, physical pin 5, D1 indicator LED constexpr uint8_t MUTE_PHOTORELAY_PIN = PIN_PA6; // U2 PA6, physical pin 2, U4 input via R3; unused here // ─── Active Levels ──────────────────────────────────────────────── constexpr uint8_t FOOTSWITCH_PRESSED_LEVEL = LOW; // switch assumed to pull FOOT_SW_NODE to GND constexpr uint8_t RELAY_ON_LEVEL = HIGH; // PA1 HIGH turns Q2 on and energizes relay constexpr uint8_t RELAY_OFF_LEVEL = LOW; // LED appears connected from +5V through R2/D1 into PA2, so PA2 sinks current when LOW. constexpr uint8_t LED_ACTIVE_LEVEL = LOW; constexpr uint8_t LED_INACTIVE_LEVEL = HIGH; // Optional anti-pop photorelay is left off. Adjust if you later add mute timing. constexpr uint8_t MUTE_INACTIVE_LEVEL = LOW; // ─── Debounce Configuration ─────────────────────────────────────── constexpr unsigned long DEBOUNCE_TIME_MS = 40; // requested 30–50 ms range // ─── State Variables ────────────────────────────────────────────── bool effectOn = false; uint8_t lastRawFootswitchLevel = HIGH; uint8_t debouncedFootswitchLevel = HIGH; unsigned long lastDebounceChangeMs = 0; // ─── Output Helpers ─────────────────────────────────────────────── void applyEffectState() { if (effectOn) { // Effect ON: energize relay so audio path switches to distortion circuit. digitalWrite(RELAY_DRIVE_PIN, RELAY_ON_LEVEL); digitalWrite(LED_PIN, LED_ACTIVE_LEVEL); } else { // Effect OFF: relay off, bypass mode. digitalWrite(RELAY_DRIVE_PIN, RELAY_OFF_LEVEL); digitalWrite(LED_PIN, LED_INACTIVE_LEVEL); } } void setDefaultBypassState() { effectOn = false; applyEffectState(); } // ─── Setup ──────────────────────────────────────────────────────── void setup() { // Configure outputs first and force safe defaults before enabling input logic. pinMode(RELAY_DRIVE_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT); pinMode(MUTE_PHOTORELAY_PIN, OUTPUT); digitalWrite(MUTE_PHOTORELAY_PIN, MUTE_INACTIVE_LEVEL); setDefaultBypassState(); // Footswitch input uses internal pull-up because the switch is assumed to pull to GND. pinMode(FOOTSWITCH_PIN, INPUT_PULLUP); // Initialize debounce state from the current input level. lastRawFootswitchLevel = digitalRead(FOOTSWITCH_PIN); debouncedFootswitchLevel = lastRawFootswitchLevel; lastDebounceChangeMs = millis(); } // ─── Main Loop ──────────────────────────────────────────────────── void loop() { const unsigned long nowMs = millis(); const uint8_t rawLevel = digitalRead(FOOTSWITCH_PIN); // If the raw input changed, restart debounce timing. if (rawLevel != lastRawFootswitchLevel) { lastRawFootswitchLevel = rawLevel; lastDebounceChangeMs = nowMs; } // Accept a new stable input state after debounce time has elapsed. if ((nowMs - lastDebounceChangeMs) >= DEBOUNCE_TIME_MS && rawLevel != debouncedFootswitchLevel) { debouncedFootswitchLevel = rawLevel; // Toggle only on the transition to the pressed state. // This prevents repeated toggles while the switch is held. if (debouncedFootswitchLevel == FOOTSWITCH_PRESSED_LEVEL) { effectOn = !effectOn; applyEffectState(); } } }
FOOT_SW_NODE at U2 PA3, but only firmware-level behavior can confirm the external footswitch polarity. If the switch does not pull to ground, change pinMode(FOOTSWITCH_PIN, INPUT_PULLUP) and FOOTSWITCH_PRESSED_LEVEL accordingly.RELAY_COIL_NEG is not directly driven by U2; it is the relay coil low-side node at Q2 collector. U2 drives Q2 through PA1/R4, so the correct firmware output is PA1, active HIGH.+5V and D1 then connects to PA2. If testing shows inverted LED behavior, swap LED_ACTIVE_LEVEL and LED_INACTIVE_LEVEL.Welcome 👋
Flux accelerates your PCB design with AI.
Create your account to start using this component and bring your ideas to life.