user73147: I'm having trouble with these variables. As you can see they're uint32_t type, so they should have a maximum value of 4 million or so, but they're rolling over and going negative at 32,767 like a signed int. Here's the relevant code:
byte lPin = 7;
char buff[100];
uint32_t loAvg = 0;
uint32_t hiAvg = 0;

void setup() {
  pinMode(lPin, OUTPUT);
  digitalWrite(lPin, HIGH); // Active LOW, so this is off

  Serial.begin(9600);
  // Generate high/low averages
  for(int i = 0; i < 100; i++) {
    loAvg += analogRead(A0);
  }
  loAvg /= 100;

  digitalWrite(lPin, LOW);
  delay(500);

  for(int i = 0; i < 100; i++) {
    hiAvg += analogRead(A0);
  }
  hiAvg /= 100;
  
  digitalWrite(lPin, HIGH);
  delay(500);
  
  sprintf(buff, "loAvg=%d, hiAvg=%d", loAvg, hiAvg);
  Serial.println(buff);

  Serial.println(hiAvg);
  digitalWrite(lPin, LOW);
  hiAvg = 0;
}

void loop() {
  sprintf(buff, "test=%d", hiAvg);
  Serial.println(buff);
  hiAvg+=100;
}

I removed a bunch of stuff from the code to save posting the whole (much longer) thing. If it ends up being relevant I can though, I just think I narrowed the problem down to this. Observing the serial monitor I get this on startup:
loAvg=287, hiAvg=0
933
test=0
test=100
test=200
...

The test=# repeats until 32700, then continues at -32736. I'm confused by the hiAvg=0 followed by the 933, showing that it totally is getting a high average, because that's around what it should be. Even if it's the sprintf() messing with it, in the setup function the value should only be around the 900 range so it wouldn't overflow there. Any ideas anyone?

user70020: *printf and bit-width specified types
#include <inttypes.h> or C++'s #include <cinttypes> counterpart (when you have it; not on AVR-based Arduinos) gives access to macros defined for the format specifiers for each of the fixed, fast, and least versions of these types.  All of these macros expand to some string literal or another.
For uint32_t the macro defining to its format specifier is PRIu32.  For an AVR, this is "%lu".  It needn't be "%lu" in  the general case.  uint32_t is one of the types where you can often get away with using "%lu" and have it either work out being exactly correct for the platform or somewhat incorrect but working anyway because it's a platform where unsigned int and unsigned long happen to have the same representation.
In C and C++, and so Arduino, adjacent string literals are concatenated into one logical string in the early phases of compilation that follow the macro preprocessor.  So, the intention is that you choose the correct macro and you put them following something like "%" or "%12" if you wanted a minimum-width of 12.  As in "%" PRIu32 and "%12" PRIu32 respectively.  So, in your case,  having included (directly or indirectly) <stdint.h> for uint32_t and <inttypes.h> for PRIu32 or their C++ counterpart headers, and then your code looks something like:
snprintf(
  buf,
  sizeof buf,
  "loAvg=%" PRIu32 ", hiAvg=%" PRIu32,
  loAvg,
  hiAvg
);

There's little to no reason to not use the snprintf.  The reason why the non-n version exists at all is mostly that snprintf showed up in 1999, instead of circa the mid 1970s.  I'd say it's pretty safe to use snprintf now.  There probably hasn't been an Arduino that doesn't support it.  About the only reason to use sprintf would be if you were calling it with a null pointer for the buffer argument to get it to do a dry run and tell how much memory you need for the result, and you just didn't want to supply a limiting size.
There are PRI... macros for all of the combinations of standard bit width and choice of signed decimal, unsigned decimal, lowercase hex, uppercase hex, etc.  E.g "%" "PRId16" is  for int16_t in decimal, "%" PRIX64 for uint64_t in hexadecimal with uppercase alphabetics.  The are ones for the fast and least bitwidth types, and whole show is repeated with macros starting with SCN for the scanf specifiers, not that you should use the scanf family functions for anything really.
snprintf and sprintf are variadic functions.  After the format specifier there's no type information available to the compiler to know what conversions to apply.  It will convert types smaller than int rank up to int on unsigned int, but that's about it.  E.g. it will not reliably down-convert an unsigned long long into an unsigned int, the way it would if the types were known.  Modern compilers will sometimes warn you if you grossly misapply format specifiers, but they're not required to.  They're not expected to dissect the format string and attempt to recover type information.  So it's up to you to make sure whatever you pass in for arguments matches with the format specifiers.  As you've seen it's confusing if you get it wrong with printf-type functions, but it doesn't cause real problems unless you, you know, don't limit it to stay within the output buffer with the snprintf version.  In the case of passing in an unsigned long long where an unsigned int was expected, in practice, for a little-endian system like AVR, it may appear to do that for one argument.  But then it may fail on the next argument, because the size of the last argument was in correct, it is now reading from the wrong place.
Print/Stream/Serial concatenating and buffering
The way you're using sprintf in your code isn't taking advantage of any of its features that Serial/Print doesn't do.
Serial.print(F("loAvg="));
Serial.print(loAvg);
Serial.print(F(", hiAvg="));
Serial.println(hiAvg);

Despite taking four lines, this is actually smaller, faster, more reliable code than the sprintf one-liner.
Putting the output into a buffer first might make sense if you were going to put it into a packet, like for UDP or nRF24L01.  But, Print/Stream/Serial already concatenates and buffers things for you.

Incidentally, if you're going to use printf functions and you're doing it on an AVR-based Arduino, look at the avr-libc documentation for the _P variants that take their format strings from PROGMEM and the PSTR macro.
It is also possible to complete the implementation of <stdio.h> for stdout and stderr through libc-specific means.  So, if you really want to, you can have the regular printf function pushing data out through Serial (among other things) such that you don't need to buffer repeatedly with sprintf.

user313: %d expects a signed int. %u expects an unsigned int. Insert the l modifier to expect a long in each of those cases. So you need a format code of %lu to print a uint32_t.
The following code:
#include <Arduino.h>

void setup()
{
    uint32_t x=110000;
    char buf[50];

   // Open console
   Serial.begin(115200);
   
    sprintf(buf, "%%d: %d\n", x);       Serial.print(buf);
    sprintf(buf, "%%u: %u\n", x);       Serial.print(buf);
    sprintf(buf, "%%ld: %ld\n", x); Serial.print(buf);
    sprintf(buf, "%%lu: %lu\n", x); Serial.print(buf);
}


void loop() {
   ;
}

prints this:
%d: -21072
%u: 44464
%ld: 110000
%lu: 110000


73147: <p>I'm having trouble with these variables. As you can see they're uint32_t type, so they should have a maximum value of 4 million or so, but they're rolling over and going negative at 32,767 like a signed int. Here's the relevant code:</p>
<pre><code>byte lPin = 7;
char buff[100];
uint32_t loAvg = 0;
uint32_t hiAvg = 0;

void setup() {
  pinMode(lPin, OUTPUT);
  digitalWrite(lPin, HIGH); // Active LOW, so this is off

  Serial.begin(9600);
  // Generate high/low averages
  for(int i = 0; i &lt; 100; i++) {
    loAvg += analogRead(A0);
  }
  loAvg /= 100;

  digitalWrite(lPin, LOW);
  delay(500);

  for(int i = 0; i &lt; 100; i++) {
    hiAvg += analogRead(A0);
  }
  hiAvg /= 100;
  
  digitalWrite(lPin, HIGH);
  delay(500);
  
  sprintf(buff, &quot;loAvg=%d, hiAvg=%d&quot;, loAvg, hiAvg);
  Serial.println(buff);

  Serial.println(hiAvg);
  digitalWrite(lPin, LOW);
  hiAvg = 0;
}

void loop() {
  sprintf(buff, &quot;test=%d&quot;, hiAvg);
  Serial.println(buff);
  hiAvg+=100;
}
</code></pre>
<p>I removed a bunch of stuff from the code to save posting the whole (much longer) thing. If it ends up being relevant I can though, I just think I narrowed the problem down to this. Observing the serial monitor I get this on startup:</p>
<pre><code>loAvg=287, hiAvg=0
933
test=0
test=100
test=200
...
</code></pre>
<p>The <code>test=#</code> repeats until 32700, then continues at -32736. I'm confused by the hiAvg=0 followed by the 933, showing that it totally is getting a high average, because that's around what it should be. Even if it's the sprintf() messing with it, in the setup function the value should only be around the 900 range so it wouldn't overflow there. Any ideas anyone?</p>
 70020: <h2>*<code>printf</code> and bit-width specified types</h2>
<p><code>#include &lt;inttypes.h&gt;</code> or C++'s <code>#include &lt;cinttypes&gt;</code> counterpart (when you have it; not on AVR-based Arduinos) gives access to macros defined for the format specifiers for each of the fixed, fast, and least versions of these types.  All of these macros expand to some string literal or another.</p>
<p>For <code>uint32_t</code> the macro defining to its format specifier is <code>PRIu32</code>.  For an AVR, this is <code>&quot;%lu&quot;</code>.  It needn't be <code>&quot;%lu&quot;</code> in  the general case.  <code>uint32_t</code> is one of the types where you can often get away with using <code>&quot;%lu&quot;</code> and have it either work out being exactly correct for the platform or somewhat incorrect but working anyway because it's a platform where <code>unsigned int</code> and <code>unsigned long</code> happen to have the same representation.</p>
<p>In C and C++, and so Arduino, adjacent string literals are concatenated into one logical string in the early phases of compilation that follow the macro preprocessor.  So, the intention is that you choose the correct macro and you put them following something like <code>&quot;%&quot;</code> or <code>&quot;%12&quot;</code> if you wanted a minimum-width of 12.  As in <code>&quot;%&quot; PRIu32</code> and <code>&quot;%12&quot; PRIu32</code> respectively.  So, in your case,  having included (directly or indirectly) <code>&lt;stdint.h&gt;</code> for <code>uint32_t</code> and <code>&lt;inttypes.h&gt;</code> for <code>PRIu32</code> or their C++ counterpart headers, and then your code looks something like:</p>
<pre class="lang-cpp prettyprint-override"><code>snprintf(
  buf,
  sizeof buf,
  &quot;loAvg=%&quot; PRIu32 &quot;, hiAvg=%&quot; PRIu32,
  loAvg,
  hiAvg
);
</code></pre>
<p>There's little to no reason to not use the s<strong>n</strong>printf.  The reason why the non-n version exists at all is mostly that <code>snprintf</code> showed up in 1999, instead of circa the mid 1970s.  I'd say it's pretty safe to use <code>snprintf</code> now.  There probably hasn't been an Arduino that doesn't support it.  About the only reason to use <code>sprintf</code> would be if you were calling it with a null pointer for the buffer argument to get it to do a dry run and tell how much memory you need for the result, and you just didn't want to supply a limiting size.</p>
<p>There are <code>PRI...</code> <a href="https://en.cppreference.com/w/cpp/header/cinttypes" rel="nofollow noreferrer">macros for all of the combinations</a> of standard bit width and choice of signed decimal, unsigned decimal, lowercase hex, uppercase hex, etc.  E.g <code>&quot;%&quot; &quot;PRId16&quot;</code> is  for <code>int16_t</code> in decimal, <code>&quot;%&quot; PRIX64</code> for <code>uint64_t</code> in hexadecimal with uppercase alphabetics.  The are ones for the <code>fast</code> and <code>least</code> bitwidth types, and whole show is repeated with macros starting with <code>SCN</code> for the <code>scanf</code> specifiers, not that you should use the <code>scanf</code> family functions for anything really.</p>
<p><code>snprintf</code> and <code>sprintf</code> are variadic functions.  After the format specifier there's no type information available to the compiler to know what conversions to apply.  It will convert types smaller than <code>int</code> rank up to <code>int</code> on <code>unsigned int</code>, but that's about it.  E.g. it will not reliably down-convert an <code>unsigned long long</code> into an <code>unsigned int</code>, the way it would if the types were known.  Modern compilers will sometimes warn you if you grossly misapply format specifiers, but they're not required to.  They're not expected to dissect the format string and attempt to recover type information.  So it's up to you to make sure whatever you pass in for arguments matches with the format specifiers.  As you've seen it's confusing if you get it wrong with <code>printf</code>-type functions, but it doesn't cause real problems unless you, you know, don't limit it to stay within the output buffer with the s<strong>n</strong>printf version.  In the case of passing in an <code>unsigned long long</code> where an <code>unsigned int</code> was expected, in practice, for a little-endian system like AVR, it may appear to do that for one argument.  But then it may fail on the next argument, because the size of the last argument was in correct, it is now reading from the wrong place.</p>
<h2><code>Print</code>/<code>Stream</code>/<code>Serial</code> concatenating and buffering</h2>
<p>The way you're using <code>sprintf</code> in your code isn't taking advantage of any of its features that <code>Serial</code>/<code>Print</code> doesn't do.</p>
<pre class="lang-cpp prettyprint-override"><code>Serial.print(F(&quot;loAvg=&quot;));
Serial.print(loAvg);
Serial.print(F(&quot;, hiAvg=&quot;));
Serial.println(hiAvg);
</code></pre>
<p>Despite taking four lines, this is actually smaller, faster, more reliable code than the <code>sprintf</code> one-liner.</p>
<p>Putting the output into a buffer first might make sense if you were going to put it into a packet, like for UDP or nRF24L01.  But, <code>Print</code>/<code>Stream</code>/<code>Serial</code> already concatenates and buffers things for you.</p>
<hr />
<p>Incidentally, if you're going to use <code>printf</code> functions and you're doing it on an AVR-based Arduino, look at the avr-libc <a href="https://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html" rel="nofollow noreferrer">documentation for the <code>_P</code> variants</a> that take their format strings from PROGMEM and the <a href="https://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#ga05ca900ebf7cd121be73c654d9ccb3eb" rel="nofollow noreferrer"><code>PSTR</code> macro</a>.</p>
<p>It is also possible to complete the implementation of <code>&lt;stdio.h&gt;</code> for <code>stdout</code> and <code>stderr</code> through libc-specific means.  So, if you really want to, you can have the regular <code>printf</code> function pushing data out through <code>Serial</code> (among other things) such that you <em>don't</em> need to buffer repeatedly with <code>sprintf</code>.</p>
 313: <p><code>%d</code> expects a signed int. <code>%u</code> expects an unsigned int. Insert the <code>l</code> modifier to expect a long in each of those cases. So you need a format code of <code>%lu</code> to print a uint32_t.</p>
<p>The following code:</p>
<pre><code>#include &lt;Arduino.h&gt;

void setup()
{
    uint32_t x=110000;
    char buf[50];

   // Open console
   Serial.begin(115200);
   
    sprintf(buf, &quot;%%d: %d\n&quot;, x);       Serial.print(buf);
    sprintf(buf, &quot;%%u: %u\n&quot;, x);       Serial.print(buf);
    sprintf(buf, &quot;%%ld: %ld\n&quot;, x); Serial.print(buf);
    sprintf(buf, &quot;%%lu: %lu\n&quot;, x); Serial.print(buf);
}


void loop() {
   ;
}
</code></pre>
<p>prints this:</p>
<pre><code>%d: -21072
%u: 44464
%ld: 110000
%lu: 110000
</code></pre>
