String type is not working!

Hi,
I am using hifive1 mcu which is an arduino compatible board. I have done many projects in this using arduino ide. I have created a new projects where it contains a "String variable", when i try to print the variable in the serial monitor It is not printing ! i dont know why, previously it was working well.Suddenly i am facing this weird issue.

The same sample code when i run in arduino uno it is working well, when it comes to my Hifive1 it doesn't print the String variable alone all the other println are printing.

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("\n\nString charAt() and setCharAt():");
}

void loop() {
  // make a String to report a sensor reading:
  String reportString = "SensorReading: 456";
  Serial.println(reportString);

  // the reading's most significant digit is at position 15 in the reportString:
  char mostSignificantDigit = reportString.charAt(15);

  String message = "Most significant digit of the sensor reading is: ";
  Serial.println(message + mostSignificantDigit);

  // add blank space:
  Serial.println();

  // you can also set the character of a String. Change the : to a = character
  reportString.setCharAt(13, '=');
  Serial.println(reportString);

  // do nothing while true:
  while (true);
}

O/P

String charAt() and setCharAt():

Kindly help me out.
Thank you.

DanielKirubakaran:
O/P

String charAt() and setCharAt():

It is doing exactly what you are telling it to do - look carefully at your code.

As you have only posted a snippet I have no idea what you are hoping it would do. Post a complete program that illustrates the problem.

Separately, and not directly related to your problem, it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

...R

Actually i have given the complete code. Scroll down in the code box to see the loop().
The issue is it is not printing the Serial.println()'s which is in the loop().

That board seems to have plenty of RAM, so I don't think that use of Strings (bad idea though it is) can be the issue.

That it works on an Arduino (it certainly does on my Uno) suggests that the problem lies with the hifive1 or more likely, the toolchain you're using to program it.

DanielKirubakaran:
Actually i have given the complete code.

When I did not see any global variables defined before setup() I had assumed (incorrectly) that it was only a snippet - apologies.

Your program seems to work fine on my Uno.

...R

I suspect there is a problem in the run-time code provided for the Freedom E310 processor of your HiFive1 board. I'd try putting the code into setup() and leaving loop() empty in case there is a problem caused by the while(1);

Still not working when leaving the loop() empty.
It only prints the "String charAt() and setCharAt():"

Also tried to print,

char *hello="hello";
Serial.println(hello);

it prints the char*. But why not String type?
is reinstalling arduino ide a good choice?

These are the tests that i have done in the morning in different systems.

I)Windows10(currently i am using)
Arduino version 1.8.9

output:

String charAt() and setCharAt():

II)Linux(ubuntu 18.04)
Arduino Version 1.8.8

output:
String charAt() and setCharAt():
SensorReading: 456
Most significant digit of the sensor reading is: 4
SensorReading= 456

III)Windows7 (colleague’s system)
Arduino Version 1.8.8

output:

String charAt() and setCharAt():

I guess, if i reinstall the ide in my system again , the same issue will occur.,

I was using Linux Mint when I tried your program on my Uno (Reply #4)

...R

Robin2:
I was using Linux Mint when I tried your program on my Uno (Reply #4)

...R

It is working for me also in my UNO board
But not working in Hifive1 board , especially those string data types

DanielKirubakaran:
It is working for me also in my UNO board
But not working in Hifive1 board , especially those string data types

Did you have to load a special "core" to use the Hifive1 board, and if so, who wrote it? Maybe that is where you should be seeking an answer?

...R

Yes , that is "Sifive".
I have put this query in their forum as well. Assumed that the people who worked with the board which i am using may also there in this forum as the board is an Arduino compatible one.

DanielKirubakaran:
Yes , that is "Sifive".

I'm confused. You have called it "hifive1" in your earlier Posts.

A link to the website would be a useful.

...R

It is Sifive's hifive1.As you asked about the authors i told about Sifive's team.
please check it out here.

Thanks for your patience.

Thanks.

My guess is that they have not properly implemented the interface with the Arduino IDE.

Have you tried modifying your code so it does not use the String class, instead uses cstrings - char arrays terminated with 0.

...R

No i didn't modify the code. Even i guess the same.
Don't know what happened in between! because i have done many projects and used these Strings before.
i am trying to find out the issue.If you are able to sort out the issue kindly let me know.So that i will mention the topic as [Resolved]

Thanks for your valuable time.

DanielKirubakaran:
.If you are able to sort out the issue kindly let me know.So that i will mention the topic as [Resolved]

As your code works on the Arduino I have I cannot help further.

...R