Skip to content

Commit 4f89646

Browse files
committed
doc: added README and first example for battery.
Signed-off-by: ubi de feo <me@ubidefeo.com>
1 parent 8084294 commit 4f89646

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<img src="https://content.arduino.cc/website/Arduino_logo_teal.svg" height="100" align="right" />
2+
3+
`Arduino Nesso N1`
4+
=======================
5+
6+
Support library for [Arduino Nesso N1](https://store.arduino.cc/products/nesso-n1)
7+
8+
## :mag_right: Resources
9+
10+
* [Guides and tutorials](https://docs.arduino.cc/hardware/nesso-n1/)
11+
* [How to install a library](https://www.arduino.cc/en/guide/libraries)
12+
* [Help Center](https://support.arduino.cc/)
13+
* [Forum](https://forum.arduino.cc)
14+
15+
## :bug: Bugs & Issues
16+
17+
If you want to report an issue with this library, you can submit it to the [issue tracker](https://github.com/arduino-libraries/Arduino_Nesso_n1/issues) of this repository. Remember to include as much detail as you can about your hardware set-up, code and steps for reproducing the issue. Make sure you're using an original Arduino board.
18+
19+
## :technologist: Development
20+
21+
There are many ways to contribute:
22+
23+
* Improve documentation and examples
24+
* Fix a bug
25+
* Test open Pull Requests
26+
* Implement a new feature
27+
* Discuss potential ways to improve this library
28+
29+
You can submit your patches directly to this repository as Pull Requests. Please provide a detailed description of the problem you're trying to solve and make sure you test on real hardware.
30+
31+
## :yellow_heart: Support the project
32+
33+
This open-source code is maintained by Arduino with the help of the community. We invest a considerable amount of time in testing code, optimizing it and introducing new features. Please consider [buying original Arduino boards](https://store.arduino.cc/) to support our work on the project.
34+
35+
## License
36+
37+
Copyright (c) 2022 Arduino SA. All rights reserved.
38+
39+
This library is free software; you can redistribute it and/or
40+
modify it under the terms of the GNU Lesser General Public
41+
License as published by the Free Software Foundation; either
42+
version 2.1 of the License, or (at your option) any later version.
43+
44+
This library is distributed in the hope that it will be useful,
45+
but WITHOUT ANY WARRANTY; without even the implied warranty of
46+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47+
Lesser General Public License for more details.
48+
49+
You should have received a copy of the GNU Lesser General Public
50+
License along with this library; if not, write to the Free Software
51+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

examples/BatteryDisplay.ino

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
Arduino Nesso N1 - Display Battery Status
3+
4+
This example will enable battery charging and display its charging state.
5+
6+
created: December 11 2025
7+
by: Ubi de Feo
8+
9+
This example code is in the public domain.
10+
*/
11+
12+
#include <Arduino_Nesso_N1.h>
13+
NessoBattery battery;
14+
NessoDisplay display;
15+
16+
const int DISPLAY_WIDTH = 240;
17+
const int DISPLAY_HEIGHT = 135;
18+
const uint16_t COLOR_TEAL = 0x0410;
19+
const uint16_t COLOR_BLACK = 0x0000;
20+
const uint16_t COLOR_GREEN = 0x1e85;
21+
const uint16_t COLOR_ORANGE = 0xed03;
22+
const uint16_t COLOR_RED = 0xe841;
23+
const int ANIMATION_DELAY = 30;
24+
const int COLS = 20;
25+
const int ROWS = 1;
26+
const int REGION_WIDTH = 12;
27+
const int REGION_HEIGHT = 135;
28+
29+
30+
LGFX_Sprite statusSprite(&display);
31+
32+
float batteryVoltage = 0.0;
33+
int counter = 0;
34+
char uptimeString[26];
35+
bool ledStatus = false;
36+
unsigned long lastLEDflip = 0;
37+
int progressEdge = 240;
38+
bool progressExpanding = true;
39+
40+
void setup() {
41+
Serial.begin(115200);
42+
43+
display.begin();
44+
45+
battery.begin();
46+
battery.enableCharge();
47+
48+
pinMode(LED_BUILTIN, OUTPUT);
49+
50+
display.setRotation(1);
51+
display.setEpdMode(epd_mode_t::epd_fastest);
52+
53+
display.fillScreen(TFT_WHITE);
54+
display.setTextColor(COLOR_TEAL);
55+
display.setTextSize(5);
56+
display.drawString("Nesso N1", 6, 11);
57+
58+
statusSprite.createSprite(240, 81);
59+
lastLEDflip = millis();
60+
}
61+
62+
void loop() {
63+
unsigned long msNow = millis();
64+
65+
float chargeLevel = battery.getChargeLevel();
66+
batteryVoltage = battery.getVoltage();
67+
68+
char batteryStatusTicker[16];
69+
sprintf(batteryStatusTicker, "%4.2f %6.2f%%", batteryVoltage, chargeLevel);
70+
if (msNow - lastLEDflip > 1000) {
71+
ledStatus = !ledStatus;
72+
// LED_BUILTIN currently disabled for failures
73+
digitalWrite(LED_BUILTIN, ledStatus);
74+
lastLEDflip = msNow;
75+
Serial.print(batteryVoltage);
76+
Serial.print(" ");
77+
Serial.print(chargeLevel);
78+
Serial.println("%");
79+
sprintf(uptimeString, "uptime:\n%012d\n", millis() / 1000);
80+
Serial.println(uptimeString);
81+
}
82+
renderstatusSprite();
83+
}
84+
85+
void renderstatusSprite() {
86+
int offsetY = 18;
87+
statusSprite.fillSprite(TFT_WHITE);
88+
statusSprite.setColor(COLOR_ORANGE);
89+
if (progressExpanding) {
90+
statusSprite.fillRect(progressEdge, 0, 240, 8);
91+
} else {
92+
statusSprite.fillRect(0, 0, progressEdge, 8);
93+
}
94+
95+
progressEdge -= 1;
96+
if (progressEdge <= 0) {
97+
progressEdge = 240;
98+
progressExpanding = !progressExpanding;
99+
}
100+
statusSprite.setTextSize(3);
101+
statusSprite.setTextColor(COLOR_BLACK);
102+
statusSprite.drawString("Battery:", 6, offsetY);
103+
uint16_t textColor = 0x0000;
104+
if (batteryVoltage > 3.7) {
105+
textColor = COLOR_GREEN;
106+
} else if (batteryVoltage <= 3.7 && batteryVoltage >= 3.3) {
107+
textColor = COLOR_ORANGE;
108+
} else {
109+
textColor = COLOR_RED;
110+
}
111+
char batteryString[6];
112+
sprintf(batteryString, "%4.2f", batteryVoltage);
113+
statusSprite.setTextColor(textColor);
114+
statusSprite.drawString(batteryString, 165, offsetY);
115+
statusSprite.setTextColor(COLOR_BLACK);
116+
statusSprite.setTextSize(2);
117+
118+
statusSprite.setTextColor(COLOR_TEAL);
119+
statusSprite.drawString(uptimeString, 6, offsetY + 38);
120+
statusSprite.pushSprite(0, 54);
121+
//
122+
}

0 commit comments

Comments
 (0)