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

Place your projects here
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 »

Chella Vee. I'm sorry I took so long to reply.
I saw her message, I made a little program and I forgot to upload it!
Until Andy made me visit this page again today.
I understand that what he wants is a reduced version of the radio2.bas program.
I have started from the secondary file dial.bas to try to adapt it.
There it goes:

Code: [Local Link Removed for Guests]

' Lilygo TTGO T-Display ESP32 with PCM5102 I2S DAC
' and KY-040 rotary encoder to change stations.
' Tested with Annex32 CAN 1.48.22 (problems volume>50)

' Read text file with stations and fill
' arrays with name and streaming url address
file$ = "/stationR.txt"
index = word.count(file.read$(file$), "=") - 2
dim name$(index)
dim url$(index)
gosub loadArrays

' Retrieve the last tuned station or create
' a new file with the first one on the list
if file.exists("/last.dat") then
  station = val(file.read$("/last.dat"))
else
  station = 0
  file.save "/last.dat", str$(station)
endif

' configure TFT screen
background = tft.color(yellow) 
foreground = tft.color(black)
gosub TFT_init

' configure I2S DAC
gosub PLAY_init

' configure rotary encoder
turn = 0
CL = 13 ' clk pin to ESP32 GPIO13
DT = 12 ' dt  pin to ESP32 GPIO12 
pin.mode CL, input, pullup  ' enable internal pull-up resistors 
pin.mode DT, input, pullup
interrupt CL, readCL

gosub menu
goto bucle
wait

bucle:
while 1
  if turn = 1 then
    pause 15  ' debounce

    if pin(CL) = 1 then
      do
      loop until pin(DT) = 0
      num = pin(CL) << 2
      num = num OR pin(DT)
      if num = 0 then station = station + 1     ' clockwise
      if station > index then station = index   ' upper limit
      if num = 4 then station = station - 1     ' counterclockwise
      if station < 0 then station = 0           ' lower limit

      play.stream url$(station), 40000
      pause 50
'      wlog station, name$(station)
      gosub menu
      file.save "/last.dat", str$(station)
    endif

    turn = 0
  endif  
wend
return

END

' --------------------------------------
menu:
  select case station
    case 0
      emisora = 0
      row = 0
    case index-3 to index
      emisora = index-3
      row = 3 - (index mod station)
    case else
      emisora = station-1
      row = 1
  end select
  
  tft.fill background  
  for y = 62 to 152 step 30
    tft.text.draw name$(emisora), 50, y
    emisora = emisora + 1
  next y
          
  tft.text.color white, blue  
  tft.text.draw name$(station), 50, (row*30) + 62
  tft.text.color foreground, background 

return

' ---------------------------
readCL:
  if pin(CL) = 0 then return
  if turn    = 1 then return
  turn = 1 ' If you've made it this far, you've earned it.
return

' --------------------------------------
loadArrays:
  for i = 0 to index
    line$    = file.read$(file$, i+1)
    name$(i) = word$(line$, 1, "=")
    url$(i)  = replace$(word$(line$, 2, "="), chr$(13), "")  ' remove cr from end of line
  next i
return

' --------------------------------------
TFT_init:
  tft.init 2           ' orientation Portrait Reversed
  tft.brightness 128   ' brightness = 0 to 255
  tft.text.color foreground, background
  tft.text.align 0
  tft.fill background
  tft.text.font 4
return

' --------------------------------------
PLAY_init:
  play.setup 1, 64  ' output to external DAC, buffer=64, stereo
  play.volume 50
  play.stream url$(station), 40000
return

' --------------------------------------
'info1:
'  tft.text.font 3
'  tft.text.draw bas.ver$, 55, 65
'  tft.text.draw "Version " + str$(bas.ver), 55, 95  
'  tft.text.draw bas.ssid$, 55, 125
'  tft.text.draw "IP  " + word$(ip$, 1), 55, 155
'  pause 5000
'return


' ********** HARDWARE **********
' PCM5102    ESP32
' -------   -------
'  BCK      GPIO27
'  DIN      GPIO02
'  LCK      GPIO26
'  GND      GND
'  VIN      +5V
'  SCK      GND (to avoid oscillations)

' rotary encoder KY-040
' It does not use either the resistors on the board or the connection to Vcc.
' ESSENTIAL two 100nF capacitors between CLK/DT and GND
' KY-040   ESP32
' ------   ------
'  CLK    GPIO13
'  DT     GPIO12
'  SW     N/C
'  +      N/C
'  GND    GND
stationR.txt
for the rotary encoder, I have based on the code of:
[Local Link Removed for Guests]
You do not have the required permissions to view the files attached to this post.
User avatar
Chella Vee
Posts: 6
Joined: Sun Nov 27, 2022 12:35 am
Has thanked: 2 times

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

Post by Chella Vee »

Dear Fernando

Thank you so for much for the code and your time much appreciated.

I'll try let you know if I've noticed any issues.

Kind Regards
Chella
User avatar
Chella Vee
Posts: 6
Joined: Sun Nov 27, 2022 12:35 am
Has thanked: 2 times

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

Post by Chella Vee »

Dear Fernando,

Do you know where I get the Annex 1.47.2?

I used 1.48.22 and I get this below error.
Partition table file 'partition table.bin' does not exist exit code:22

Please, can you advice?
image.png
Thank you.
You do not have the required permissions to view the files attached to this post.
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 »

Hi Chella Vee.
If your current problem is that you can't load the Annex interpreter in your TTFO T-Display module, it's more efficient to ask a question in a dedicated thread, eg [Local Link Removed for Guests] . Someone more specialized in these problems than me, can advise you.
However, version 1.47.2 can be obtained, in this forum. The binaries are found, (although a little hidden), I seem to remember that in [Local Link Removed for Guests] or in a web page that I am writing about Annex: https://www.myrapidq.it/magazine/ , clicking on the “Resources” icon at the top right of the window.
In any case, I can advise you:
For this Internet Radio program, do not record the “Full” version. Load “No BLE”, which disables Bluetooth but frees up a lot of memory.
Under “Data Size”, choose “Empty”.
Click on “Erase the flash Memory” before recording Annex.
If all else fails, run the Arduino IDE, select “ESP32 Dev Module” and upload any small sketch to reformat the ESP32. Then try again to record Annex.
User avatar
Chella Vee
Posts: 6
Joined: Sun Nov 27, 2022 12:35 am
Has thanked: 2 times

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

Post by Chella Vee »

Dear Fernando

Thank you for the info and I did the Blink on Arduino IDE and working okay.
I will try flashing again with 1.47.2 on annex and keep you updated.

Kind Regards
User avatar
Chella Vee
Posts: 6
Joined: Sun Nov 27, 2022 12:35 am
Has thanked: 2 times

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

Post by Chella Vee »

Dear Fernando,

Please, see below I'm successfully able to load 1.47.2 finally thank you!

However, if reconnect the prog not loading and showing blank screen please see below

In this case I have to manually load the code again and run. I can see all the files are saved.

Any thought please? not sure what I'm doing wrong.

Thank you.
:D
You do not have the required permissions to view the files attached to this post.
User avatar
PeterN
Posts: 366
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 171 times
Been thanked: 203 times
Contact:

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

Post by PeterN »

A program is defined to run automatically by setting the “Autorun File” in the config page
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 »

I think you are doing everything right. !! Congratulations!!
But in this program, as in all of them, if you want it to load and run automatically when you turn on your module, just fill in the "Autorun File" box in the "Config" window.
Don't forget the slash / at the beginning.
In my case, I have called the program "radioDial.bas" and I have written this:
image.png
You do not have the required permissions to view the files attached to this post.
User avatar
Chella Vee
Posts: 6
Joined: Sun Nov 27, 2022 12:35 am
Has thanked: 2 times

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

Post by Chella Vee »

As always grate thanks much Fernando!

Best Wishes
Old Dave
Posts: 18
Joined: Thu Jan 26, 2023 12:16 am
Has thanked: 4 times
Been thanked: 5 times

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

Post by Old Dave »

Hi all...

Very very late to the party, but wanted to post my thanks to Fernando Perez for this great project.

Couldn't find a 'great case' for the project so used the best I could find on thingiverse, not perfect but it will do until I can find better.

Used a touch pcb for changing channels, so just a finger on the ANAIRE and it does what its supposed to do.
IMG_20230202_152037259[1].jpg
IMG_20230202_152243555[1].jpg
IMG_20230202_152605074[1].jpg


And also thanks to cicciocb for the ability to easily flash the ESP32 (TTGO-T)
You do not have the required permissions to view the files attached to this post.
Post Reply