Notifications
Clear all

Internet Radio + HD44780 + scroll text

15 Posts
5 Users
2 Likes
502 Views
(@sinc_int)
Active Member
Joined: 9 months ago
Posts: 4
Topic starter  

Hello

I am using this code ( https://github.com/schreibfaul1/ESP32-audioI2S) to build an internet radio with ESP32.
I added an HD44780 display where I would like to display audio_showstation on line 0 and audio_showstreamtitle on line 1
Everything works fine, but I can't scroll the text on line 1.
here is an example, unfortunately in Polish:

I am looking for help in programming this task.

Regards

SinC


   
Quote
Topic Tags
Will
 Will
(@will)
Famed Member
Joined: 2 years ago
Posts: 2299
 

@sinc_int

I can't guess what the problem is :), can you give us a hint by telling us what, exactly happens (that shouldn't) or what should happen (that doesn't).

Also, post your code so we can see what's happening in there.

Experience is what you get when you don't get what you want.


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4527
 

@sinc_int I don't understand, you say you can't scroll the text on line 1 but in the YT vid I see it scrolling.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
byron
(@byron)
Noble Member
Joined: 4 years ago
Posts: 1051
 

@sinc_int

I think you are showing an example of scrolling test in a Sony player and are asking how to programatically scroll text on your home built internet player screen ??

If so the following may help.  Of course you would need to send the text to your internet radio's screen (linked to your ESP32) instead of printf to a terminal screen but I hope the example helps (if thats indeed what you were asking)

 
#include <stdio.h>

char longText[50] = "tell me another one, just like the other one, do ";
char c;

int main(void) {
    int x, txtLen;
    for (txtLen = 0; txtLen < 49; txtLen++) {
       printf("%s\n", longText);
       // remove first character and move the rest to the left
       c = longText[0]; // copy first character
       // move the other characters to the left
       for (x = 0; x < 49; x++) {
           longText[x] = longText[x + 1];
           }
       // copy what was the character to the end
       longText[48] = c;
     }
}

 


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4527
 

@byron Wow, I assumed there was a 'scroll' function in the library, didn't know you had to manually do it.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4527
 

@sinc_int Here is the sample sketch showing how to do scrolling

 

 

 

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
}

void loop() {
  // set the cursor to (0,0):
  lcd.setCursor(0, 0);
  // print from 0 to 9:
  for (int thisChar = 0; thisChar < 10; thisChar++) {
    lcd.print(thisChar);
    delay(500);
  }

  // set the cursor to (16,1):
  lcd.setCursor(16, 1);
  // set the display to automatically scroll:
  lcd.autoscroll();
  // print from 0 to 9:
  for (int thisChar = 0; thisChar < 10; thisChar++) {
    lcd.print(thisChar);
    delay(500);
  }
  // turn off automatic scrolling
  lcd.noAutoscroll();

  // clear screen for the next loop:
  lcd.clear();
}

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
byron
(@byron)
Noble Member
Joined: 4 years ago
Posts: 1051
 

@zander

Good point and you are probably correct, but I would expect if there is any scrolling text ability for the particular screen being used to be in the driver library for the screen.  

I usually use python these days and the python library for my dinky little 320 x 240 lcd screen does include the ability scroll text. 


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4527
 

@byron I just posted the example before I saw your post. Yes, it does appear to be a library function.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
byron
(@byron)
Noble Member
Joined: 4 years ago
Posts: 1051
 

@zander

you are posting too fast for me to keep up, I guess I will have to drink more coffee, or whatever you are on 😀.   I thought you were an old fogey but you are running circles around me. 😮 


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4527
 

@byron That's because one of my legs is shorter.

His answer BTW is to call the autoscroll member of the LCD object. A quick look doesn't tell me how to limit it to just one line, it seems to be the entire display. mylcdobject.autoscroll();

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
frogandtoad reacted
ReplyQuote
(@sinc_int)
Active Member
Joined: 9 months ago
Posts: 4
Topic starter  

Unfortunately, when I add the scrolling function, the radio is stuttering.

The delay line breaks everything.

 


   
ReplyQuote
Ron
 Ron
(@zander)
Illustrious Member
Joined: 2 years ago
Posts: 4527
 

@sinc_int Please use the reply link.

I assume you are referring to the sample code I posted. If so just remove the delay, I think the example is flawed, the auto scroll should happen anyway.

Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting


   
ReplyQuote
(@sinc_int)
Active Member
Joined: 9 months ago
Posts: 4
Topic starter  
#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"
#include "WiFiManager.h"
#include "time.h"
#include "LiquidCrystal.h"

//Define display pinout
LiquidCrystal lcd(13, 12, 14, 19, 18, 5);

// Define I2S connections
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26

// Create audio object
Audio audio;

TaskHandle_t Task1, Task2;

String ssid = "MYSSID";
String password = "MYPASSWORD";
char * LargeText = " Understanding code for scrolling text on 20*2 LCD Display. ";
int iLineNumber = 1; // Line number to show your string (Either 0 or 1)
int iCursor = 0;

void setup() {
Serial.begin(115200); // Start Serial Monitor
lcd.begin (20, 2); // Start LCD display

// Setup WiFi in Station mode
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid.c_str(), password.c_str());

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

// WiFi Connected, print IP to serial monitor
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("");
lcd.setCursor(0, 0);
lcd.print("IP: ");
lcd.print(WiFi.localIP());
delay(2000);
lcd.clear();
lcd.print("Radio Italo4you");

// Connect MAX98357 I2S Amplifier Module
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(10); // Set thevolume (0-100)
audio.connecttohost("http://s0.radiohost.pl:8018/stream"); //connect to stream

xTaskCreatePinnedToCore( codeForTask1, "stream", 15000, NULL, 2, &Task1, 0);
delay(500); // needed to start-up task1?
xTaskCreatePinnedToCore( codeForTask2, "txt", 15000, NULL, 2, &Task2, 1);
}

void codeForTask1( void * parameter ) {
for (;;) {
audio.loop(); //out radio stream
}
}

void audio_showstreamtitle(const char *info) {
// LargeText = info; // it doesnt work
Serial.print("streamtitle "); Serial.println(info);
}

void UpdateLCDDisplay()
{
int iLenOfLargeText = strlen(LargeText); // Calculate lenght of string.
if (iCursor == (iLenOfLargeText - 1) ){ // Reset variable for rollover effect.
iCursor = 0;
}
//lcd.clear();
lcd.setCursor(0,iLineNumber);
if(iCursor < iLenOfLargeText - 20) // This loop exicuted for normal 20 characters.
{
for (int iChar = iCursor; iChar < iCursor + 20 ; iChar++) {
lcd.print(LargeText[iChar]);
}
}
else
{
for (int iChar = iCursor; iChar < (iLenOfLargeText - 1) ; iChar++){ // This code takes care of printing charecters of current string.
lcd.print(LargeText[iChar]);
}
for (int iChar = 0; iChar <= 20 - (iLenOfLargeText - iCursor); iChar++){ // Reamining charecter will be printed by this loop.
lcd.print(LargeText[iChar]);
}
}
iCursor++;
}

void codeForTask2( void * parameter ) {
for (;;) {
UpdateLCDDisplay(); // Scoll text by 1 character
delay(350); // Change delay to change speed for scrollig text.
}
}
void loop() {
}

This is my code. 

How to display 'info' as 'LagreText'?

 

Regards

SinC


   
ReplyQuote
(@sinc_int)
Active Member
Joined: 9 months ago
Posts: 4
Topic starter  

I found a solution.

      strcat(LargeText, info);

Thread to be closed.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 4 years ago
Posts: 1506
 

@sinc_int

Posted by: @sinc_int

I found a solution.

      strcat(LargeText, info);

Thread to be closed.

That is actually a serious error, and if it worked, it's only by chance... that's what "undefined behavior" means in C and C++.

Why not just use Arduino "String" type or the in ESP32, the ISO C++ std::string from #include<string>?

Much safer and easier to handle.

Cheers


   
Ron reacted
ReplyQuote