Giter Club home page Giter Club logo

Comments (8)

feilipu avatar feilipu commented on August 12, 2024 1

I'll take a look at String() shortly, to see if there is anything that can be fixed in that library.

from arduino_freertos_library.

feilipu avatar feilipu commented on August 12, 2024 1

I've spent some time identifying the limitations here, and have the following input.
String functions seem to be very finicky. But the following code segment delivers what you need.

#include <Arduino_FreeRTOS.h>

void TaskAnalogRead( void *pvParameters );

String sensorValue; // Make the sensorValue a Global Variable, otherwise it will be reallocated each time the Task for() loop is run.

// the setup function runs once when you press reset or power the board
void setup() {

  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

  sensorValue.reserve(255); // Reserve a fixed space for your String, larger than the maximum length required, to avoid reallocation.

  // Now set up a Task to run independently.
  xTaskCreate(
    TaskAnalogRead
    ,  (const portCHAR *) "AnalogRead"
    ,  128  // Stack size
    ,  NULL
    ,  1  // Priority
    ,  NULL );

  // Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started.
}

void loop()
{
  // Empty. Things are done in Tasks.
}

/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/

void TaskAnalogRead( void *pvParameters __attribute__((unused)) )  // This is a Task.
{
  for (;;)
  {
    // read the input on analog pin 0:

    int analogValue = analogRead(A0); // Embedding functions in String() doesn't work well, so separate the function call out.
    sensorValue = "is: " + String( analogValue ); // Concatenation is needed, or the int to String conversion seems to fail.

    // sensorValue = String( analogValue );
    // sensorValue = String(analogRead(A0));
    // String sensorValue = String(analogRead(A0), DEC);

    Serial.print("Address: ");
    Serial.print(int(&sensorValue), HEX);
    Serial.print("  Length: ");
    Serial.println(sensorValue.length());

    // print out the value you read:
    Serial.print("Sensor Value ");
    Serial.println(sensorValue);

    vTaskDelay(10);  // ten tick delay (150ms) in between reads to reduce spam.
  }

}

from arduino_freertos_library.

feilipu avatar feilipu commented on August 12, 2024

rkertesz,

Just retested a few different sketches (including both example sketches) with a clean install of Arduino 1.6.9 and the 8.2.3-14 Arduino_FreeRTOS library version, on Windows 10,

It works as expected. I can't replicate your issue.
Perhaps provide some more background information.

from arduino_freertos_library.

rkertesz avatar rkertesz commented on August 12, 2024

from arduino_freertos_library.

feilipu avatar feilipu commented on August 12, 2024

I've tested the one line change, and confirmed that there is an issue with the String library.

    int sensorValue = analogRead(A0); //  Original, works correctly
    // String sensorValue = String(analogRead(A0)); //  Proposed, prints blanks
    // String sensorValue = "hello"; //  Tested, also prints blanks

As hello doesn't print either, the problem doesn't originate from the analogRead library.

      Serial.print("Sensor Value: "); \\  Correctly prints the text "Sensor Value: "
      Serial.println(sensorValue);  \\  just a blank, but newline & CR are printed.

So Arduino_FreeRTOS is not breaking the String function. There's something else happening.
I don't have time to dig into String() now to find out why it is broken. But I'll have a look soon.

from arduino_freertos_library.

rkertesz avatar rkertesz commented on August 12, 2024

Ah. Thank you. Yes. I agree that it is a pervasive String issue. Thank you for double checking this. I just wanted to note that it looks like it isn't just a printing issue but the string variable doesn't get populated with any text. A *char array does work as expected.

from arduino_freertos_library.

rkertesz avatar rkertesz commented on August 12, 2024

Should I just keep an eye on the master branch for this fix?

from arduino_freertos_library.

feilipu avatar feilipu commented on August 12, 2024

Yes. Best place to look, together with a 9.0.1 version, once it is released.

But note that there is little chance that I'll be able to influence the Arduino developers to change the String library, unless a general issue can be proven.

Otherwise, just use char* as the workaround.

from arduino_freertos_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.