### Complete Application Example - Battery Status Display (Arduino C++) Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt This C++ code implements a complete application for the Arduino Nesso N1. It initializes the display, battery module, and an LED, then continuously updates a sprite on the display with battery voltage and uptime. The battery voltage is color-coded (green, orange, red) based on its level. Dependencies include Arduino_Nesso_N1.h, which handles the hardware abstraction, and implicitly M5GFX for display operations. ```cpp #include NessoBattery battery; NessoDisplay display; LGFX_Sprite statusSprite(&display); const uint16_t COLOR_TEAL = 0x0410; const uint16_t COLOR_BLACK = 0x0000; const uint16_t COLOR_GREEN = 0x1e85; const uint16_t COLOR_ORANGE = 0xed03; const uint16_t COLOR_RED = 0xe841; float batteryVoltage = 0.0; bool ledStatus = false; unsigned long lastUpdate = 0; char uptimeString[32]; void setup() { Serial.begin(115200); // Initialize display display.begin(); display.setRotation(1); display.setEpdMode(epd_mode_t::epd_fastest); display.fillScreen(TFT_WHITE); display.setTextColor(COLOR_TEAL); display.setTextSize(5); display.drawString("Nesso N1", 6, 11); // Initialize battery management battery.begin(); battery.enableCharge(); // Configure LED pinMode(LED_BUILTIN, OUTPUT); // Create sprite for status display statusSprite.createSprite(240, 81); lastUpdate = millis(); } void loop() { unsigned long now = millis(); // Read battery status float chargeLevel = battery.getChargeLevel(); batteryVoltage = battery.getVoltage(); float current = battery.getCurrent(); // Update LED and serial output every second if (now - lastUpdate > 1000) { ledStatus = !ledStatus; digitalWrite(LED_BUILTIN, ledStatus); Serial.printf("Battery: %.2fV, %.2f%%, %.2fA\n", batteryVoltage, chargeLevel, current); sprintf(uptimeString, "uptime:\n%012lu\n", millis() / 1000); lastUpdate = now; } // Render status display renderStatus(); } void renderStatus() { statusSprite.fillSprite(TFT_WHITE); // Draw battery voltage statusSprite.setTextSize(3); statusSprite.setTextColor(COLOR_BLACK); statusSprite.drawString("Battery:", 6, 18); // Color-code voltage based on level uint16_t textColor; if (batteryVoltage > 3.7) { textColor = COLOR_GREEN; } else if (batteryVoltage >= 3.3) { textColor = COLOR_ORANGE; } else { textColor = COLOR_RED; } char voltageStr[8]; sprintf(voltageStr, "%4.2f", batteryVoltage); statusSprite.setTextColor(textColor); statusSprite.drawString(voltageStr, 165, 18); // Draw uptime statusSprite.setTextSize(2); statusSprite.setTextColor(COLOR_TEAL); statusSprite.drawString(uptimeString, 6, 56); // Push sprite to display statusSprite.pushSprite(0, 54); } ``` -------------------------------- ### NessoBattery - Initialize and Monitor Battery Status (Arduino) Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt Initializes the battery management system, configures charging parameters, and provides functions to read battery voltage, current, charge level, power, temperature, and cycle count. It also allows checking the charging status and controlling advanced features like watchdog and ship mode. ```cpp #include NessoBattery battery; void setup() { Serial.begin(115200); // Initialize battery with charging parameters: // - 256mA charging current // - 4.2V target voltage // - 2.58V under-voltage lockout // - 4.52V input voltage limit // - Watchdog disabled (0s) battery.begin(256, 4200, NessoBattery::UVLO_2580mV, 4520, 0); // Enable charging battery.enableCharge(); // Configure charging parameters battery.setChargeCurrent(300); // 300mA charge current battery.setChargeVoltage(4200); // 4.2V target voltage battery.setDischargeCurrent(2000); // 2A discharge current battery.setIinLimitCurrent(500); // 500mA input current limit } void loop() { // Read battery status float voltage = battery.getVoltage(); // Returns voltage in Volts (e.g., 3.85) float current = battery.getCurrent(); // Returns current in Amperes (e.g., 0.25) uint16_t chargeLevel = battery.getChargeLevel(); // Returns percentage (0-100) int16_t avgPower = battery.getAvgPower(); // Returns power in mW (can be negative) float temperature = battery.getTemperature(); // Returns temp in Celsius uint16_t cycles = battery.getCycleCount(); // Returns battery cycle count // Check charging status NessoBattery::ChargeStatus status = battery.getChargeStatus(); switch(status) { case NessoBattery::NOT_CHARGING: Serial.println("Not charging"); break; case NessoBattery::PRE_CHARGE: Serial.println("Pre-charge mode"); break; case NessoBattery::CHARGING: Serial.println("Charging"); break; case NessoBattery::FULL_CHARGE: Serial.println("Fully charged"); break; } Serial.printf("Battery: %.2fV, %.2fA, %d%%, %.1fC, %d cycles\n", voltage, current, chargeLevel, temperature, cycles); // Advanced charging control battery.feedWatchdog(); // Reset watchdog timer battery.setHiZ(false); // Disable Hi-Z mode (allow USB to power system) battery.setShipMode(false); // Disable ship mode delay(1000); } ``` -------------------------------- ### NessoDisplay - Basic LCD Drawing and Sprite Usage (Arduino) Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt Initializes the ST7789 LCD display, allowing basic drawing operations like filling the screen, drawing text, shapes, and lines. It also demonstrates creating and using sprites for efficient, flicker-free rendering of dynamic content. ```cpp #include NessoDisplay display; LGFX_Sprite sprite(&display); void setup() { // Initialize display and configure pins display.begin(); // Set orientation and performance mode display.setRotation(1); // Landscape orientation display.setEpdMode(epd_mode_t::epd_fastest); // Basic drawing operations display.fillScreen(TFT_WHITE); display.setTextColor(0x0410); // Teal color display.setTextSize(5); display.drawString("Hello", 10, 20); // Draw shapes display.fillRect(0, 100, 240, 35, TFT_BLACK); display.drawCircle(120, 67, 30, TFT_RED); display.drawLine(0, 0, 240, 135, TFT_BLUE); // Create sprite for efficient rendering sprite.createSprite(240, 80); } void loop() { // Use sprites for flicker-free animation sprite.fillSprite(TFT_WHITE); sprite.setTextSize(3); sprite.setTextColor(TFT_BLACK); sprite.drawString("Battery:", 6, 10); // Color formatting (RGB565) uint16_t green = 0x1e85; uint16_t orange = 0xed03; uint16_t red = 0xe841; sprite.setTextColor(green); sprite.drawString("OK", 150, 10); // Draw progress bar int progress = millis() % 240; sprite.fillRect(0, 0, progress, 5, orange); // Push sprite to display at position sprite.pushSprite(0, 55); delay(30); } ``` -------------------------------- ### NessoDisplay - LCD Display Management Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt Provides a hardware-accelerated display interface based on M5GFX for the 240x135 ST7789 LCD, supporting sprite operations and fast rendering. ```APIDOC ## NessoDisplay - LCD Display Management ### Description Hardware-accelerated display interface based on M5GFX for the 240x135 ST7789 LCD with sprite support and fast rendering. ### Initialization and Configuration - `NessoDisplay()`: Constructor for the NessoDisplay class. - `begin()`: Initializes the display and configures necessary pins. - `setRotation(uint8_t rotation)`: Sets the display orientation (0-3). - `setEpdMode(epd_mode_t mode)`: Sets the display rendering mode for performance tuning. ### Basic Drawing Operations - `fillScreen(uint16_t color)`: Fills the entire screen with a specified color. - `setTextColor(uint16_t color)`: Sets the text color. - `setTextSize(uint8_t size)`: Sets the text size. - `drawString(const char *text, int32_t x, int32_t y)`: Draws a string at the specified coordinates. - `fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color)`: Draws a filled rectangle. - `drawCircle(int32_t x, int32_t y, int32_t r, uint16_t color)`: Draws a circle. - `drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint16_t color)`: Draws a line. ### Sprite Operations - `LGFX_Sprite sprite(&display)`: Creates a sprite object associated with the display. - `sprite.createSprite(int32_t w, int32_t h)`: Creates a sprite with the specified width and height. - `sprite.fillSprite(uint16_t color)`: Fills the sprite with a specified color. - `sprite.setTextColor(uint16_t color)`: Sets the text color for the sprite. - `sprite.setTextSize(uint8_t size)`: Sets the text size for the sprite. - `sprite.drawString(const char *text, int32_t x, int32_t y)`: Draws a string on the sprite. - `sprite.fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color)`: Draws a filled rectangle on the sprite. - `sprite.pushSprite(int32_t x, int32_t y)`: Pushes the sprite onto the display at the specified coordinates. ### Color Formatting Colors are typically represented in RGB565 format (e.g., `0x1e85` for green, `0xed03` for orange, `0xe841` for red). ### Example Usage ```cpp #include NessoDisplay display; LGFX_Sprite sprite(&display); void setup() { display.begin(); display.setRotation(1); display.fillScreen(TFT_WHITE); display.drawString("Hello", 10, 20); sprite.createSprite(240, 80); } void loop() { sprite.fillSprite(TFT_WHITE); sprite.drawString("Status: OK", 6, 10); sprite.pushSprite(0, 55); delay(30); } ``` ``` -------------------------------- ### NessoBattery - Battery Management and Monitoring Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt Provides a complete battery management system, including charging control and battery status monitoring using the AW32001 charger and BQ27220 fuel gauge. ```APIDOC ## NessoBattery - Battery Management and Monitoring ### Description Complete battery management system providing charging control and battery status monitoring through AW32001 charger and BQ27220 fuel gauge. ### Initialization and Configuration - `NessoBattery()`: Constructor for the NessoBattery class. - `begin(uint8_t chargeCurrent, uint16_t chargeVoltage, NessoBattery::UVLO_t uvlo, uint16_t inputVoltageLimit, uint8_t watchdogTimeout)`: Initializes the battery system with specified charging parameters. - `enableCharge()`: Enables the charging process. - `setChargeCurrent(uint16_t current)`: Sets the charging current in mA. - `setChargeVoltage(uint16_t voltage)`: Sets the target charging voltage in mV. - `setDischargeCurrent(uint16_t current)`: Sets the discharge current in mA. - `setIinLimitCurrent(uint16_t current)`: Sets the input current limit in mA. ### Battery Status - `getVoltage()`: Returns the current battery voltage in Volts. - `getCurrent()`: Returns the current battery current in Amperes (positive for charging, negative for discharging). - `getChargeLevel()`: Returns the battery charge level as a percentage (0-100). - `getAvgPower()`: Returns the average power in milliwatts (can be negative). - `getTemperature()`: Returns the battery temperature in Celsius. - `getCycleCount()`: Returns the battery cycle count. - `getChargeStatus()`: Returns the current charging status (e.g., NOT_CHARGING, CHARGING, FULL_CHARGE). ### Advanced Control - `feedWatchdog()`: Resets the battery system's watchdog timer. - `setHiZ(bool enable)`: Enables or disables Hi-Z mode. - `setShipMode(bool enable)`: Enables or disables ship mode. ### Example Usage ```cpp #include NessoBattery battery; void setup() { Serial.begin(115200); battery.begin(256, 4200, NessoBattery::UVLO_2580mV, 4520, 0); battery.enableCharge(); battery.setChargeCurrent(300); battery.setChargeVoltage(4200); } void loop() { float voltage = battery.getVoltage(); uint16_t chargeLevel = battery.getChargeLevel(); Serial.printf("Battery: %.2fV, %d%%\n", voltage, chargeLevel); delay(1000); } ``` ``` -------------------------------- ### NessoTouch - Capacitive Touch Input with Arduino Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt Interface for the FT6x36 capacitive touch controller to read single-touch input and track coordinates. It requires the Arduino_Nesso_N1 library and Wire.h. Outputs touch coordinates and detects touches in specific screen regions. ```cpp #include NessoDisplay display; NessoTouch touch(Wire); int16_t touchX = 0; int16_t touchY = 0; bool wasTouched = false; void setup() { Serial.begin(115200); display.begin(); display.setRotation(1); display.fillScreen(TFT_BLACK); display.setTextColor(TFT_WHITE); display.setTextSize(2); // Initialize touch controller if (touch.begin()) { Serial.println("Touch controller initialized"); display.drawString("Touch Ready", 10, 10); } else { Serial.println("Touch init failed"); display.drawString("Touch Error", 10, 10); } } void loop() { // Check if screen is touched if (touch.isTouched()) { // Read touch coordinates if (touch.read(touchX, touchY)) { Serial.printf("Touch detected at: X=%d, Y=%d\n", touchX, touchY); // Draw circle at touch position display.fillCircle(touchX, touchY, 5, TFT_RED); // Handle touch regions if (touchX < 80) { Serial.println("Left area touched"); } else if (touchX > 160) { Serial.println("Right area touched"); } wasTouched = true; } } else { if (wasTouched) { Serial.println("Touch released"); wasTouched = false; } } delay(50); } ``` -------------------------------- ### ExpanderPin - GPIO Expander Control with Arduino Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt An I2C-based GPIO expander interface for controlling various hardware pins, including buttons, LEDs, power management, and peripheral control. It configures pins for input/output, sets pull-up resistors, and reads button states. Useful for managing onboard components and external modules. ```cpp #include // Predefined expander pins: // LORA_LNA_ENABLE, LORA_ANTENNA_SWITCH, LORA_ENABLE // POWEROFF, GROVE_POWER_EN, VIN_DETECT // LCD_RESET, LCD_BACKLIGHT, LED_BUILTIN // KEY1, KEY2 void setup() { Serial.begin(115200); // Configure LED output pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // Configure display backlight pinMode(LCD_BACKLIGHT, OUTPUT); digitalWrite(LCD_BACKLIGHT, HIGH); // Turn on backlight // Configure user buttons with pull-up pinMode(KEY1, INPUT_PULLUP); pinMode(KEY2, INPUT_PULLUP); // Configure Grove connector power pinMode(GROVE_POWER_EN, OUTPUT); digitalWrite(GROVE_POWER_EN, HIGH); // Enable Grove power // Configure LoRa control pins pinMode(LORA_ENABLE, OUTPUT); pinMode(LORA_LNA_ENABLE, OUTPUT); pinMode(LORA_ANTENNA_SWITCH, OUTPUT); digitalWrite(LORA_ENABLE, HIGH); // Enable LoRa module // Configure voltage detection input pinMode(VIN_DETECT, INPUT); Serial.println("GPIO expander pins configured"); } void loop() { // Read button states int key1State = digitalRead(KEY1); int key2State = digitalRead(KEY2); if (key1State == LOW) { Serial.println("KEY1 pressed"); digitalWrite(LED_BUILTIN, HIGH); } if (key2State == LOW) { Serial.println("KEY2 pressed"); digitalWrite(LED_BUILTIN, LOW); } // Check USB power detection if (digitalRead(VIN_DETECT)) { Serial.println("USB power connected"); } // Blink LED static unsigned long lastBlink = 0; if (millis() - lastBlink > 1000) { digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); lastBlink = millis(); } delay(100); } ``` -------------------------------- ### MyBoschSensor - Accelerometer Access with Arduino Source: https://context7.com/arduino-libraries/arduino_nesso_n1/llms.txt Provides access to the BMI270 accelerometer for motion sensing and orientation detection. It configures the accelerometer for a ±4G range and 25Hz ODR in performance-optimized mode. Outputs acceleration data and detects orientation and tilt. ```cpp #include // IMU instance is predefined as 'IMU' // Uses MyBoschSensor class configured for accelerometer-only mode void setup() { Serial.begin(115200); // Initialize accelerometer if (!IMU.begin()) { Serial.println("Failed to initialize IMU!"); while (1); } Serial.println("IMU initialized"); Serial.println("Accelerometer configured:"); Serial.println("- Range: ±4G"); Serial.println("- ODR: 25Hz"); Serial.println("- Mode: Performance optimized"); } void loop() { float x, y, z; // Read acceleration data if (IMU.accelerationAvailable()) { IMU.readAcceleration(x, y, z); Serial.printf("Acceleration: X=%.2f, Y=%.2f, Z=%.2f g\n", x, y, z); // Detect orientation if (z > 0.8) { Serial.println("Face up"); } else if (z < -0.8) { Serial.println("Face down"); } // Detect tilt if (abs(x) > 0.5 || abs(y) > 0.5) { Serial.println("Device tilted"); } // Calculate magnitude for shake detection float magnitude = sqrt(x*x + y*y + z*z); if (magnitude > 2.0) { Serial.println("Shake detected!"); } } delay(100); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.