Internet Radio: TTGO T-Display ESP32 with PCM5102 and Annex 1.47.2

Place your projects here
User avatar
cicciocb
Site Admin
Posts: 1997
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 428 times
Been thanked: 1336 times
Contact:

Re: Internet Radio: TTGO T-Display ESP32 with PCM5102 and Annex 1.47.2

Post by cicciocb »

You are trying to use https:// streams

These require more RAM and your module is not provided with external PSRAM.

Try to flash a firmware without BLE to gain more free RAM
User avatar
Pepper
Posts: 6
Joined: Thu Jun 29, 2023 10:31 am
Has thanked: 3 times

Re: Internet Radio: TTGO T-Display ESP32 with PCM5102 and Annex 1.47.2

Post by Pepper »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Fri Jun 30, 2023 2:30 pm
Thanks, I did use use the BLE Option and emty files.
I now installed the Toolkit 1.1 and new Annex but this does not have the custom config option so i think i have to specify pins used for screen and so on.
Hopefully it will have a couple of bits free ram.

Not sure if this will work.
TTGO-T Esp32 BLE
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: Internet Radio: TTGO T-Display ESP32 with PCM5102 and Annex 1.47.2

Post by Fernando Perez »

Hello Pepper.
As has already been discussed in the forum, the problem with Internet stations is that they disappear or change their URL very frequently.
In your case, I would try to remove the security "s" from the https address in your stations. Try this file:

Code: [Local Link Removed for Guests]

1  The Great American=http://listen.shoutcast.com/thegreatamericansongbook
2  Jacaranda=http://live.jacarandafm.com/jacarandahigh.mp3
3  Classica RAI=http://icestreaming.rai.it/5.mp3
4  The 40's sounds=http://81.17.57.158:24929/stream
5  Bosveld=http://iceant.antfarm.co.za/Bosveld
6  Vibe Radio Jazz=http://94.130.242.5:8020/stream
7  Latina=http://start-latina.ice.infomaniak.ch/start-latina-high.mp3
8  Classical 90.5=http://streaming.azpm.org:80/kuat192.mp3
9  Radio Swiss Classic=http://stream.srg-ssr.ch/m/rsc_de/mp3_128
Don't forget to delete the last.dat file or press [Enter] at the end of the last line of the new file.

As for the third station you mention, I don't know what to advise you, since it seems to be a different streaming coding system, which I'm not familiar with.
You do not have the required permissions to view the files attached to this post.
User avatar
Pepper
Posts: 6
Joined: Thu Jun 29, 2023 10:31 am
Has thanked: 3 times

Re: Internet Radio: TTGO T-Display ESP32 with PCM5102 and Annex 1.47.2

Post by Pepper »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Fri Jun 30, 2023 6:02 pm
Done the stations .txt file thanks - working now...but
What is weird i had to flash the module again, uploaded modified file and all stations are working perfectly even after restarts.

However in my browser(firefox) using editor and editing ONLY a single station name in stations.txt - uploaded it and after restarting some stations does not work anymore including the station name i edited - Stream not open.
Restarting or cycling the power the does not correct it.

Using Annex 1.47.2
Any ideas?
TTGO-T Esp32 BLE
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: Internet Radio: TTGO T-Display ESP32 with PCM5102 and Annex 1.47.2

Post by Fernando Perez »

This may be because the Annex editor treats line endings differently from Notepad.
Also, I've noticed a major flaw in my program: When a station doesn't exist, it stops working without any warning as to why.
For this reason, I have prepared a minimal version, without any flourishes, that you can use to check if everything works perfectly for you before making the final version with the additions you want: VU meter, station information, recording/recovery of the last station heard , etc.
Instead of storing station data in arrays or files, I've used the ancient Basic language method DATA/READ/RESTORE, which gives me an excuse to use ONERROR and study how it works.
In the list of stations, you will see that the third one, Lima Radio, returns an error and how to correct it.
I also advise you to load your module with the version of Annex 1.49.2, which is the one I have used on this occasion; It seems quite stable and with obvious improvements.

Code: [Local Link Removed for Guests]

' Lilygo TTGO T-Display ESP32 with PCM5102 I2S DAC
' Annex32 BLE 1.49.2 

numError =  0
onError goto Dread

myIP$ = "IP: " + word$(ip$, 1)

pin.mode 21, input, pullup
interrupt 21, change_Station

gosub tft_Init
gosub i2s_Init
gosub play_Station

wait
END

' --------------------------------------
tft_Init:
  tft.init 2 ' Orientation Portrait Reversed
  tft.brightness 128 ' 0 to 255
  tft.text.color tft.color(black), tft.color(white) ' foreground, background
  tft.text.align 0
  tft.text.font 4
  tft.fill tft.color(white)
  tft.text.draw "INTERNET RADIO", 60, 80
  tft.text.draw myIP$, 60, 130
  pause 2000  
return

' --------------------------------------
i2s_Init:
  play.setup 1, 64
  play.volume 75
return

' --------------------------------------
change_Station:
  if pin(21) = 0 then return
  pause 20 ' adjust for the best button debounce
  wlog "Pressed"
  if pin(21) = 1 then gosub play_Station
return

' --------------------------------------
name_Station:
  tft.fill tft.color(white)
  tft.text.draw name$, 50, 62
return

' --------------------------------------
play_Station:

  READ name$, url$
  if numError = 33 then ' End of DATA 
    numError = 0
    RESTORE  ' go back to the beginning
    READ name$, url$
  endif
   
  play.stream url$
  if play.isplaying = 0 then
    gosub missing_Station
  else
    gosub name_Station
  endif
    
return

' --------------------------------------
missing_Station:
  gosub name_Station
  tft.text.draw "Station is missing", 51, 102
  tft.text.draw "Press button again", 50, 142
return

' --------------------------------------
Dread:
  numError = BAS.ErrNum
return

' ===============================================
DATA "The Great American", "http://listen.shoutcast.com/thegreatamericansongbook"
DATA "Jacaranda", "http://live.jacarandafm.com/jacarandahigh.mp3"
DATA "Lima", "http://17563.live.streamtheworld.com:80/CRP_OAS_SC?dist=20004&csegid=20004"
DATA "Classica RAI", "http://icestreaming.rai.it/5.mp3"
DATA "The 40's sounds", "http://81.17.57.158:24929/stream"
DATA "Rio de Janeiro", "http://26673.live.streamtheworld.com:80/NOVABRASIL_RIO_SC"
DATA "Bosveld", "http://iceant.antfarm.co.za/Bosveld"
DATA "Vibe Radio Jazz", "http://94.130.242.5:8020/stream"
DATA "Latina", "http://start-latina.ice.infomaniak.ch/start-latina-high.mp3"
DATA "Classical 90.5", "http://streaming.azpm.org:80/kuat192.mp3"
DATA "Radio Swiss Classic", "http://stream.srg-ssr.ch/m/rsc_de/mp3_128"
DATA "Rotterdam", "http://25333.live.streamtheworld.com:3690/VERONICA_SC"

User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: Internet Radio: TTGO T-Display ESP32 with PCM5102 and Annex 1.47.2

Post by Fernando Perez »

Someone thanked me (thanks to you, Bugs) and when I entered this thread, I remembered that I have written a new version of this program; applying the wisdom that comes with years :roll: and a thorough study of GUI elements. I have done several checks and tests and it seems robust and stable. It's actually the version I personally use.

Code: [Local Link Removed for Guests]

' Lilygo TTGO T-Display (135x240) ESP32 with PCM5102 I2S DAC
' Very important: Currently it only works well on Annex32 CAN 1.49.2

' Intercept errors 
numError =  0
onError goto scared

' Retrieve the last tuned station or create a new file with the first one on the list
station = 1 : name$ = ""
if file.exists("/last.dat") then station = val(file.read$("/last.dat")) else file.save "/last.dat", str$(station)
for i =1 to station
  READ name$, url$
next i  

' Initialize display
tft.init 2         ' Orientation Portrait Reversed
tft.brightness 128 ' Brightness 0 to 255
background = tft.color(yellow)

' Create GUI objects
gui.init 4, background ' Background yellow
title$ = "Waiting data..." : vL = 0 : vR = 0
head = gui.textLine(45, 55, 230, 30, name$,  4, navy, background, background, 7)
body = gui.textLine(50, 90, 230, 30, title$, 3, black, background, background, 3)
vumL = gui.progressBar(45, 130, 230, 25, vL, 0, blue, white, black)
vumR = gui.progressBar(45, 157, 230, 25, vR, 0, red, white, black)

' Initialize I2S audio
volume = 75 : maxLevel = 0
play.setup 1, 64
play.volume volume
gosub playStation
onplay infoStation ' If streaming metadata is received

' Manage station change button
firstTime = 1
pin.mode 21, input, pullup
interrupt 21, changeStation

' Main loop
while 1
  for i = 1 to 18 ' scrolls first 18 characters of title
    gui.setText body, mid$(title$, 1, i)
    gosub vumeter
  next i  

  for i = 2 to len(title$) - 12 ' scrolls remaining title characters
    gui.setText body, mid$(title$, i, 18)
    gosub vumeter
  next i
wend

END

'-----------
playStation:
'-----------
  play.stream url$
  if play.isplaying = 0 then
    gui.setText head, "MISSING STATION"
    title$ = "Station " + str$(station) + " not answer"
  else  
    gui.setText head, name$
  endif  
  gui.refresh
return

'-------
vumeter:
'-------
  if play.vu_L > maxLevel then maxLevel = play.vu_L
  if play.vu_R > maxLevel then maxLevel = play.vu_R  
  gui.setValue vumL, convert.map(play.vu_L, 0, maxLevel, 0, 100)
  gui.setValue vumR, convert.map(play.vu_R, 0, maxLevel, 0, 100)
  gui.refresh
  pause 150
return

'------------
 infoStation:
'------------
' Only activates when station changes song
  info$ = play.message$
  title$ = mid$(info$, instr(info$, "StreamTitle=") + 12)
  if len(title$) = 1 then title$ = "No title information"
  ' Very special cases:
  if name$ = "The 40's sounds" then replace$(title$, "Big Band Swing Jazz Jive 40s 50s", "")
  ' Other cases here..

  blanks = 18 - (len(title$) MOD 18)
  title$ = title$ + space$(blanks) 
return

'--------------
 changeStation:
'--------------
  if pin(21) = 0 then return
  if firstTime then
    firstTime = 0
    return
  endif 

  pause 20  ' adjust for the best button debounce

  if pin(21) = 1 then
    READ name$, url$
    station = station + 1 

    if numError = 33 then ' End of DATA 
      numError = 0 : station = 1
      RESTORE
      READ name$, url$
    endif  

    file.save "/last.dat", str$(station)
    maxLevel = 0
    gosub playStation
  endif
return

'-------
 scared:
'------- 
  numError = BAS.ErrNum
return

' ===============================================================================
DATA "The Great American", "http://listen.shoutcast.com/thegreatamericansongbook"
DATA "Classica RAI", "http://icestreaming.rai.it/5.mp3"
DATA "Classical 90.5", "http://streaming.azpm.org:80/kuat192.mp3"
DATA "Radio Swiss Classic", "http://stream.srg-ssr.ch/m/rsc_de/mp3_128"
DATA "The 40's sounds", "http://81.17.57.158:24929/stream"
DATA "Vibe Radio Jazz", "http://94.130.242.5:8020/stream"
DATA "Rio de Janeiro", "http://26673.live.streamtheworld.com:80/NOVABRASIL_RIO_SC" ' broken link for test
DATA "Bosveld", "http://iceant.antfarm.co.za/Bosveld"
DATA "Jacaranda", "http://live.jacarandafm.com/jacarandahigh.mp3"
DATA "Latina", "http://start-latina.ice.infomaniak.ch/start-latina-high.mp3"
DATA "Rotterdam", "http://25333.live.streamtheworld.com:3690/VERONICA_SC"
DATA "Madrid", "http://server7.emitironline.com:8000/stream"

And I think I am done, since when I have tried to update my TTGO to Annex versions higher than 1.49.2, everything is problems: Instability, noises and when I try to use it as "Autorun File", it is waiting for data, without sound and without starting the vumeters.
But I don't care, because the way it is now, I'm satisfied.

Remember that when the screen reports that a station has stopped broadcasting and you go to delete the corresponding DATA, also delete the last.dat file. Maintaining it usually doesn't cause problems, but it's better to be safe.
Post Reply