Post about your Basic project here

Moderator: Mmiscool

User avatar
By luc VdV
#39883 Same radio-chip, now with extra LCD-display.
Code: Select allserialprintln "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.
Radio and LCD.png

radio.png
You do not have the required permissions to view the files attached to this post.
User avatar
By Mmiscool
#39902 I found that some of the problems with modes crashing is how clean the power supply is. Maybe add an extra cap.

Also try serialprinting the ramfree() to see if there is some thing killing the memory.
User avatar
By forlotto
#40331 Curious did this solution help or have you tried it?
User avatar
By luc VdV
#40477 It was a comination of a lot of problems.
Esp01 has fewer memory so i did not include the [I2C_readregs] sub anymore. Still random fails.
I placed a strong capacitor close tot the module. It improved a lot!!!!! but it still wasn't stable for 24hrs.
It was a big improvement. I would recomend this to all users who have random problems with their modules, even on running/saving programs, the IDE was much reliable.
My 3.3v power was not capable of driving enough power so i used another power source.
Now it is working without troubles, with the esp01 module.