• TopoR test

    03/14/2019 at 08:49 0 comments

    Just a quick test of the program TopoR. This is my Bloxorz cartridge, manually routed in KiCad:

    And this is the routing with TopoR:

    Looks very good, 100% routed, less vias (20 instead of 35) and shorter connections. I have to look in more detail into it how to specify different trace width for the power supply, but it is much better and easier than manual routing, or the KiCad auto-router. You can download a free trial of the program from their website, and a lite version with limited number of connections.

  • potentiometer on breadboard

    12/26/2018 at 13:59 0 comments

    Just a quick tip: If you use a stereo potentiometer with PC (printed circuit board) pins termination style, for example this one, then you can just plug it into a breadboard and it is very stable, perfect for prototyping. No need for soldering wires or any extra breakout board. The 2 potentiometers are in parallel, so use a 20 k pot, if you need 10 k.

    This image shows a similar potentiometer, I can't find the exact same model, but the datasheet of the Bourns potentiometer shows (nearly) 0.2" pitch as well, so it should work the same.

  • 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 {
      public:
        PinOut(uint8_t pin): m_pin(pin) {
          pinMode(pin, OUTPUT);
        }
    
        PinOut& operator= (uint8_t state) {
          digitalWrite(m_pin, state ? HIGH : LOW);
          return *this;
        }
    
      private:
        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;
      delay(1000);
      led = 0;
      delay(1000);
    }
    

    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:

    https://os.mbed.com/handbook/PortOut