Skip to content

Commit 366ca54

Browse files
committed
Removed dependency on Adafruit NeoPixel. Added breathing. #207 #208
1 parent 5cf10f2 commit 366ca54

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

.github/workflows/arduino.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ jobs:
3131
- name: EspSoftwareSerial
3232
version: 8.1.0
3333
- source-url: https://github.com/fatpat/arduino-dra818/archive/refs/tags/v1.0.1.zip
34-
- name: Adafruit NeoPixel
3534
verbose: true

microcontroller-src/README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@
6060
- Locate the **EspSoftwareSerial** library in the search results.
6161
- Click the **Install** button to add the library to your Arduino environment.
6262

63-
2. **Install Adafruit NeoPixel:**
64-
- Navigate to `Sketch` > `Include Library` > `Manage Libraries`.
65-
- In the **Library Manager** window, enter **"Adafruit NeoPixel"** into the search bar.
66-
- Locate the **Adafruit NeoPixel** library in the search results.
67-
- Click the **Install** button to add the library to your Arduino environment.
68-
69-
3. **Install DRA818:**
63+
2. **Install DRA818:**
7064
> **Note:** The version of the DRA818 library available through the Arduino Library Manager is currently broken. To ensure proper functionality, you need to install it manually from the official GitHub release.
7165
7266
- **Download the DRA818 Library ZIP:**
@@ -80,8 +74,8 @@
8074
- Select the ZIP file and click **Open**.
8175
- A confirmation message should appear indicating that the library was added successfully.
8276

83-
4. **Confirm All Libraries Are Installed:**
84-
- After completing the above steps, ensure that **EspSoftwareSerial**, **Adafruit NeoPixel**, and **DRA818** are listed under `Sketch` > `Include Library`.
77+
3. **Confirm All Libraries Are Installed:**
78+
- After completing the above steps, ensure that **EspSoftwareSerial** and **DRA818** are listed under `Sketch` > `Include Library`.
8579
- If any libraries are missing, revisit the installation steps to ensure they were added correctly.
8680

8781
### Opening the Project (Arduino IDE)

microcontroller-src/kv4p_ht_esp32_wroom_32/kv4p_ht_esp32_wroom_32.ino

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2424
#include <driver/i2s.h>
2525
#include <driver/dac.h>
2626
#include <esp_task_wdt.h>
27-
#include <Adafruit_NeoPixel.h>
2827

2928
const byte FIRMWARE_VER[8] = {'0', '0', '0', '0', '0', '0', '1', '1'}; // Should be 8 characters representing a zero-padded version, like 00000001.
3029
const byte VERSION_PREFIX[7] = {'V', 'E', 'R', 'S', 'I', 'O', 'N'}; // Must match RadioAudioService.VERSION_PREFIX in Android app.
@@ -147,8 +146,18 @@ hw_ver_t hardware_version = HW_VER_V1; // lowest common denominator
147146
// NeoPixel support
148147
#define PIXELS_PIN 13
149148
#define NUM_PIXELS 1
150-
Adafruit_NeoPixel pixels(NUM_PIXELS, PIXELS_PIN, NEO_GRB + NEO_KHZ400);
151-
bool first_time = true;
149+
150+
struct RGBColor {
151+
uint8_t red;
152+
uint8_t green;
153+
uint8_t blue;
154+
};
155+
const RGBColor COLOR_STOPPED = {0, 0, 0};
156+
const RGBColor COLOR_RX_SQL_CLOSED = {0, 0, 32};
157+
const RGBColor COLOR_RX_SQL_OPEN = {0, 32, 0};
158+
const RGBColor COLOR_TX = {16, 16, 0};
159+
const RGBColor COLOR_BLACK = {0, 0, 0};
160+
RGBColor COLOR_HW_VER = COLOR_BLACK;
152161

153162
////////////////////////////////////////////////////////////////////////////////
154163
/// Forward Declarations
@@ -163,6 +172,7 @@ void iir_lowpass_reset();
163172
hw_ver_t get_hardware_version();
164173
void reportPhysPttState();
165174
void show_LEDs();
175+
void neopixelColor(RGBColor color, float bright = 1.0);
166176

167177
void setup() {
168178
// Used for setup, need to know early.
@@ -173,36 +183,26 @@ void setup() {
173183
Serial.setTxBufferSize(USB_BUFFER_SIZE);
174184
Serial.begin(230400);
175185

176-
// Indicate detected hardware version
177-
// Config some pin assignments.
178-
uint32_t color = 0;
186+
// Hardware dependent pin assignments.
179187
switch (hardware_version) {
180188
case HW_VER_V1:
181-
color = pixels.Color(0, 32, 0);
189+
COLOR_HW_VER = {0, 32, 0};
182190
SQ_PIN = 32;
183191
break;
184192
case HW_VER_V2_0C:
185-
color = pixels.Color(32, 0, 0);
193+
COLOR_HW_VER = {32, 0, 0};
186194
SQ_PIN = 4;
187195
break;
188196
case HW_VER_V2_0D:
189-
color = pixels.Color(0, 0, 32);
197+
COLOR_HW_VER = {0, 0, 32};
190198
SQ_PIN = 4;
191199
break;
192200
default:
193201
// Unknown version detected. Indicate this some way?
202+
COLOR_HW_VER = {16, 16, 16};
194203
break;
195204
}
196205

197-
for (uint8_t ndx = 3; ndx; ndx--) {
198-
pixels.setPixelColor(0, color);
199-
pixels.show();
200-
delay(200);
201-
pixels.setPixelColor(0, 0);
202-
pixels.show();
203-
delay(200);
204-
}
205-
206206
// Configure watch dog timer (WDT), which will reset the system if it gets stuck somehow.
207207
esp_task_wdt_init(10, true); // Reboot if locked up for a bit
208208
esp_task_wdt_add(NULL); // Add the current task to WDT watch
@@ -227,6 +227,7 @@ void setup() {
227227
Serial2.setTimeout(10); // Very short so we don't tie up rx audio while reading from radio module (responses are tiny so this is ok)
228228

229229
// Begin in STOPPED mode
230+
lastSquelched = (digitalRead(SQ_PIN) == HIGH);
230231
setMode(MODE_STOPPED);
231232
}
232233

@@ -628,10 +629,6 @@ void loop() {
628629
size_t samplesRead = bytesRead / 2;
629630

630631
bool squelched = (digitalRead(SQ_PIN) == HIGH);
631-
if (first_time) {
632-
lastSquelched = squelched;
633-
show_LEDs();
634-
}
635632

636633
// Check for squelch status change
637634
if (squelched != lastSquelched) {
@@ -739,7 +736,6 @@ void loop() {
739736
// Disregard, we don't want to crash. Just pick up at next loop().)
740737
// Serial.println("Exception in loop(), skipping cycle.");
741738
}
742-
first_time = false;
743739
show_LEDs();
744740
}
745741

@@ -857,17 +853,30 @@ hw_ver_t get_hardware_version() {
857853
return ver;
858854
}
859855

860-
void show_LEDs() {
861-
const static uint32_t COLOR_STOPPED = pixels.Color(0, 0, 0);
862-
const static uint32_t COLOR_RX_SQL_CLOSED = pixels.Color(0, 0, 32); // TODO: animate this state? Breath? Option to turn off entirely?
863-
const static uint32_t COLOR_TX = pixels.Color(16, 16, 0);
864-
const static uint32_t COLOR_RX_SQL_OPEN = pixels.Color(0, 32, 0);
856+
void neopixelColor(RGBColor C, float bright) {
857+
uint8_t red = uint8_t(C.red*bright);
858+
uint8_t green = uint8_t(C.green*bright);
859+
uint8_t blue = uint8_t(C.blue*bright);
860+
neopixelWrite(PIXELS_PIN, red, green, blue);
861+
}
865862

863+
// Calculate a float between min and max, that ramps from min to max in half of breath_every,
864+
// and from max to min the second half of breath_every.
865+
// now and breath_every are arbitrary units, but usually are milliseconds from millis().
866+
float calc_breath(uint32_t now, uint32_t breath_every, float min, float max) {
867+
float amplitude = max - min;
868+
float bright = (float(now%breath_every)/breath_every)*2.0; // 0.0 to 2.0, how far through breath_every are we
869+
if (bright > 1.0) bright = 2.0-bright; // Fold >1.0 back down to between 1.0 and 0.0.
870+
bright = bright*amplitude + min;
871+
return bright;
872+
}
873+
874+
void show_LEDs() {
866875
// When to actually act?
867876
static Mode last_mode = MODE_STOPPED;
868877
static bool last_squelched = true; // Eww. This is too closely named to the variable we're tracking.
869878
static uint32_t next_time = 0;
870-
const static uint32_t update_every = 100; // in milliseconds
879+
const static uint32_t update_every = 50; // in milliseconds
871880

872881
uint32_t now = millis();
873882

@@ -883,21 +892,21 @@ void show_LEDs() {
883892
switch (mode) {
884893
case MODE_STOPPED:
885894
digitalWrite(LED_PIN, LOW);
886-
pixels.setPixelColor(0, COLOR_STOPPED);
895+
//neopixelColor(COLOR_STOPPED);
896+
neopixelColor(COLOR_HW_VER);
887897
break;
888898
case MODE_RX:
889899
digitalWrite(LED_PIN, LOW);
890900
if (lastSquelched) {
891-
pixels.setPixelColor(0, COLOR_RX_SQL_CLOSED);
901+
neopixelColor(COLOR_RX_SQL_CLOSED, calc_breath(now, 2000, 0.5, 1.5));
892902
} else {
893-
pixels.setPixelColor(0, COLOR_RX_SQL_OPEN);
903+
neopixelColor(COLOR_RX_SQL_OPEN);
894904
}
895905
break;
896906
case MODE_TX:
897907
digitalWrite(LED_PIN, HIGH);
898-
pixels.setPixelColor(0, COLOR_TX);
908+
neopixelColor(COLOR_TX);
899909
break;
900910
}
901-
pixels.show();
902911
}
903912
}

microcontroller-src/platformio.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ lib_deps =
2323
; fatpat/DRA818@^1.0.1
2424
https://github.com/fatpat/arduino-dra818.git#v1.0.1 ; v1.0.1 is the latest release, but has not been pushed to registry. Update later
2525
plerup/EspSoftwareSerial@^8.2.0
26-
Adafruit/Adafruit NeoPixel

website-src/contribute.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ <h1>Project files</h1>
6060
<ul>
6161
<li>Board: Install v2.0.17 of <b>esp32</b> by Espressif Systems from Boards Manager - DO NOT use newer versions, the code is not compatible with the API changes that were made. The board may not be auto-detected when plugged in, make sure it says <i>ESP32 Dev Module</i> in the drop-down at the top of the IDE or select it manually.</li>
6262
<li>Library: EspSoftwareSerial (8.1.0) - get this from the built-in library installer</li>
63-
<li>Library: Adafruit NeoPixel (>= 1.12.4) - get this from the built-in library installer</li>^M
6463
<li>Library: <a href="https://github.com/fatpat/arduino-dra818/releases/tag/v1.0.1" target="_new">arduino-dra818 v1.0.1</a> - DO NOT use version 1.0.0 that's included in Arduino package installer, it's old and broken. Install with <i>Sketch > Include Library > Add .ZIP Library.</i></li>
6564
<li>Configuration: Choose <i>Tools > Events Run On > Core 0</i> so audio processing interrupts run on a separate thread for maximum stability.</li>
6665
</ul>
@@ -76,4 +75,4 @@ <h1>Overview docs</h1>
7675
</main>
7776
</div>
7877
</body>
79-
</html>
78+
</html>

0 commit comments

Comments
 (0)