• Write better Arduino code with advanced C++ features

    08/09/2018 at 22:19 0 comments

    The Arduino IDE allows to use advanced C++ features like classes and operator overloading. There are not many Arduino sketches that uses these features, but it can help to make your code more readable and maintainable.

    This is an example how to make the standard "blink" example easier to read:

    // general class to simplify the syntax to write to a pin
    class PinOut {
        PinOut(uint8_t pin): m_pin(pin) {
          pinMode(pin, OUTPUT);
        PinOut& operator= (uint8_t state) {
          digitalWrite(m_pin, state ? HIGH : LOW);
          return *this;
        uint8_t m_pin;
    // example usage: create a "led" object, which uses the pin number LED_BUILTIN
    PinOut led(LED_BUILTIN);
    void setup() {}
    // much easier to read "blinking" example
    void loop() {
      led = 1;
      led = 0;

    So instead of writing "digitalWrite(LED_BUILTIN, HIGH)" whenever you want to light up the LED, now you can just write "led = 1". You can create more objects for other pins as well, which makes your program much easier to read.

    Left as an exercise to the reader to implement a class for reading pins.

    You could outsource the class in a separate library, then you need just an include to use the class, without always copying the class declaration in your sketch.

    This example was inspired by the PortOut class of the mbed framework:


  • How to solder a 1 mm x 1.5 mm, 6 pad USON package IC

    06/22/2018 at 16:51 3 comments

    This page describes how I tested a TPS3420 reset chip on a breadboard. First I glued the chip in dead bug style on a SMD adapter board:

    Then I tinned the pads of the IC and of the SMD adapter (the pink things at the left side are my fingers) :

    For connecting the pads of the IC to the pads of the adapter, I used enameled wire, AWG 36 (0.12 mm diameter) :

    To remove the enamel, I used a scrap board and some more tin. The lacquer melts after some time and the wire gets tinned as well:

    Then I soldered one side of the wire to the SMD pad, first, and cut it to length. The scratches on the IC are in the flux residue, when I tried to position the wire with a scalpel. You need eagle eyes or a good microscope to do this.

    Then I soldered the other end the IC pad:

    If you move the soldering iron to strong, or apply too much heat or for too long, pads disappear, as happened for me. Buy some spare part.

    Finally I plugged in some pin headers in a breadboard and placed the SMD adapter on it. This guarantees that the pin headers are straight when soldering.

    Connected in a testing circuit:

    Testing: green is both button inputs and yellow is the reset output. 

    As specified in the datasheet, reset triggers after holding down both button inputs for 12.5 s, with TS=VCC configuration.

  • eBay Watt Meter review

    02/12/2018 at 22:40 0 comments

    I bought this watt meter from eBay. The case is a nice extruded aluminium case, but it is unusable for low currents. For example it shows 30 mA for a 100 mA load, tested with a passive resistor:

    And still about 28% error for 1 A, tested with a passive resistor as well:

    I guess for higher currents it gets better.

    Internally it uses a shunt in the ground path, which is called low-side current measurement. This might be a problem if you have other things connected to ground to the device you are measuring:

    It works down to about 4.7 V. But it should be possible to desolder the red wires from the board and solder a wire for an external power supply to the PCB.

    The display is soldered to the board, so I can't see details of the circuit:

    Conclusion: if you want to measure high currents above 1 A and don't care about accuracy, you can use this. Otherwise don't buy it.