serialprintln "created with ESP Basic V1.77"
freq = 94.2
volume = 8
[BuildPage]
gosub [Update_lcd]
gosub [I2C_writeregs]
cls
wprint "volume:"
slider volume 0 15
wprint "<br>Freq="
textbox freq
wprint "MHz<br>"
button "Apply changes" [BuildPage]
wprint "<br>"
button "Exit" [Exit]
button "Preset1" [preset1]
wait
[preset1]
freq = 97.5
goto [BuildPage]
[I2C_writeregs]
gosub [buildregisters]
i2c.begin(16)
i2c.write(reg2h)
i2c.write(reg2l)
i2c.write(reg3h)
i2c.write(reg3l)
i2c.write(reg4h)
i2c.write(reg4l)
i2c.write(reg5h)
i2c.write(reg5l)
i2c.end()
return
[buildregisters]
reg2h = 242
reg2l = 141
if volume = 0 then reg2h = reg2h - 64
chan = freq * 1000
chan = chan - 87000
chan = chan / 100
chan = chan * 64
reg3h = chan / 256
reg3h = int(reg3h)
x = reg3h * 256
reg3l = chan - x
reg3l = int(reg3l)
reg3l = reg3l + 16
reg4h = 4
reg4l = 0
reg5h = 128
reg5l = 128 + volume
return
[I2C_readregs]
i2c.requestfrom(16,4)
regah = i2c.read()
regal = i2c.read()
regbh = i2c.read()
regbl = i2c.read()
i2c.end()
return
[Update_lcd]
lcdcls
lcdprint "Freq:" 0 0
lcdprint freq 5 0
lcdprint "MHz" 9 0
lcdprint " Vol:" 0 1
lcdprint volume 5 1
return
[Exit]
volume = 0
gosub [I2C_writeregs]
lcdcls
lcdprint "Radio: off"
cls
end
A few details:
-This example works with a radio-module with I2C RDA5807-chip, not with the TEA5767.
-You need 2 different power-lines. +3V3 for radio and ESP-module and +5V connected to LCD-module. Make shure you do not connect your ESP-module to +5V.
-I have used a ESP8288-DEV module, but tested it also with ESP-12.
-It works with ESP-01 module with 512K flash but it is not stabile. The module crashes after random-times.
-No extra pullup resistors are needed on SCL and SDA because the display-module has those resistors on its PCB.
-Subroutine [I2C_readregs] is included in the code but not used in this example.