Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions advancedio/addressable-leds.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ The wiring for addressable LEDs is simple—just three connections:

### Preparing the LED stick

![](assets/images/RGBLEDStick_8LEDs_SolderPadsAndLEDS.png)
![Back and front views of an 8-LED WS2812B stick, showing the solder pads and the row of addressable RGB LEDs](assets/images/RGBLEDStick_8LEDs_SolderPadsAndLEDS.png)
**Figure.** The back and front sides of an 8-LED WS2812B stick. We will need to solder either jumper wires or header pins to the pads.
{: .fs-1 }

Expand Down Expand Up @@ -413,7 +413,7 @@ void loop() {

If your colors look wrong (*e.g.,* you asked for red but got green), try changing `NEO_GRB` to `NEO_RGB` in the strip constructor. This is the most common issue students encounter!

![](assets/images/AddressableLEDs_RainbowStatic8.png)
![An 8-LED addressable RGB stick lit up in a static rainbow gradient from red through green to blue](assets/images/AddressableLEDs_RainbowStatic8.png)
**Figure.** An image of the RGB LED stick running the above code. You can also view and play with this on [Tinkercad](https://www.tinkercad.com/things/lSqArYGju94-neopixel-strip-8-static-rainbow). See our [RainbowStatic8.ino](https://github.com/makeabilitylab/arduino/blob/master/AddressableLEDs/NeoPixel/RainbowStatic8/RainbowStatic8.ino) and [RainbowStatic.ino](https://github.com/makeabilitylab/arduino/blob/master/AddressableLEDs/NeoPixel/RainbowStatic/RainbowStatic.ino) sketches in GitHub.
{: .fs-1 }

Expand Down
20 changes: 10 additions & 10 deletions advancedio/smoothing-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ usetocbot: true

By now, you may have noticed that your analog input data can be noisy. How can we smooth our input and what factors should we consider?

<video autoplay loop muted playsinline>
<video aria-label="A noisy analog input signal (blue) being smoothed in real time by a moving average filter with a window size of 10 (red), graphed in the Arduino Serial Plotter" autoplay loop muted playsinline>
<source src="assets/videos/MovingAverageFilterWindowSize10-Optimized.mp4" type="video/mp4" />
</video>

Expand Down Expand Up @@ -52,7 +52,7 @@ When reading sensor data using analog input pins on a microcontroller (*e.g.,* v

Even with a simple potentiometer, we can observe noise on our input pin. In the video below, we are **not** touching the potentiometer and yet the analog input is oscillating between 142 and 143 (0.694V and 0.699V)—shown as the blue line. You may have experienced this too in your own potentiometer-based projects or in the [Arduino potentiometer lesson](../arduino/potentiometers.md). In this case, we fixed this "input noise" by smoothing the signal using a moving average filter—shown in red—which we will describe in this lesson.

<video autoplay loop muted playsinline>
<video aria-label="A potentiometer's raw analog input (blue) oscillating between 142 and 143 while untouched, with the noise removed by a moving average filter of window size 10 (red)" autoplay loop muted playsinline>
<source src="assets/videos/PotentiometerOscillatingWithNoInputButFixedWithMovingAverage-Optimized.mp4" type="video/mp4" />
</video>
**Video.** In this video, we're graphing the raw analog input (blue line) from a potentiometer along with a "smoothed" version (red line). Although we're not touching or using the potentiometer, the analog input is oscillating between 142 and 143 (0.694V and 0.699V). We smooth this noise using a moving average filter (window size = 10)—shown in red. Note that, depending on the oscillation pattern, a different window size or smoothing approach may be necessary. Read more about potentiometer noise [here](https://passive-components.eu/resistors-potentiometers-basic-principles/). Graph made with the built-in [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/).
Expand Down Expand Up @@ -92,7 +92,7 @@ This filter is a type of **low-pass** filter because it smooths out (eliminates)

You can control the filter's performance by tweaking the size of the sliding window. The animation below demonstrates a sliding window of size 3. The blue line corresponds to the raw input signal; the orange line, the smoothed filter output. For illustrative purposes, we only show the sliding window applied to a subset of data.

<video autoplay loop muted playsinline>
<video aria-label="An animation illustrating a moving average filter with a window size of 3 sliding over a raw input signal (blue) to produce the smoothed output (orange)" autoplay loop muted playsinline>
<source src="assets/videos/MovingAverageFilter_PowerPointAnimation_TrimmedAndCropped.mp4" type="video/mp4" />
</video>
**Video** This video illustrates a moving average filter of window size 3 over a subset of data. Animation made in PowerPoint.
Expand All @@ -109,7 +109,7 @@ Below, we compute three different moving average filter window sizes: 5, 10, and

<!-- The object-oriented filtering approach makes it easy to test and compare the effect of different window sizes on the filtered output. -->

<video autoplay loop muted playsinline>
<video aria-label="Raw analog input (blue) graphed alongside moving average filter output for three window sizes: 5 (red), 10 (green), and 20 (yellow), in the Arduino Serial Plotter" autoplay loop muted playsinline>
<source src="assets/videos/MovingAverageWithThreeWindowSizes-Optimized.mp4" type="video/mp4" />
</video>
**Video** This video graphs raw analog input (blue) and filtered output from three different moving average window sizes: 5 (red line), 10 (green), and 20 (yellow). To produce this video, we used [this code](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingAverageFilterWindowSizeDemo/MovingAverageFilterWindowSizeDemo.ino) and the [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/). You should [try it](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingAverageFilterWindowSizeDemo/MovingAverageFilterWindowSizeDemo.ino) yourself!
Expand Down Expand Up @@ -190,7 +190,7 @@ Below, we've included sample weights for both linear and exponential weighting s

| Linear Weights | Exponential Weights |
|:----------------:|:-------------:|
| ![](assets/images/WeightedMovingAverage_WindowSize15_Wikipedia.png) | ![](assets/images/ExponentialMovingAverageWeights_WindowSize15_Wikipedia.png) |
| ![Bar chart of linearly decreasing weights across a moving average window of size 15](assets/images/WeightedMovingAverage_WindowSize15_Wikipedia.png) | ![Bar chart of exponentially decreasing weights across a moving average window of size 15](assets/images/ExponentialMovingAverageWeights_WindowSize15_Wikipedia.png) |
| Linearly decreasing weights for window size 15 | Exponentially decreasing weights for window size 15|

**Figure.** Images from [Wikipedia](https://en.wikipedia.org/wiki/Moving_average).
Expand All @@ -217,7 +217,7 @@ Where:

The coefficient $$\alpha$$ determines the exponential dropoff. A higher $$\alpha$$ weights more recent data more. For example, the video below shows EWMA performance with $$\alpha$$ equal to 0.5 (red line), 0.1 (green line), and 0.01 (yellow line). Notice how closely the $$\alpha=0.5$$ EWMA filter tracks the underlying raw signal whereas the $$\alpha=0.01$$ filter is quite distorted and lagged. The $$\alpha=0.1$$ filter may still be appropriate, depending on your needs. Again, it's up to you to experiment!

<video autoplay loop muted playsinline>
<video aria-label="Exponentially weighted moving average filter output for three alpha values: 0.5 (red) tracking the raw signal closely, 0.1 (green), and 0.01 (yellow) heavily distorted and lagged" autoplay loop muted playsinline>
<source src="assets/videos/ExponentialMovingAverageFilter-ThreeAlphaValues-Optimized.mp4" type="video/mp4" />
</video>
**Video** This video shows EWMA performance with $$\alpha$$ equal to 0.5 (red line), 0.1 (green line), and 0.01 (yellow line). The code used to produce this video is [here](https://github.com/makeabilitylab/arduino/blob/master/Filters/EwmaFilterAlphaDemo/EwmaFilterAlphaDemo.ino). Graph made with the built-in [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/).
Expand Down Expand Up @@ -264,7 +264,7 @@ void loop()

A **moving median filter** is almost the exact same as a [moving average filter](#moving-average-filter) but takes the **median** over the sliding window rather than the average.

<video autoplay loop muted playsinline>
<video aria-label="An animation illustrating a moving median filter with a window size of three sliding over a signal to produce the smoothed output" autoplay loop muted playsinline>
<source src="assets/videos/MovingMedianFilter_PowerPointAnimation_TrimmedAndCropped.mp4" type="video/mp4" />
</video>
**Video** This video shows a moving median filter with a window size of three. Animation made in PowerPoint.
Expand Down Expand Up @@ -295,7 +295,7 @@ But how can we obtain this "middle" value efficiently? We know that re-sorting a

Similar to the moving average filter, we can tweak the moving median filter's performance by modifying the filter window size. Below, we show a moving median filter with window sizes 5, 11, and 21. For this video, we used our test code [MovingMedianFilterWindowSizeDemo.ino](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingMedianFilterWindowSizeDemo/MovingMedianFilterWindowSizeDemo.ino), which relies on Luis Llama's [Arduino Median Filter 2](https://github.com/warhog/Arduino-MedianFilter) library based on Phil Ekstrom's "[Better Than Average](https://www.embedded.com/better-than-average/)" article.

<video autoplay loop muted playsinline>
<video aria-label="Moving median filter output for window sizes 5, 11, and 21, showing how the median filter flattens peaks in the signal, graphed in the Arduino Serial Plotter" autoplay loop muted playsinline>
<source src="assets/videos/MovingMedianFilter-ThreeWindowSizes-TrimmedAndOptimized.mp4" type="video/mp4" />
</video>
**Video** This video shows moving median filter performance with window sizes 5, 11, and 21. Notice how a median filter tends to flatten "peaks" in the signal, which is unlike the other filters we've examined. To make this video, we used [this code](https://github.com/makeabilitylab/arduino/blob/master/Filters/MovingMedianFilterWindowSizeDemo/MovingMedianFilterWindowSizeDemo.ino) and the built-in [Arduino Serial Plotter](https://diyrobocars.com/2020/05/04/arduino-serial-plotter-the-missing-manual/).
Expand All @@ -305,7 +305,7 @@ Similar to the moving average filter, we can tweak the moving median filter's pe

Median filters are widely used in image processing to remove noise from images (image processing is its own subfield of signal processing focusing on 2D DSP techniques). Unlike mean (or average) filters, median filters remove noise while preserving edges—and edges are often a crucial part of other image processing algorithms like the [Canny edge detector](https://en.wikipedia.org/wiki/Canny_edge_detector).

![](assets/images/Medianfilterp_Wikipedia.png)
![A noisy image with salt-and-pepper speckle on the left and the same image after median filtering removes the noise while preserving edges on the right](assets/images/Medianfilterp_Wikipedia.png)
{: .mx-auto .align-center }

**Figure**. Median filtering is widely used in image processing where it is particularly effective at removing "speckle" or "salt-and-pepper" noise while preserving edges. Image from [Wikipedia](https://en.wikipedia.org/wiki/Median_filter).
Expand All @@ -315,7 +315,7 @@ In the case of 1-dimensional signal processing, which we've focused on in this l

| Moving Average Filter | Moving Median Filter |
|:----------------:|:-------------:|
| ![](assets/images/SignalSmoothingExample_13-OriginalMovingAverageAndSavitzkyGolay_MathWorks.png) | ![](assets/images/SignalSmoothingExample_14-OriginalVsMedianFilter.png) |
| ![Graph of a clock signal whose sharp rising and falling edges are distorted and rounded by a moving average filter](assets/images/SignalSmoothingExample_13-OriginalMovingAverageAndSavitzkyGolay_MathWorks.png) | ![Graph of a clock signal smoothed by a median filter that preserves and crispens the sharp transition edges](assets/images/SignalSmoothingExample_14-OriginalVsMedianFilter.png) |
| The moving average filter distorts the rising and falling edges of the clock signal | The median filter both smooths the signal and crispens the clock transition edges |

**Figure.** Images from [MathWorks](https://www.mathworks.com/help/signal/ug/signal-smoothing.html).
Expand Down
4 changes: 2 additions & 2 deletions arduino/led-blink3.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ This [source code](https://github.com/makeabilitylab/arduino/blob/master/Basics/
#### Workbench video

<div class="iframe-container">
<iframe src="https://www.youtube.com/embed/8DHhmXr3mC8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe title="Workbench video of an Arduino blinking multiple LEDs at different rates without using delay()" src="https://www.youtube.com/embed/8DHhmXr3mC8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

### Multi-rate blinking: an object-oriented approach
Expand Down Expand Up @@ -326,7 +326,7 @@ See the [code in our GitHub repository](https://github.com/makeabilitylab/arduin
#### Workbench video

<div class="iframe-container">
<iframe src="https://www.youtube.com/embed/vb5l8Tncedo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe title="Workbench video of multi-rate LED blinking using the Blinker class in external .h and .cpp files" src="https://www.youtube.com/embed/vb5l8Tncedo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

## Exercises
Expand Down
8 changes: 4 additions & 4 deletions arduino/rgb-led-fade.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ This [source code](https://github.com/makeabilitylab/arduino/blob/master/Basics/
Here are two videos showing the code running on an Arduino Uno. First, in the Tinkercad simulator. You can see the crossfade colors and a plot of the corresponding `analogWrite` values.

<div class="iframe-container">
<iframe src="https://www.youtube.com/embed/ZyfHRQFwmeg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe title="Tinkercad simulation of the RGB crossfader code with a plot of the corresponding analogWrite values" src="https://www.youtube.com/embed/ZyfHRQFwmeg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

Second, a workbench video of the code running on an Arduino Uno:

<div class="iframe-container">
<iframe src="https://www.youtube.com/embed/zL7xIWHqVaY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe title="Workbench video of the RGB crossfader code running on an Arduino Uno" src="https://www.youtube.com/embed/zL7xIWHqVaY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

<!--TODO: add in a p5js that demonstrates how this works? And maybe let's reader play with different color values? -->
Expand All @@ -169,7 +169,7 @@ RGB and HSL color space visualizations from [Wikipedia](https://en.wikipedia.org
Here's a video of various hues, saturations, and lightness levels using Hunor Marton's HSL Color Picker. Play around with it yourself on [codepen.io](https://codepen.io/HunorMarton/pen/dvXVvQ/). You can also open up almost any painting or graphics application to play with and switch between colorspaces from MSPaint to Adobe Photoshop and Illustrator to [GIMP](https://www.gimp.org/) and [Inkscape](https://inkscape.org/).

<div class="iframe-container">
<iframe src="https://www.youtube.com/embed/a0j8qyBJE2E" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe title="Screen recording of Hunor Marton's HSL Color Picker showing various hues, saturations, and lightness levels" src="https://www.youtube.com/embed/a0j8qyBJE2E" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
A screen recording of [Hunor Marton's HSL Color Picker](https://codepen.io/HunorMarton/pen/dvXVvQ/).
{: .fs-1 }
Expand Down Expand Up @@ -225,7 +225,7 @@ This [source code](https://github.com/makeabilitylab/arduino/blob/master/Basics/
Here's a workbench video of [CrossFadeHue.ino](https://github.com/makeabilitylab/arduino/tree/master/Basics/analogWrite/CrossFadeHue) with a common cathode RGB LED.

<div class="iframe-container">
<iframe src="https://www.youtube.com/embed/ROfJge7bsfI" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe title="Workbench video of the HSL-based RGB crossfader (CrossFadeHue.ino) running on a common cathode RGB LED" src="https://www.youtube.com/embed/ROfJge7bsfI" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

<!-- TODO look up what the minimum step value that makes sense with our quantization -->
Expand Down
6 changes: 3 additions & 3 deletions arduino/rgb-led.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ That's it. Now compile, upload, and run your code!
In the video below, I'm running our [BlinkRGB](https://github.com/makeabilitylab/arduino/tree/master/Basics/digitalWrite/BlinkRGB) code, which is the same as above but includes some [`Serial.print`](https://www.arduino.cc/reference/en/language/functions/communication/serial/print/) calls for debugging (see this [mini-tutorial](https://create.arduino.cc/projecthub/glowascii/serial-monitor-arduino-basics-399eb6) on using the Serial.print and the Arduino IDE's Serial Monitor for debugging)

<div class="iframe-container">
<iframe src="https://www.youtube.com/embed/ASez28rPjRU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe title="Workbench video of the BlinkRGB code cycling a common cathode RGB LED through colors, diffused by a yogurt container" src="https://www.youtube.com/embed/ASez28rPjRU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
The yogurt container is used to diffuse the light. Kleenex, white paper, or a ping pong ball (with a hole in it for the LED) works well too!
{: .fs-1 }

Below, we show a video animation of the code executing and resulting circuit behavior. Pay close attention to the direction of current—it will flow in the opposite direction with the Common Anode design (covered next).

<video controls="controls">
<video aria-label="Animation of a common cathode RGB LED circuit executing, showing the direction of current flow" controls="controls">
<source src="assets/movies/Arduino_RGBLED_CommonCathode_Animation.mp4" type="video/mp4">
</video>

Expand Down Expand Up @@ -249,7 +249,7 @@ We will flash the same sequence as before but again our `HIGH`s and `LOW`s are f

Here's an animation. Pay close attention to the current direction—it flows from 5V down through the LED, the current limiting resistors, and into the digital I/O pins.

<video controls="controls">
<video aria-label="Animation of a common anode RGB LED circuit with current flowing from 5V down through the LED and resistors into the digital I/O pins" controls="controls">
<source src="assets/movies/Arduino_RGBLED_CommonAnode_Animation.mp4" type="video/mp4">
</video>

Expand Down
Loading
Loading