MP1584 buck converter module

This small module MP1584 buck-converter module seems to be a good solution to power small circuits from higher voltages. Especially cool with this chip is that it accepts input voltages up to 29V. This makes it a perfect candidate for additional circuits that connect to a KNX bus. But it’s not limited to KNX buses. If you want to build a WiFi interface for your Roomba, you also have to down-regulate the 15V battery voltage to 5V or even 3.3V. You want to something to power a circuit from a car battery? This seems to be a perfect circuit for there use cases.

mp1584With it’s tiny dimensions of 17 x 22mm it’s size is around the size of 2 MicroSD cards (and much smaller than a single SD card).

The output voltage of the module is controlled by a tiny potentiometer. You will need a multimeter to check the output voltage before connecting it to a circuit.

While the plain voltage range data seems to be quite good, how does the circuit behave on different loads? Some Chinese dealers claim that similar modules should handle 3A load. If you just look at the size of the inductor you might already start thinking that this most likely isn’t true. However, DC resistance of the inductor is approximately 10mOhm (I miss my Kelvin probes and therefore could only measure this very roughly).

Let’s start with 29V input voltage – this will bring everything to the limit. Output voltage is fixed to 5V in this experiment. Without any current drawn, it still looks a bit rough:

29_0

However, a voltage swing of (Vpp) 98mV is no problem at all. Between 0.1A and 0.9A the circuit behaves quite well. Vpp is around 0.2V (a bit lower on low currents, higher in higher currents)

29_0.5

We reach the end at 1A. Now the regulator doesn’t provide a stable output voltage anymore:
29_1

But what about lower input voltages? Let’s go the the other “extreme”: 9V (it will work with even less, but let’s give it a bit headroom).

Almost perfectly clean with no load:
9_0

A bit more stable than at 29V for currents between 0.1A and 0.7A:

9_0.4

And at 0.7A we reach the end of the useable current range:

9_0.7

Conclusion: This module works fine for almost every embedded use case: Arduino, ESP8266 WiFi modules and even a Raspberry Pi without any additional USB devices plugged in.

Here are 2 animation that shows the output voltage under different loads:

29V input, 5V output, 0-1A in 0.1A steps:

29v_animated

9V input, %V output, 0-0.7A in 0.1A steps:

9v_animated

Power supplies for LED installations

If you look around on the Internet you will find a lot of interesting DIY LED installations. Most projects are stripes for lighting and Ambilight clones. Last week I stumbled across a very good guide how to build your own Ambilight clone. I won’t link to this guide as it had one big problem: safety!

Many projects use power supplies similar to this one:

pl8886134-short_circuit_protection_standard_led_display_power_supply_100w_5v_20a_ip20_60hz_en1122

Why? Because they are available quite cheap from many Chinese suppliers. I can’t say if a specific power supply itself is safe. With this type of power supply, the build quality is usually quite good because you can see most parts and people wouldn’t buy them if you can already see that parts are not soldered correctly. Note that this doesn’t say anything about the quality of the parts. But let’s just say, the manufacturer designed this power supply well and it is safe. Why shouldn’t you use something like this? Why isn’t it safe?

Many DIY installations install power supplies in places where they are hidden, but can still be accessed  from the outside. Check out this picture:

powersupply-unsafe

You won’t see the power supply from the front, however, the mains is still relatively easy accessible. Even if you don’t have kids at home, this is unsafe!

There is an easy way to deal with this problem: You should use fully capsulated power supplies with standard AC cables like this one:

laptop-adapter-ac-adapter

This type of power supplies is also available in many different voltages with a power range of up to 100W – more than enough for usual LED installations.

Battery powered ESP8266 sensor

The ESP8266 is a powerful and inexpensive device. There is almost no need anymore to use proprietary RF protocols like the nRF24 chip that was popular some years ago. However, there is one major problem when using WLAN: power consumption.

When connected to a WLAN, the ESP8266 consumes at least 80mA – sometimes even more. If you use 3 2400mAh that means, they will be empty in a bit more than a day. This doesn’t sound like a good deal.

Luckily, for sensor applications, you don’t have to be connected to the LAN the whole time. You don’t even have to have the ESP itself running. To save as much power as possible, you have to do the following:

  1. Collect your data. If this takes time, do it before connecting to WLAN. If it takes just a few millesconds, it doesn’t matter much.
  2. Connect to WLAN.
  3. Send data.
  4. Go to deep sleep mode. You use the ESP.deepSleep() method for this.

You have to look at a few things when using the ESP.deepSleep() method:

  1. To wake up after sleeping, GPIO16 of the ESP8266 has to be connected to RESET. Otherwise the device won’t wake up again.
  2. The delay parameter is defined in microseconds (not seconds or milliseconds). If it looks like your device isn’t sleeping at all, you might have used a value that is too small (you won’t even notice if the device sleeps for 3600 microseconds)
  3. There is a second parameter that can have the values WAKE_RF_DEFAULT, WAKE_RFCAL,WAKE_NO_RFCAL, WAKE_RF_DISABLED. The WAKE_RF_DISABLED looks good, but beware to use it. Using this does not mean that the RF subsystem is disabled during sleep (it always is), but that it is disabled when waking up again. Your ESP8266 won’t be able to do any network communication anymore.

A few other tips to save energy:

  1. Do not turn on LEDs for a longer time. Flashing them a few milliseconds is usually a good visual feedback and will consume only a tiny bit of energy.
  2. If you need to have LEDs on for a longer time, dimm them. analogWrite is your friend for this.

Check out this sample code. It uses WiFiManager which helps to connect to configure your WLAN SSID/password and even the name/IP address of the MQTT broker.

#include         // Generic ESP8266 WiFi routines
#include        // MQTT client
#include           // Local DNS Server used for redirecting all requests to the configuration portal
#include    // Local WebServer used to serve the configuration portal
#include         // WiFi Configuration Magic


const char* mqtt_server = "192.168.1.88";
const char* mqtt_channel_up = "active";
const char* mqtt_channel_data = "sensor/%d/adc";

const int pin_red = 15;
const int pin_green = 12;
const int pin_blue = 13;
const int pin_button = 4;
const int analog_ldr = 0;

const int sleepSeconds = 60 * 15;

WiFiManager wifiManager;
WiFiClient espClient;
PubSubClient client(espClient);


void send_sensor_data(void) {
  Serial.println("Sending sensor data\n");
  int data = analogRead(A0);
  char s_channel[50];
  char s_id[10];
  char s_data[10];
  sprintf(s_channel, mqtt_channel_data, ESP.getChipId());
  sprintf(s_id, "%d", ESP.getChipId());
  sprintf(s_data, "%d", data);

  digitalWrite(pin_blue, HIGH);
  client.connect("ESP8266Client");
  digitalWrite(pin_blue, LOW);
  if (! client.connected()) {
    Serial.println("Could not connect to MQTT broker, doing nothing");
  } else {
    digitalWrite(pin_green, HIGH);
    client.publish(mqtt_channel_up, s_id); // show that this device is up
    client.publish(s_channel, s_data); // send sensor data
    digitalWrite(pin_green, LOW);
  }
}

void setup() {
  delay(500); // This makes it easier to upload new firmware and/or press the "clean" button

  pinMode(pin_red, OUTPUT);
  pinMode(pin_green, OUTPUT);
  pinMode(pin_blue, OUTPUT);

  digitalWrite(pin_red, HIGH);

  // Setup Serial interface for debugging
  Serial.begin(115200);

  //  Bring up WLAN
  WiFiManager wifiManager;

  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  wifiManager.setTimeout(60);

  WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
  wifiManager.addParameter(&custom_mqtt_server);

  if (digitalRead(pin_button) == 0) {
    // reset settings
    wifiManager.resetSettings();
  }

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect()) {
    Serial.println("failed to connect and hit timeout");
    delay(100);
    // do nothing: deep sleep, but longer than usual. Something might be wrong and
    // we should save power
    ESP.deepSleep(sleepSeconds * 10 * 1000000, WAKE_RF_DISABLED);
  }

  mqtt_server = custom_mqtt_server.getValue();

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Setup MQTT client
  client.setServer(mqtt_server, 1883);

  digitalWrite(pin_red, LOW);
}

void loop(void) {
  send_sensor_data();
  Serial.printf("Sleeping deep for %i seconds...", sleepSeconds);
  ESP.deepSleep(sleepSeconds * 1000000);
  delay(100);
}

A minimal KNX setup

If you are an experienced electronics hacker and you want to do some tests with KNX, you need to invest a bit. However, a minimal KNX setup for initial tests doesn’t have to be very expensive:

  • a 29V power supply that supplies at least 300mA
    Most bench power supplies will do the job. For a test you don’t have to buy an expensive KNX power supply.
  • a KNX choke
    You can’t connect KNX devices directly to the power supply. A choke is essential. Without it, no communication on the bus will be possible. Standalone chokes starts at around 35€.
    Another option is using a 47-Ohm resistor in between the power supply and your KNX bus line. While it might not work, it is worth a try as it will cost you only a few cent.
  • a KNX sensor
    If you have some push buttons laying around, a cheap KNX bus coupler from eBay might be the cheapest option. You can get these for less than 30€
  • a KNX actuator
    Some KNX sensors (like wall-mounted push buttons) have status LEDs that can be controlled from the KNX bus. In this case, you do not need a separate actuator. Otherwise have a look on eBay for old binary outputs. You should be able to find something for less than 30€
  • USB or Ethernet interface
    USB interfaces are usually a bit cheaper. You might find used USB interfaces in the range of 50-80€. However, I would still recommend to spend a bit more money and buy an Ethernet/KNX interface. You are more flexible with these as multiple devices can access it simultaneously. You might not be able to save a lot of money on a used one, but new Ethernet interfaces are available from 150€

This means, a minimal KNX setup will cost you between 200€ and 300€. This isn’t really cheap, but still less expensive than many people might think. The good thing: The most expensive component is the Ethernet interface. If you decide not to go on with a full KNX installation, you can still sell it for a good price. Otherwise, you can use this in your house installation.

The minimal installation looks like this:

Minimal KNX installation