Page 3 of 3

Re: Global Earthquake Display on ILI9341 TFT. - From old forum.

Posted: Tue Aug 10, 2021 2:42 pm
by AndyGadget
(We're not leaving Andy anything to do 8-) )
Well, I've just received my ILI9488 and a couple more ESP32 modules so I'll be putting those together.

That's the way I did it; using an on-line polynomial fitter to generate the equation only I used https://mycurvefit.com/

The query I raised in the 'bugs' section about slow write speeds on an ESP32 is a bit of a bother as well. Not a problem when all is up and running but during debugging I was corrupting my history file if I forgot to wait a minute or so after a re-run for the write to complete. I'm wondering if the same problem would occur using FILE.SAVE_IOBUFF to save the data in one hit rather than as discrete writes.

There is a slight difference in my map in that I shifted the x axis a couple of hundred miles to give New Zealand a bit of breathing space and to stop Hawaii being right on the 'fold' of the map as these places do see a lot of seismic activity. (Isn't that the way when you're using a paper map; The place you're interested in is either on the fold or right on the edge :D)

The thing about map projections is there are so many to choose from (although only a couple which you can sensibly put on an LCD screen). I did try it with an equirectangular projection which would have made both the X and Y axes linear but Africa and the Americas were so stretched from what we're used to seeing that it didn't look 'right'.

Re: Global Earthquake Display on ILI9341 TFT. - From old forum.

Posted: Tue Aug 10, 2021 2:58 pm
by Fernando Perez
That is correct, it seems to work very well.
There have only been two earthquakes since I made the switch, but they match the location on the jpg map with the Google Maps image for those coordinates.
Perfect!
image.png

Re: Global Earthquake Display on ILI9341 TFT. - From old forum.

Posted: Wed Aug 11, 2021 9:18 pm
by Fernando Perez
The formula plots the pixel at the appropriate point on the y-axis.
But when trying to systematize it, I have found curious points.
Please reproduce this code in your Annex:

Code: [Local Link Removed for Guests]

wlog "Start"

while 1

  wlog
  sign = rnd(1) : if sign > 0.5 then sig = 1 else sign = -1
  lat = rnd(91) * sign : wlog "latitude: "; lat
  wlog
  
  y = 0
  y = y + (221.9496 * (lat^0))   : wlog y; " step 0"
  y = y + (-1.417675 * lat^1)    : wlog y; " step 1"
  y = y + (3.483879e-3 * lat^2)  : wlog y; " step 2"
  y = y + (2.5858636e-5 * lat^3) : wlog y; " step 3"
  y = y + (-2.116389e-6 * lat^4) : wlog y; " step 4"
  y = y + (-2.5483e-8 * lat^5)   : wlog y; " step 5"                    
  y = y + (2.78e-10 * lat^6)     : wlog y; " step 6"
  wlog

  y = 2.78e-10*lat^6-2.5483e-8*lat^5-2.116389e-6*lat^4+2.5858636e-5*lat^3+3.483879e-3*lat^2-1.417675*lat+221.9496
  wlog y; " single line"
  
  pause 5000

wend

In mine I observe that from step 2, the result does not vary.
image.png
Could we do without in the formula of steps 3, 4, 5 and 6?
Or, even, since the y-pixel is an integer value, skip step 2?

Code: [Local Link Removed for Guests]

y = cint(221.9496 - 1.417675 * lat)
It has nothing to do with this, but I have observed that if I start the program with WHILE 1, the loop only executes once. If I put something like WLOG "Start", it works fine.
Also, if I remove the parentheses around the (lat ^ 0), the result is not equal to 1. It seems that in this case the precedence of the operators is not respected.
What do you think?

Re: Global Earthquake Display on ILI9341 TFT. - From old forum.

Posted: Thu Aug 12, 2021 9:40 am
by Fernando Perez
I have already recorded a sufficient number of earthquakes and the accuracy seems to be quite good.
So I propose this version, with the abbreviated formula. If they enter the coordinates in Google Maps, as they appear on the TFT screen, it takes them directly to the map to compare precision.

Code: [Local Link Removed for Guests]

server$ = "seismicportal.eu/fdsnws/event/1/query?limit=1&format=json"
idPrev$ = ""
on = 0 : x = 0 : y = 0 : pMag = 0

tft.init 1  ' ILI9486 480x320 3.5"
tft.text.align 8
tft.jpg "/map.jpg"  ' display image with map

timer0 500, blink
timer1 60000, query
gosub query
wait

' -----------------------------
query:
  result$ = wGet$(server$, 443, 0, 1)

  id$ = json$(result$, "id")
  if id$ <> idPrev$ then
    idPrev$ = id$
    ' wlog result$

    loc$ = json$(result$, "flynn_region")
    if loc$ = "not found" then return

    ' Load map to clear display, then print text info about event
    tft.jpg "/map.jpg"
    gui.redraw
    tft.text.color black
        
    mag$ = json$(result$, "mag")
    tft.text.draw mag$, 55, 45, 4

    tEvent$ = mid$(json$(result$, "lastupdate"), 12, 5)
    tft.text.draw tEvent$, 455, 35, 3
    
    ' Break location text neatly and display on 2 lines if long
    lines = word.count(loc$)
    for line = 0 to lines - 1
      tft.text.draw word$(loc$, line + 1), 130, 240 + (line * 20), 3
    next line  
    
    ' Convert longitude and latitude of event to screen co-ordinates
    lon = val(json$(result$, "lon"))
    x = cInt(convert.map(lon, -180, 180, 0, 480))
    lat = val(json$(result$, "lat"))
    y = cint(221.9496 - 1.417675 * lat)
 
    ' Size of plotted circle is proportional to quake magnitude 
    pMag = cInt(val(mag$) * 0.8)
    if pMag <= 1 then pMag = 1

    ' Plot most recent event
    tft.circle x, y, pMag, &HF800, 1
    
    coordinates$ = str$(lat) + ", " + str$(lon)
    tft.text.draw coordinates$, 360, 310, 3
    
   '  wlog
   '  wlog loc$
   '  wlog coordinates$
   '  wlog " X = "; str$(x), " Y = "; str$(y)

  end if

return

' ------ flashing point -------
blink:
  on = 1 - on
  if on = 0 then tft.circle x, y, pMag, &HFFE0, 1 else tft.circle x, y, pMag, &HF800, 1
return
https://www.myrapidq.it/public/Argentina.jpeg