header image
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).


Unconstrained Optimization
August 13th, 2015 under Programming. [ Comments: none ]

MATLAB/GNU Octave offers simple ways to find the minimum of any function. The two easiest methods are

1
fminsearch
fminsearch
and
1
fminunc
fminunc
. The former uses a simplex search method while the latter uses a gradient based method.

Here is a simple example for a lognormal parameter estimation:

1
2
3
4
x = sort([0.0027400 0.0093730 0.0458460 0.0135300])
y = (1:length(x))./(length(x)+1)
fun = @(p) sum( (logninv(y,p(1),p(2)) - x).^2)
estimate = fminsearch(fun,[-5;2])
x = sort([0.0027400 0.0093730 0.0458460 0.0135300])
y = (1:length(x))./(length(x)+1)
fun = @(p) sum( (logninv(y,p(1),p(2)) - x).^2)
estimate = fminsearch(fun,[-5;2])


« Previous entries