But I think we can still take advantage of these small modules, as long as our application is not very demanding in terms of resources.
This project uses an ESP12F mounted on a 2.54mm pitch breakout board, with a little tinkering to use an AMS1117 instead of the intended IC on the PCB.
But you can use any common ESP8266 module except for ESP01.
The images that I have used are included in the zip. Create a /image folder and upload them there. Or change the paths in the .bas files
The Mareas program is for my city, Santander (Spain). But if you live in a maritime zone, it is almost certain that a similar service exists in your country.
To use the OpenWeatherMap service, you have to register to obtain your own Api Key. But the free service works very well.
https://youtu.be/p-qBsNE56Hw
Code: [Local Link Removed for Guests]
' File Menu.bas
nRow = 3 : nCol = 1
nOpc = (nRow+1) * (nCol+1)
dim opc$(nOpc) = "Info","Clima","Mareas","Aurora","Mario","Dimmer","1","Maximo Libre"
tft.init 5, 4, 0
tft.fill tft.rgb(0,152,152)
tft.text.size 2
foreground = tft.rgb(17,43,69)
flange = tft.rgb(71,71,234)
background = tft.rgb(234,234,71)
tft.text.col foreground, background
' -------------------------------------------------------
' DRAW BUTTONS:
' tft.rect x, y, width, height, color, fill, round_radius
w = 90 : h = 50
for row = 0 to nRow
for col = 0 to nCol
nOpc = row*2 + col
x = col*110 + 25 : y = row*70 + 25
x = col*110 + 20 : y = row*70 + 25
tft.rect x, y, w, h, background, 1, 8
tft.rect x+2, y+2, w-4, h-4, flange, 0, 8
printCenter x, y, opc$(nOpc)
next col
next row
touch.setup 0
ontouch pulsado
wait
END
' ---------------------------
pulsado:
col = 0 : row = 0
xT = touch.x : yT = touch.y
wlog xT
select case xT
case 125 to 215 : col = 1
case 5 to 90 : col = 2
end select
select case yT
case 12 to 50 : row = 1
case 90 to 135 : row = 2
case 165 to 210 : row = 3
case 250 to 290 : row = 4
end select
if (col>0) AND (row>0) then nOpc = row*2 + col-3
r = bas.load "/" + opc$(nOpc) +".bas"
return
' ---------------------------
sub printCenter(x, y, t$)
LOCAL width, xOff
t$ = left$(t$, 6)
width =len(t$)
xOff = 39-(width-1)*6
x = x + xOff
y = y + 16
printDX x, y, t$
end sub
' Tips for Andygadget https://cicciocb.com/forum/viewtopic.php?f=7&t=207
sub printDX(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y
tft.print t$
end sub
Code: [Local Link Removed for Guests]
' File Info.bas
tft.init 5, 4, 0
background = tft.rgb(255, 255, 255)
tft.fill background
tft.bmp "/image/Annex.bmp", 10, 10
tft.text.size 2
tft.text.col tft.rgb(0, 0, 0)
printCentra2 140, "** INFO **"
tft.text.col tft.rgb(0, 0, 180)
printDX 15, 165, bas.ver$
printDX 15, 190, bas.ssid$
printDX 15, 215, word$(ip$, 1)
a$ = wget$("myexternalip.com/raw", 443)
printDX 15, 240, a$
a$ = wget$("https://ipinfo.io/" + a$ + "/geo", 443)
a$ = json$(a$, "org")
if len(a$) > 17 then
wordWrap a$, 17, 15, 265
else
printDX 15, 265, a$
endif
touch.setup 0
ontouch pulsado
wait
END
' ---------------------
pulsado:
r = bas.load "/Menu.bas"
return
' ---------------------
sub wordWrap(t$, width, x, y)
local line$, i
line$ = left$(t$, width)
for i = len(line$) to 1 step -1
if mid$(line$, i, 1) = " " then exit for
next i
wlog i
printDX x, y, left$(t$, i-1)
y = y + 25
printDX x, y, mid$(t$, i+1)
end sub
' --------------------
sub printCentra2(y, t$)
local x
x = (240-(len(t$)*12))/2
printDX x, y, t$
end sub
' ---------------------
sub printCentra3(y, t$)
local x
x = (240-(len(t$)*18.5))/2
printBold x, y, t$
end sub
' ---------------------
' Tips for Andygadget https://cicciocb.com/forum/viewtopic.php?f=7&t=207
sub printAt(x, y, t$)
tft.text.pos x, y
tft.print t$
end sub
' ---------------------
sub printDX(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y
tft.print t$
end sub
' ---------------------
sub printBold(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y+1
tft.print t$
end sub
Code: [Local Link Removed for Guests]
' File Clima.bas
oldTime$ = "" : oldDate$ = ""
weekDay$ = "" : month$ = "" : year$ = ""
city$ = "Santander"
appid$ = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ' KEY openweathermap.org
meteo$ = ""
nameWind$ = ""
nameForce$ = ""
update$ = ""
C$ = " "+chr$(248)+"C"
tft.init 5, 4, 0
touch.setup 0
ontouch pulsado
background = tft.rgb(255, 255, 127)
foreground = tft.rgb(0, 0, 180)
tft.text.col foreground
timer0 1000, bucle
wait
' ------------------------------------------
bucle:
if date$ <> oldDate$ then gosub anotherDay
tft.text.col background
printDX 115, 68, oldTime$
tft.text.col 0
printDX 115, 68, time$
tft.text.col foreground
oldTime$ = time$
return
' ------------------------------------
anotherDay:
oldDate$ = date$
today date$, weekDay$, month$, year$
tft.fill background
tft.text.col foreground
tft.text.size 3
printCentra3 10, weekDay$
tft.text.size 2
printAT 20, 45, left$(date$,2)+" "+month$+" "+year$
printAT 20, 68, "Son las"
gosub meteo
return
' -----------------
meteo:
update$ = time$
meteo$ = wget$("api.openweathermap.org/data/2.5/weather?q=" + city$ + "&appid=" + appid$ + "&units=metric&lang=es", 80)
wlog meteo$
tft.line 15, 93, 225, 93, tft.rgb(255,0,0)
printAT 20, 103, "Temper. " + json$(meteo$,"temp") + C$
printAT 20, 126, "Presi" + chr$(162) + "n " + json$(meteo$,"pressure") + " hPA"
printAT 20, 149, "Humedad " + json$(meteo$,"humidity") + " %"
tft.line 15, 173, 225, 173, tft.rgb(255,0,0)
printAT 20, 185, "Viento " + str$(cint(val(json$(meteo$,"speed")) * 3.6))+ " km/H"
printNameWind 20, 208
printWindSpeed 20, 231
tft.line 15, 255, 225, 255, tft.rgb(255,0,0)
printCentra2 277, ucase$(json$(meteo$,"description"))
return
' ---------------------
pulsado:
r = bas.load "/Menu.bas"
return
' ========================================
sub today(today$, weekDay$, month$, year$)
local diaSemana, diaSemana$
local mes, mes$
diaSemana$ = "S"+chr$(160)+"bado,Domingo,Lunes,Martes,Mi"+chr$(130)+"rcoles,Jueves,Viernes"
mes$ = "Enero,Febrero,Marzo,Abril,Mayo,Junio,Julio,Agosto,Septiembre,Octubre,Noviembre,Diciembre"
diaSemana = ((((dateunix(today$)-dateunix("01/01/00")))/(24*3600)) mod 7) + 1
weekDay$ = word$(diaSemana$, diaSemana, ",")
mes = val(mid$(today$, 4, 2))
month$ = word$(mes$, mes, ",")
year$ = "20" + right$(today$, 2)
end sub
' ========================================
sub printWindSpeed(x, y)
local speed, name$
speed = cint(val(json$(meteo$, "speed")) * 3.6)
select case speed
case 0 to 1 : name$="Calma"
case 2 to 5 : name$="Ventolina"
case 6 to 11 : name$="Flojito"
case 12 to 19 : name$="Flojo"
case 20 to 28 : name$="Bonancible"
case 29 to 38 : name$="Fresquito"
case 39 to 49 : name$="Fresco"
case 50 to 61 : name$="Frescachon"
case 62 to 74 : name$="Temporal"
case 75 to 88 : name$="Temporal fuerte"
case 89 to 102 : name$="Tormenta fuerte"
case 103 to 117 : name$="Tempor. muy duro"
case > 118 : name$="Huracan"
end select
printAT x, y, name$
end sub
' ========================================
sub printNameWind(x, y)
local deg, name$
deg = val(json$(meteo$, "deg"))
select case deg
case 0 to 11.24 : name$ = "NORTE"
case 11.25 to 33.74 : name$ = "Norte-Nordeste"
case 33.75 to 56.24 : name$ = "Nordeste"
case 56.25 to 78.74 : name$ = "Este-Nordeste"
case 78.75 to 101.24 : name$ = "ESTE"
case 101.25 to 123.74 : name$ = "Este-Sudeste"
case 123.75 to 146.24 : name$ = "Sudeste"
case 146.25 to 168.74 : name$ = "Sur-Sudeste"
case 168.75 to 191.24 : name$ = "SUR"
case 191.25 to 213.74 : name$ = "Sur-Sudoeste"
case 213.75 to 236.24 : name$ = "Sudoeste"
case 236.25 to 258.74 : name$ = "Este-Sudoeste"
case 258.75 to 281.24 : name$ = "OESTE"
case 281.25 to 303.74 : name$ = "Oeste-Noroeste"
case 303.75 to 326.24 : name$ = "Noroeste"
case 326.25 to 348.74 : name$ = "Norte-Noroeste"
case 348.75 to 360 : name$ = "NORTE"
end select
printAT x, y, name$
end sub
sub printCentra2(y, t$)
local x
x = (240-(len(t$)*12))/2
printBold x, y, t$
end sub
sub printCentra3(y, t$)
local x
x = (240-(len(t$)*18.5))/2
printBold x, y, t$
end sub
' Tips for Andygadget https://cicciocb.com/forum/viewtopic.php?f=7&t=207
sub printBold(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y+1
tft.print t$
end sub
sub printAt(x, y, t$)
tft.text.pos x, y
tft.print t$
end sub
sub printDY(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x, y+1
tft.print t$
end sub
sub printDX(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y
tft.print t$
end sub
Code: [Local Link Removed for Guests]
' File Mareas.bas
background = tft.rgb(255, 255, 255)
foreground = tft.rgb(0, 0, 180)
tft.init 5, 4, 0
tft.fill background
tft.text.col foreground
tft.text.size 2
tft.bmp "/image/Marina.bmp", 10, 10
fecha$ = date$
printAt 150, 20, "Horario"
printAt 180, 50, "de"
printAt 160, 80, "Mareas"
printAT 175, 110, "d"+chr$(161)+"a"
printAt 130, 140, fecha$
fecha$ = "20" + right$(fecha$, 2) + mid$(fecha$, 4, 2) + left$(fecha$, 2)
id$ = "3" ' Puerto de Santander
query$ = "https://ideihm.covam.es/api-ihm/getmarea?request=gettide&id="
query$ = query$ + id$ + "&format=json&date=" + fecha$
gosub loading
marea$ = wget$(query$, 443)
gosub loaded
gosub answer
touch.setup 0
ontouch tap
WAIT
' ---------------------
tap:
r = bas.load "/Menu.bas"
return
' ---------------------
loading:
tft.text.size 3
printCentra3 220, "Cargando"
return
' ---------------------
loaded:
tft.text.col background
printCentra3 220, "Cargando"
tft.text.col foreground
tft.text.size 2
return
' ---------------------
answer:
printCentra2 170, "Puerto " + json$(marea$, "puerto")
tft.line 15, 195, 225, 195, tft.rgb(255,0,0)
for i = 1 to 4
dato$ = ""
altura = val(json$(marea$, "altura[" + str$(i) + "]")) + 0.05
dato$ = dato$ + json$(marea$, "hora[" + str$(i) + "]") + " "
dato$ = dato$ + ucase$(json$(marea$, "tipo[" + str$(i) + "]")) + " "
dato$ = dato$ + left$(str$(altura), 3)
printAt 16, (24*(i-1))+210, dato$
next i
return
---------------------
sub printCentra2(y, t$)
local x
x = (240-(len(t$)*12))/2
printDX x, y, t$
end sub
' ---------------------
sub printCentra3(y, t$)
local x
x = (240-(len(t$)*18.5))/2
printBold x, y, t$
end sub
' ---------------------
' Tips for Andygadget https://cicciocb.com/forum/viewtopic.php?f=7&t=207
sub printAt(x, y, t$)
tft.text.pos x, y
tft.print t$
end sub
' ---------------------
sub printDX(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y
tft.print t$
end sub
' ---------------------
sub printBold(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y+1
tft.print t$
end sub
Code: [Local Link Removed for Guests]
' File Aurora.bas
city$ = "Santander"
appid$ = "XXXXXXXXXXXXXXXXXXXXXXXXXXX" ' Key openweathermap.org
meteo$ = wget$("api.openweathermap.org/data/2.5/weather?q=" + city$ + "&appid=" + appid$ + "&units=metric&lang=es", 80)
tft.init 5, 4, 0
background = tft.rgb(255, 255, 255)
foreground = tft.rgb(0, 0, 180)
tft.fill background
tft.bmp "/image/logo.bmp"
tft.text.col foreground
tft.text.size 2
printBold 20, 140, ucase$(city$)
printDX 20, 174, "Latitud " + json$(meteo$, "lat")
printDX 20, 198, "Longitud " + json$(meteo$, "lon")
sunrise = val(json$(meteo$, "sunrise")) + 3600 ' Sumar 1*60*60 para 1 hora
sunset = val(json$(meteo$, "sunset")) + 3600
printDX 20, 222, "Amanece " + unixtime$(sunrise)
printDX 20, 246, "Anochece " + unixtime$(sunset)
touch.setup 0
ontouch tap
WAIT
END
' ---------------------
tap:
r = bas.load "/Menu.bas"
return
' Tips for Andygadget https://cicciocb.com/forum/viewtopic.php?f=7&t=207
sub printBold(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y+1
tft.print t$
end sub
sub printAt(x, y, t$)
tft.text.pos x, y
tft.print t$
end sub
sub printDY(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x, y+1
tft.print t$
end sub
sub printDX(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y
tft.print t$
end sub
Code: [Local Link Removed for Guests]
' File Mario.bas
receiver_MAC$ = "C4:5B:BE:55:78:85" ' MAC address of the receiver
ret = espNow.begin
if ret = 0 then wlog "ESP-NOW OK" else wlog "ESP-NOW ERROR"
espnow.add_peer RECEIVER_MAC$ ' set the address of the receiver
onEspNowError status ' jump in case of TX error
tft.init 5, 4, 0
background = tft.rgb(255, 255, 255)
foreground = tft.rgb(0, 0, 180)
tft.fill background
tft.bmp "/image/mario.bmp", 10, 20
tft.bmp "/image/luz_0.bmp", 181, 141
tft.text.col foreground
tft.text.size 2
printCentra2 240, "Press the bulb"
tft.text.col tft.rgb(255 ,0, 0)
printBold 10, 280, chr$(174) + " Menu"
printBold 135, 280, "Dimmer "+ chr$(175)
touch.setup 0
ontouch pulsado
on = 0
wait
END
' ----------------------------------
status:
wlog "TX error on "; espnow.error$
return
' ----------------------------------
pulsado:
xT = touch.x : yT = touch.y
select case yT
case 136 to 190 ' Bulb
if xT>2 AND xT<37 then gosub relay
case 290 to 310
if xT>160 AND xT<230 then
r = bas.load "/Menu.bas"
endif
if xT > -6 AND xT < 100 then
r = bas.load "/Dimmer.bas"
endif
end select
' if xT>2 AND xT<37 then
' if yT>136 AND yT<190 then
' gosub relay
' endif
' endif
'
' if xT > 160 AND xT < 230 then
' if yT >290 AND yT < 310 then
' r = bas.load "/Menu.bas"
' endif
' endif
'
' if xT > -6 AND xT < 100 then
' if yT >290 AND yT < 310 then
' r = bas.load "/Dimmer.bas"
' endif
' endif
return
' ----------------------------------
relay:
on = 1 - on
if on = 1 then
tft.bmp "/image/luz_1.bmp", 181, 141
espnow.write "releON"
else
tft.bmp "/image/luz_0.bmp", 181, 141
espnow.write "releOFF"
endif
return
' ----------------------------------
sub printCentra2(y, t$)
local x
x = (240-(len(t$)*12))/2
printBold x, y, t$
end sub
' Tips for Andygadget https://cicciocb.com/forum/viewtopic.php?f=7&t=207
sub printBold(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y+1
tft.print t$
end sub
sub printDX(x, y, t$)
tft.text.pos x, y
tft.print t$
tft.text.pos x+1, y
tft.print t$
end sub
Code: [Local Link Removed for Guests]
' File Dimmer.bas
receiver_MAC$ = "C4:5B:BE:55:78:85"
ret = espNow.begin
if ret = 0 then wlog "ESP-NOW OK" else wlog "ESP-NOW ERROR"
espnow.add_peer RECEIVER_MAC$
onEspNowError status
tft.init 5, 4, 0
tft.bmp "/image/dimmer.bmp", 1, 1
tft.bmp "/image/hamburger.bmp", 190, 10
for oldLevel = 100 to 0 step -25
gosub btnYellow
next oldLevel
level = 0 : oldLevel = 0
touch.setup 0
ontouch pulsado
wait
END
' ----------------------------------
pulsado:
xT = touch.x : yT = touch.y
if xT>-8 AND xT<30 then
if yT>-3 AND yT<12 then
r = bas.load "/Menu.bas"
endif
endif
if xT > 165 AND xT < 230 then
select case yT
case 8 to 50 : level = 100
case 135 to 170 : level = 75
case 200 to 235 : level = 50
case 260 to 295 : level = 25
case else
level = 0
end select
endif
if level <> oldLevel then gosub swap
return
' ----------------------------------
swap:
gosub btnYellow
gosub btnRed
oldLevel = level
espnow.write "dimmer" + str$(level)
return
btnYellow:
select case oldLevel
case 100 : tft.bmp "/image/TY100.bmp", 15, 25
case 75 : tft.bmp "/image/TY75.bmp", 15, 140
case 50 : tft.bmp "/image/TY50.bmp", 15, 195
case 25 : tft.bmp "/image/TY25.bmp", 15, 250
end select
return
btnRed:
select case level
case 100 : tft.bmp "/image/TR100.bmp", 15, 25
case 75 : tft.bmp "/image/TR75.bmp", 15, 140
case 50 : tft.bmp "/image/TR50.bmp", 15, 195
case 25 : tft.bmp "/image/TR25.bmp", 15, 250
end select
return
' ----------------------------------
status:
wlog "TX error on "; espnow.error$
return
Code: [Local Link Removed for Guests]
' File in the relay module
' Rele shield D1 Mini
relay = 5 ' Relay on pin 5 (D1)
led = 2 ' Led on pin 2 (D4)
pin.mode relay, output
pin.mode led, output
pin(led) = 1 ' Off (unlike: 0=on, 1=off)
ret = espnow.begin
if ret = 0 then wlog "Esp-Now escuchando..." else wlog "Error Esp-Now..."
onEspNowMsg message
wait
message:
subject$ = espNow.read$
wlog subject$
select case subject$
case "releON"
pin(relay) = 1
pin(led) = 0
case "releOFF"
pin(relay) = 0
pin(led) = 1
end select
return
Code: [Local Link Removed for Guests]
' File dimmer_ESPNOW.bas
' Loaded in the ESP8266 connected to the AC light dimmer module with Zero Cross detector
dimmer.setup 4, 5
dimmer.limits 4000, 9300 ' adjusted for my module testing DIMMER.DELAY uSec
dimmer.brightness 0
ret = espnow.begin
if ret = 0 then wlog "Esp-Now escuchando..." else wlog "Error Esp-Now..."
onEspNowMsg message
wait
message:
subject$ = espNow.read$
wlog subject$
if left$(subject$, 6) = "dimmer" then
brightness = val(mid$(subject$, 7))
dimmer.brightness brightness
endif
return