Comments (8)
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.
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.
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.
from arduino_freertos_library.
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.
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.
Should I just keep an eye on the master branch for this fix?
from arduino_freertos_library.
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)
- STM32FreeRTOS myservo can not work. HOT 2
- what is the difference of three freertos? HOT 5
- FreeRTOS automatically restarts after the last task has finished on Arduino Mega 2560 HOT 7
- vTaskDelay not functioning as expected in setup HOT 3
- Is it possible to implement a system timer interrupt version (rather than WDT) compatible with Arduino IDE? HOT 2
- Generic device support HOT 3
- RTOS Example Compile Error HOT 4
- Where is the define of TaskControlBlock_t in task.h? HOT 1
- define delay() to vTaskDelay() HOT 3
- Arduino delay() changed its behavior to not do busy wait anymore HOT 19
- INCLUDE_vTaskDelayUntil and INCLUDE_xTaskDelayUntil && avr/io.h: No such file or directory HOT 3
- Arduino Due support HOT 4
- lgt8f328p compatibility HOT 22
- Arduino R4 HOT 5
- [Q] Unable to change FreeRTOSConfig.h for a single sketch on Arduino IDE 2.2.1 HOT 1
- Casting error on vPortDelay function
- Array Queue HOT 1
- Teensy support HOT 4
- FAQ (for anyone who wishes to ask..) HOT 5
- Support for AWS FreeRTOS ESP32 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino_freertos_library.