Tighten your thermistor

This is just a PSA for all of you owners of an Anycubic i3 Mega (or any other printer for that matter) that are suffering heavy temperature oscillations or are otherwise unable to get a stable temperature during prints.

Looks like it is a common problem with multiple causes, ranging from physical problems in either the hotend, the thermistor, the cartridge heater or the controller board, to firmware problems regarding PID calibration.

This is what those oscillations look like in Octopi:



As you can see, my temps were wildly varying, sometimes ±15ºC, which would occasionally trigger an error stating “Heating failed, system stopped”. I repeated Marlin’s PID calibration procedure countless times, to no avail. Eventually I accepted I would have to live with that (or change the hotend), so I relaxed some safety parameters in Marlin (particularly regarding hysteresis) so at least I could print without that error popping up.

However after some days, I realized the thermistor (the element that measures the temperature of the hot end) was oddly placed, and when the printer cooled down I poked it with tweezers. To my suprise, it moved freely, it was totally loose within the heating block! Here’s a video:

There’s a small hole on the left with a really small screw that secures the thermistor in place. I used a small allen key to tighten it (it was totally loose) so the thermistor couldn’t move. After that, I re-run the PID calibration procedure and BOOM, totally stable temperatures! Amazing.


3D printed Arduino button pad

This is a simple yet useful project built using Arduino and my 3D printer, the Anycubic i3 Mega. It’s a 5x button pad to launch shortcuts or do actions in your computer. The requirements are:

  • 1 x Arduino Nano. They’re really powerful and fulfill this task perfectly. Probably you could use a simpler microcontroller for this.
  • 5 x push buttons, better if you mix the colors.
  • Some AWG30 wiring.
  • A 3D printer, like the Anycubic i3 Mega.
  • A mini USB cable to connect everything.
  • A couple of M2.5 screws.


3D design

The 3D design was made using Fusion 360, my favorite program to design things to be built on a 3D printer. The learning curve can be harsh, but once you grasp how everything revolves around sketches everything starts to make sense.


If you don’t feel like learning Fusion 360, you can get the 3D files clicking here. As you can see, the design is pretty simple, just a box with a lid and some holes, and a small structure to hold the Arduino Nano in place.

I printed it using SUNLU black PLA with a layer height of 0.3, no need for fine detail anyway.


The electronics in this project are braindead easy. Just connect one of the leads of each button to ground, and connect the other leads to D2, D3, D4, D5 and D6 in the Arduino Nano. Boom, you’re done.


Stick everything into the box and place the two screws in the corners to close the lid.


The software is the “hardest” part, but it’s all done for you already. You can find the latest release of the software at https://github.com/JoseTomasTocino/ArduinoButtonPad/releases.

First, you need to flash the Arduino using the sketch contained in the ArduinoSketch.zip file of the release. Check the code, it’s pretty simple. It just sends a string using the serial port whenever you press (actually, release) a button.

Then, you need a desktop application to control what happens in your operating system whenever you press a button. This app has been developed using C++ and Qt 5.14, and it’s obviously open source. You’ll find the compiled 64bit version of the software for Windows in the ArduinoButtonPad-1.0.0.zip file of the release.

The software is pretty straightforward. The functionality is separated in three groups.


  • Serial communication info: here you’ll find some info about the serial port the Arduino is using to send the signals. If it says none, make sure your Arduino is properly connected and the click Scan COM ports.
  • Profiles: here you can configure a profile for the buttons. These define what action each button does. You can have many different profiles for every situation, and type what command should each button launch. You can also toggle the checkbox at the botton to use the fifth button to cycle through the profiles, so you can jump from one profile to another really easily.
  • Other settings: you can select whether this preferences window of the application should appear at the beginning, and whether the application should start automatically when Windows boots.

Future improvements

There’s always room for improvement, and I’ve come across some ideas during the development that I may or may not tackle at the future:

  • The feeling of the pushbuttons is not so good. I’d rather use some more tactile, clicky buttons. It would be great to use some Cherry MX Blue switches, that’d be rad.
  • Using an Arduino Nano is kind of overkill. If I knew actual electronics I could’ve done a dedicated circuit for this, but that’s way beyond my knowledge. However, trying to use something like Digispark’s ATTiny85 could also work.
  • The 3D printed enclosure is OK, but it could be improved, specially the lid that kind of hovers over the box. I should’ve added an inner lip to improve the fit.


I hope you like this project and find it interesting. If you have any suggestions, leave them in the comments or open an issue to the bug tracker at GitHub.

Thanks for reading!

Developing for Arduino in Windows using PlatformIO and JetBrains CLion

If you’re reading this, chances are you’re already familiar with Arduino and its… kind of limited IDE. The official development environment is pretty limited, and the moment the project grows a little bit it becomes very inconvenient.

Thankfully there are several alternatives, and one of the most interesting ones leverages PlatformIO, a cross-platform development environment for embedded programming, and Jetbrains CLion, nowdays the most advanced C/C++ IDE, period.


First of all, click here to go to the Jetbrains website and download CLion. There’s a free trial for 30 days, and some offers for students.

Next, you have to install PlatformIO Core, you have the instructions right here. There’s also PlatformIO IDE, the most popular option, which bundles VSCode as the default editor. But for us, PlatformIO Core is just fine. After installation you’ll have a “platformio” command available at your command prompt.

Creating your first project

Once you’ve downloaded and installed everything you need, open a command prompt, navigate to the folder where you want to store your project and run:

platformio init --ide clion --board uno

This will create the necessary files for you to start your project, including a simple main.cpp file to start coding. Now open CLion, choose open project and open the folder you’ve just created. The project pane on the left side should look something like this:

Place your source files in the include or src folders and you’re good to go.

Building the project

Building your newly coded project is pretty easy, as PlatformIO already creates predefined configurations to compile and upload the data. Most of the time you’ll be compiling and uploading at the same time, so the PLATFORMIO_UPLOAD target will be the most appropriate one. Select it from the combobox you’ll find in the toolbar and click the hammer button beside it. DO NOT CLICK RUN (the green triangle button). Before building, make sure your Arduino is connected to the PC.

Once the build finishes, you’ll see this in the messages pane at the bottom:

========================= [SUCCESS] Took 9.28 seconds =========================

Build finished

And that’s it.


There are a few quirks in this workflow, but that’s the price you have to pay if you want to use this incredible editor. So far I’ve come across the following:

  • Sometimes when building, the compiler will complain about a missing SPI.h file. Make sure you’re including the Arduino.h header file and reopen the project.
  • Whenever you need to add a new file to the project you’ll have to re-run the initial platformio command we just saw before.

You can always find more information at the official PlatformIO docs online.

Bug in QProcess::stateChanged

This bug is easy to replicate and it’s been present for a long time. In fact, this bug report was sent in 2013 and still waits to be fixed.

If you have a QProcess and you use the QProcess::stateChanged signal to check when the process goes down, do not try to restart the process in the slot attached to the signal because the QProcess state will get stuck in QProcess::Starting and it won’t work.

Instead, restart your process in a slot connected to the QProcess::finished signal, or use QTimer::singleShot within the handler of stateChanged to enqueue the process restart instead of doing it immediately.

Fixing interference noise on JBL LSR 305 monitors


TL;DR: If you’re suffering from interference noise in your studio monitors, try using an external DAC. If you STILL keep hearing interference noises, don’t power the DAC from the PC but from a phone charger or something else, your power supply may be causing the interferences.

I recently purchased a pair of JBL LSR305 along with a JBL NanoPatch+ as a beefy volume knob. They sound ridiculously great when I connect them to my phone, but when I first hooked them to my computer (to the motherboard’s audio output) there was a lot of buzzing noise, that heavily (and I mean HEAVILY) increased whenever the graphics card was working hard, such as in games (Overwatch!).

I read a lot about this kind of noises. There are a lot of possible reasons, but the end result is that the analog signal coming from the PC is noisy. The analog signal that is fed to the speakers is built by converting a digital signal generated by the computer software or read from digital sources such as a CD to its analog equivalent. This transformation is done by a Digital-to-analog converter (DAC). If that transformation is done within a noisy environment, such as inside a computer case, the final analog signal may get affected.

A common suggestion is to use an external (as in, physically external) DAC, so that the conversion is done outside the PC case and no interference could ever affect the analog signal, so I bought the cheapest DAC I could find, this PROZOR DAC001. I connected the optical audio in, which is a pure digital signal coming from the PC, and the power cable, which is a 5V DC wire connected to a USB port, and… voilá, the noises were still there.

What. There was no way the digital signal could transport such interferences, so there was only another suspect left: the power cable. I moved it from a USB port to a phone charger and BOOM, no noise!

So there you got it, looks like my power supply is causing interferences inside the case AND through the USBs too. I guess it must be about to die. For the time being I’m gonna keep using the phone charger but I guess I’ll have to swap the power supply sooner or later. Hope it helps.

Showing Qt debug messages in RHEL and derivatives

If you’re working with Qt and RHEL 7.x (or any derivatives) you may have come across a bug where qDebug messages do not show up. According to this post in RedHat’s bug tracker, looks like the default logging settings are quite restrictive “[…] by design. Our users do not want to get spammed with debugging output”. You can check it by yourself at /usr/share/qt5/qtlogging.ini


The solution is pretty simple. According to the official Qt docs, you can override the settings in that file by creating your own at ~/.config/QtProject/qtlogging.ini. Mine looks like this:


That shows all debug messages except those from Qt’s internal code.

Accessing another user’s DBus in XFCE

In a RHEL73 system with XFCE I wanted to change the wallpaper from a script run by root, so I searched and found that, in theory, it could be done using

xfconf-query -c xfce4-desktop \
 -p /backdrop/screen0/monitorDP-5/workspace0/last-image \
 --set PATH_FILE

If I launched that command from a terminal from within xfce with a normal user it worked, but it didn’t work if I launched it with root, nor launching it from a tty or the provisioning script. The error I was getting was:

Failed to init libxfconf: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

I started diggin up and it seemed related to Dbus, as any configuration changes made with xfconf-query were actually relayed through Dbus. I tried running the same command prepending dbus-launch, and now the error was different:

Property “/backdrop/screen0/monitorDP-7/workspace0/last-image” does not exist on channel “xfce4-desktop”

I kept reading about DBus, discovered dbus-send and managed to replicate the call xfconf-query was doing, like this:

dbus-send --session --print-reply --type=method_call --dest=org.xfce.Xfconf /org/xfce/Xfconf org.xfce.Xfconf.SetProperty string:'xfce4-desktop' string:'/backdrop/screen0/monitorDP-7/workspace0/last-image' variant:string:'IMAGE_PATH' 

Same as before, it worked from the xfce4 terminal, but not from anywhere else. Kept reading about DBus, remembered that each session for each user has a different DBus session bus, so any changes I did from a root or a tty session would not be reflected upon the main XFCE4 session.

I tried fetching the DBUS_SESSION_BUS_ADDRESS of the main xfce4-session in order to match the session bus, but it didn’t work. I was doing it like this:

export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pidof -s xfce4-session)/environ |cut -d"=" -f2-)

The xfconf-query command failed as in the first case (with: "Failed to init libxfconf..."). However, it seemed that in order to have access to the session bus you need to match both the address and the user, so combining the two I finally managed to do it:

export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pidof -s xfce4-session)/environ |cut -d"=" -f2-)
su YOUR_USER -m -c 'xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDP-5/workspace0/last-image --set IMAGE_PATH


Colored logging in Qt & QtCreator

I’ve just come across this article at woboq about improving debug output in Qt. It turns out there’s a config variable named QT_MESSAGE_PATTERN which holds the format of the debug messages (printed by qDebug and qInfo among others).

You can use several different placeholders, like %{threadid} to output the current thread ID and so on. You can see all the available placeholders here in the docs. ANSI color codes can be used as well.

You can set it as an environment variable, from within your code, using setenv, or use qSetMessagePattern, like so:

        "\033[32m%{time h:mm:ss}"
        "\033[33m %{threadid} "
        "%{if-category}\033[32m %{category}:%{endif}"
        "%{if-warning}\033[31m%{backtrace depth=3}%{endif}"
        "%{if-critical}\033[31m%{backtrace depth=3}%{endif}"
        "%{if-fatal}\033[31m%{backtrace depth=3}%{endif}"
        "\033[0m %{message}"

 And the debug output will look like this (in QtCreator and also in the terminal):

2018-02-07 14_20_03-f110d2_3 (jttocinog)

Ain’t that cool or what.