embedded-c
C/C++ for embedded systems: microcontrollers, IoT, resource optimization
What this skill does
# embedded-c
## Purpose
This skill provides expertise in C/C++ programming for embedded systems, focusing on microcontrollers (e.g., Arduino, STM32) and IoT devices, emphasizing resource optimization like low memory usage and power efficiency.
## When to Use
Use this skill for developing firmware, handling hardware interactions (e.g., sensors, actuators), or optimizing code for constrained environments. Apply it when building IoT prototypes, debugging real-time systems, or integrating with hardware like ESP8266 for wireless connectivity.
## Key Capabilities
- Generate C/C++ code for GPIO control, timers, and interrupts, e.g., setting up a PWM signal on a microcontroller.
- Optimize code for resource constraints, such as reducing stack usage or minimizing flash memory footprint.
- Handle communication protocols like I2C, SPI, or UART in embedded contexts.
- Provide best practices for error-free coding in low-level environments, including volatile keyword usage for hardware registers.
## Usage Patterns
Prompt the AI with specific, actionable requests: "Write a C function to read temperature from an LM35 sensor on an AVR microcontroller." Structure prompts to include hardware details, e.g., "For ESP32, generate code to connect to WiFi and send HTTP requests." Always specify optimization goals, like "Ensure the code uses less than 1KB of RAM." Chain prompts for iterative development: first, generate code; then, refine for bugs.
## Common Commands/API
Use GCC for compilation with flags like `-Os` for optimization and `-mmcu=atmega328p` for AVR targets. For API examples:
- Include headers: `#include <avr/io.h>` for AVR microcontrollers.
- Code snippet for blinking an LED:
```
DDRB |= (1 << PB5); // Set PB5 as output
while(1) { PORTB ^= (1 << PB5); _delay_ms(1000); }
```
- For IoT, use ESP-IDF API: `esp_wifi_init(&config);` to initialize Wi-Fi.
- Config formats: JSON for IoT device configs, e.g., `{"ssid": "myNetwork", "password": "$WIFI_PASSWORD"}`, loaded via `nvs_set_str()` in ESP32 code.
- If API keys are needed (e.g., for cloud services), set env vars like `$AWS_IOT_KEY` and access via `getenv("AWS_IOT_KEY")` in code.
## Integration Notes
Integrate this skill with development tools by setting up environments: Install GCC and tools like avrdude for flashing. For IoT, use PlatformIO or Arduino IDE. Authenticate with services using env vars, e.g., export `$AZURE_IOT_HUB_KEY` for Azure integration. Link code with libraries via `#pragma once` guards or CMake for cross-compilation. Test on emulators like QEMU for ARM before hardware deployment. Ensure compatibility by specifying board types in prompts, e.g., "Adapt this code for STM32F4."
## Error Handling
Always check return values in embedded code, e.g., if (`i2c_read() != 0`) { handle_error(); }. Use asserts for debugging: `#include <assert.h>` and `assert(pin >= 0);`. For C++, catch exceptions in main loops: try { setup_hardware(); } catch (...) { reset_device(); }. Handle hardware failures by implementing watchdogs, e.g., `wdt_enable(WDTO_8S);` in AVR. Log errors via UART: printf("Error: Sensor timeout\n"); and use finite state machines to recover from faults.
## Concrete Usage Examples
1. Example: Write code for an Arduino Uno to read a button and toggle an LED. Prompt: "Generate C++ code for Arduino Uno: Read digital input on pin 2 and toggle pin 13 LED." Result: Use `pinMode(2, INPUT);` and in loop: `if (digitalRead(2) == HIGH) { digitalWrite(13, !digitalRead(13)); delay(50); }`.
2. Example: Optimize IoT code for ESP32 to send sensor data to a server. Prompt: "Write efficient C code for ESP32 to read DHT11 sensor and POST data to http://example.com via WiFi, using less than 10KB RAM." Result: Include `dht.h`; use `esp_http_client_init()`; snippet: `float temp = dht_readTemperature(); http_post_data(temp);`.
## Graph Relationships
- Related to cluster: iot
- Shares tags: iot, embedded
- Connected skills: potentially other iot cluster skills like "wireless-protocols" or "sensor-integration" based on common tags
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.