$15 Wireless Display

output_Xzmr1W

I’ve been looking for a project to use the ESP8266 (ESP-03) wireless module. While playing around with these modules I figured it would be nice to have a place to send debugging data to without using the the serial terminal. I figured I could hook up a 16×2 display (QC1602A) that I ordered a while ago with the ESP and have a sweet wireless display unit. Unfortunately the ESP doesn’t have enough GPIOs to drive the display. I ended up ordering an Arduino Pro Mini of Ebay to control the display, which would in turn fetch the display data through the ESP.
Continue reading “$15 Wireless Display”

$15 Wireless Display

Arduino Uno – High Frequency PWM

I did some tests to see what max PWM frequency you can archive without overclocking the Uno and running it with the stock 16Mhz crystal. The default Arduino PWM frequency is 500Hz. If you need a higher frequency you have to manually bit-bang one of the output pins.

This example shows how to do a 30% duty cycle. The delays (and the overhead of the other instructions) determine the PWM frequency. In this case I got a PWM frequency of 9.1kHz . I disabled all interrupts to avoid any interference from processing interrupt service routines.

const int PWM_PIN = 8;

void setup()
{
  pinMode(PWM_PIN, OUTPUT);
  noInterrupts();

  // Don't use loop() to avoid serialEventRun overhead
  while (true) {
    // 30% duty
    digitalWrite(PWM_PIN, HIGH);
    delayMicroseconds(30);
    digitalWrite(PWM_PIN, LOW);
    delayMicroseconds(70);
  }
}

void loop(){}

Continue reading “Arduino Uno – High Frequency PWM”

Arduino Uno – High Frequency PWM

Analog Smoothing Library for Arduino

I wrote a Arduino library to smoothen jitter in analog output signals. This can be very useful when used with potentiometers, temperature sensors or similar devices.

The analogReadSmooth() function averages consecutive output readings. You can define how many readings you want to average (window size). Choosing a large window size will smoothen the output considerably but will also slow down detection of actual signal changes. You need to adjust the window size according to your needs when instantiating the AnalogSmooth object.

Here a brief usage example:

#include <AnalogSmooth.h>

int analogPin = 1;

// Defaults to window size 10
AnalogSmooth as = AnalogSmooth();

// Window size can range from 1 - 100
AnalogSmooth as100 = AnalogSmooth(100);

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Regular reading
  float analog = analogRead(analogPin);
  Serial.print("Non-Smooth: ");
  Serial.println(analog);
  
  // Smoothing with window size 10
  float analogSmooth = as.smooth(analog);
  Serial.print("Smooth (10): ");  
  Serial.println(analogSmooth);

  // Smoothing with window size 100
  float analogSmooth100 = as100.analogReadSmooth(analogPin);
  Serial.print("Smooth (100): ");  
  Serial.println(analogSmooth100);

  Serial.println("");
  delay(1000);
}

The library can be downloaded on GitHub and then simply needs to be placed in the Arduino libray folder.

Analog Smoothing Library for Arduino