header image
ArchLinuxARM Package Downgrading
March 18th, 2020 under Linux. [ Comments: none ]

I’m running ArchLinuxARM on my Odroid C2. After a system upgrade it wouldn’t boot anymore. So after going through some forums I figured out that systemd was the culprit. I had to downgrade to the previous version. However how do I achieve this when I have just x64 system laying around.

My goal was to take the MMC which stores the system of my Odroid C2 and mount it on my x64 so that a have access to the filesystem of the ArchLinuxARM installation. This is pretty straightforward with a memorycard adapter. Now comes the tricky part.

You need to be able to run arm executables (im my case aarch64). So the first step is to get qemu-user-static unto my x64 system. AUR has a package for this. After having built and installed this package copy the executable for your architecture to the mounted mmc. I mounted it to /mnt

1
cp /usr/bin/qemu-aarch64-static /mnt/usr/bin/
cp /usr/bin/qemu-aarch64-static /mnt/usr/bin/

Next you need the arch-install-scripts to get the arch-chroot command. This is a modified chroot command which sets up all ArchLinux specific configurations.

Now we execute pacman to downgrade the package on the mounted mmc.

1
arch-chroot /mnt qemu-aarch64-static /bin/pacman -U /var/cache/pacman/pkg/systemd-244.3-1-aarch64.pkg.tar.xz
arch-chroot /mnt qemu-aarch64-static /bin/pacman -U /var/cache/pacman/pkg/systemd-244.3-1-aarch64.pkg.tar.xz


Flashing the ESP-12 with Arduino UNO
April 17th, 2018 under Electronics. [ Comments: none ]

I recently I bought a Webduino-Smart. It’s an easily available ESP-12/ESP8266 chip in my country and it can be powered through a micro USB power supply. However, I’m not fond of the javascript based development methodology. Hence I wanted to move to a different firmware.

For me the ESP8266 Arduino Core was exactly what I was looking for. Especially, because I was already familiar with Arduino development.

Unfortunately, the Webduino-Smart does not feature a USB-TTL adapter. As a consequence, the Webduino Smart cannot be programmed/flashed as easily as I was used to from the Arduino UNO. After doing some research I was able to misuse the Arduino UNO board as an USB-TTL adapter.

So here is how I could upload my sketch from the Arduino IDE through the Arduino UNO to my Webduino-Smart.

  1. Remove the ATMEGA microcontroller from the Arduino UNO. The Arduino is still accessible through the device /dev/ttyACM0.
  2. Then connect the communication channels tx and rx from the Arduino to the Webduino. (TX <-> TX, RX <-> RX)
  3. Connect the grounds of the two boards (GND <-> GND).
  4. Pull the GPIO0 of the Webduino to 0 by connecting it to the ground of the Arduino (GND <-> 00). This puts the ESP-12/ESP8266 into flash mode and lets you flash a new firmware to the device.
  5. Power the Webduino with 3.3V by connecting the 3.3V ouput from the Arduino to the power input VCC of the Webduino (3.3V <-> VCC).
  6. Select the ttyACM0 connection in the Arduino IDE (Menu Tools -> Port).
  7. Choose “Generic ESP8266 Module” as your board in the Arduino IDE (Menu Tools -> Board). This option is only available if you installed the ESP8266 Arduino Core.
  8. Leave all other settings to their default values
  9. Upload the sketch by pressing the upload button in the Arduino IDE.Note: I had to disconnect and reconnect the power of the Webduino before uploading a sketch.

In order to run the sketch I simply removed the (GND <-> 00) connection so that the Webduino boots no longer into flash mode. Then reboot the Webduino by disconnecting and reconnecting the power supply.

I read somewhere that it is not necessary to remove the ATMEGA microcontroller. The entire process should also work with the controller in place. I never tried this since I was fine flashing to Webduino without the controller.

Disclaimer: I know that the Webduino runs on 3.3V but the TX/RX pin of the Arduino are 5V. So, there is a risk of frying the Webduino. It worked for me without problems though. So, just for the record, use this procedure at your own risk!


How The Economic Machine Works by Ray Dalio
May 3rd, 2016 under Economics. [ Comments: none ]


Toggle all Charts between Logarithmic and Linear Scale
September 1st, 2015 under Excel. [ Comments: none ]

I had multiple chart in one Excel Worksheet and wanted to change the scale of the x-axis and y-axis to the logarithmic scale. The following macro toggles between the linear and logarithmic scale for all charts:

1
2
3
4
5
6
7
8
9
10
11
12
13
Sub ChartsToggle()
    For i = 1 To ActiveSheet.ChartObjects.Count      
      Application.DisplayAlerts = False
      If ActiveSheet.ChartObjects(i).Chart.Axes(xlCategory).ScaleType = xlLinear Then
        ActiveSheet.ChartObjects(i).Chart.Axes(xlCategory).ScaleType = xlLogarithmic
        ActiveSheet.ChartObjects(i).Chart.Axes(xlValue).ScaleType = xlLogarithmic
      Else
        ActiveSheet.ChartObjects(i).Chart.Axes(xlCategory).ScaleType = xlLinear
        ActiveSheet.ChartObjects(i).Chart.Axes(xlValue).ScaleType = xlLinear
      End If
    Next i
  Application.DisplayAlerts = True
End Sub
Sub ChartsToggle()
    For i = 1 To ActiveSheet.ChartObjects.Count      
      Application.DisplayAlerts = False
      If ActiveSheet.ChartObjects(i).Chart.Axes(xlCategory).ScaleType = xlLinear Then
        ActiveSheet.ChartObjects(i).Chart.Axes(xlCategory).ScaleType = xlLogarithmic
        ActiveSheet.ChartObjects(i).Chart.Axes(xlValue).ScaleType = xlLogarithmic
      Else
        ActiveSheet.ChartObjects(i).Chart.Axes(xlCategory).ScaleType = xlLinear
        ActiveSheet.ChartObjects(i).Chart.Axes(xlValue).ScaleType = xlLinear
      End If
    Next i
  Application.DisplayAlerts = True
End Sub

Note the

1
Application.DisplayAlerts = False
Application.DisplayAlerts = False
. This prevents Excel from opening a dialog box, for every chart, informing you that negative values cannot be displayed. The dialog is just shown once at the end. I had to put this line inside the for-loop because it got changed back to true after the chart modification.


Calculate Expected Shortfall in SQL
August 20th, 2015 under Programming. [ Comments: none ]

A commonly used risk measure is the Expected Shortfall. Unfortunately, this function to calculate the sample expected shortfall is rarely implemented. As there is much data stored in databases accessible through SQL, I tried to calculate this value directly in SQL. It turns out this is a one-liner. Let’s assume we have a table called “LossSimulation” and a column/field named “LossValue” then the sample expected shortfall at level 95% is

1
SELECT AVG(LossValue) FROM (SELECT TOP 95 PERCENT LossValue FROM LossSimulation ORDER BY LossValue)
SELECT AVG(LossValue) FROM (SELECT TOP 95 PERCENT LossValue FROM LossSimulation ORDER BY LossValue)

Note: Microsoft Access may list more than 95% of all records because if multiple value at the 95% quantile value are the same then all these records are listed (see here).


« Previous entries