Questions tagged [string]

A sequence of characters -- including letters, numbers and symbols -- often used for representing information in a human-readable format.

Use this tag for any questions which relate directly to using text strings in Arduino programming, whether for input, output, storage, or transmission.

This tag can cover any representation of a string which Arduino will support, including char arrays (null-terminated or otherwise), the Arduino String class, and the C++ std::string class.

323 questions
8
votes
3 answers

Why is 'n' parameter of snprintf ignored?

I have found that the n parameter of snprintf() seems to be ignored in my code. char asdf[10]; Serial1.println(snprintf(asdf, 2, "hello")); This prints 5 when I would expect it to print 2. What is happening?
Westin
  • 83
  • 4
6
votes
3 answers

How to multiply strings?

I want to have a line like this Serial.println(count*"B"); So if count=6, it would print BBBBBB, etc. Is there anything like this for arduino?
Mirror318
  • 163
  • 1
  • 5
3
votes
1 answer

if statement with string comparison

Code Snippet: String a; const int red_led_pin = 13; void setup() { Serial.begin(115200); Serial.println("Hello, ESP32-S2!"); pinMode(red_led_pin, OUTPUT); } void loop() { while (Serial.available()) { a =…
3kstc
  • 221
  • 2
  • 11
3
votes
1 answer

How to define and use a list/array of chars using `Serial.print`

I wish to define a list of months names and access it when printing a report. Array was defined as follows: const char months []= {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}; for (int i=0; i<=11; i++) { …
guyd
  • 1,033
  • 2
  • 16
  • 51
3
votes
3 answers

DateTime to string

For some reason I can't use the Time.h lib. Can you guys tell me how to create a string from the datetime into a format like this: yyyy.MM.dd:hh.mm.ss 2014.10.29:07.12.33 Seems odd that I can't find any examples of this.
Terrence
  • 31
  • 1
  • 1
  • 2
2
votes
2 answers

serial write pixels of a bmp image

I'm looking for a way to read a 24 bpp bmp file from a SD cart, and than convert it to text and write it to the serial monitor. So the output should look something like this: R255,B255,G255 And that for each pixel
luukito
  • 21
  • 4
2
votes
5 answers

Is possible to concatenate integers?

It's a basic one: I have two values from two different analogRead pins: int val1; int val2; For example, val1 = 10 and val2 = 10. How could I put these two values into a variable val3 = val1 + val2 that will give the answer 1010, instead 20 ?
Diego Dyan
  • 21
  • 1
  • 1
  • 2
1
vote
1 answer

String comparison problem

I have this callback function in my Firmata sketch. It receives a string as a character array and does something with it. The problem is, that the string is being sent to the Arduino in T\0h\0i\0s\0 form - after each character there is a \0…
Starter
  • 153
  • 1
  • 13
1
vote
0 answers

Sensor to detect whether string is in tension?

I need a sensor to detect whether there is tension on a string or not. I do not need an accurate measurement of the amount of tension- just whether the string is being pulled on or is taut. Alternatively, if there is some homemade hack of this…
Tyler
  • 11
  • 2
1
vote
4 answers

Local char* - keeps its value

Sorry for novice question in Arduino, but I'm trying to figure out why res is keeping its value when up_cmd0 is being called again. for example - if num=8 in first run and the result is :up_cmd0_res: 8, and second run num=12, the result is:…
guyd
  • 1,033
  • 2
  • 16
  • 51
1
vote
1 answer

Return a char concatenation

My goal is to create a function that concatenate 2 chars into 1, and return it as MQTT subscribe. I get a difference between the results inside and outside the function ( I'm new to Arduino ), and I can't find why: Code: // Update variable…
guyd
  • 1,033
  • 2
  • 16
  • 51
1
vote
1 answer

char array comparison

I'm having some issues dealing with strings in a small Arduino app. I wonder why this code works: mqtt.setServer("192.168.1.42", port); and this code doesn't: IPAddress ip = MDNS.queryHost(...); mqtt.setServer(ip.toString().c_str(), port); Even…
Guido
  • 113
  • 4
1
vote
1 answer

RFM69HCW 915 MHz radio module: Sending a stream of int values rather than char[ ]

I'm trying to send a stream of int values (0-4096) from one arduino to another using an RFM69HCW module. Here's my main code: #include #include #define NETWORKID 0 // Must be the same for all nodes #define MYNODEID 1 …
1
vote
2 answers

Why do i get additional characters when reading a file through a buffer if buffer size > 15?

This is a follow up question to How to speed up writing a file to a WifiClient? I modified the old code to read from one Stream and write to another which looked like this and worked fine albite being a bit slow while (file.available() > 0) { …
cross
  • 23
  • 3
1
vote
1 answer

How to convert String to Double?

I found the .toFloat() but that's not accurate enough. String StrEx = "57.10598"; float FloatEx = StrEx.toFloat(); Serial.println(String(FloatEx)); //outputs 57.11 Serial.println(StrEx); //outputs 57.10598
MatMis
  • 177
  • 2
  • 11
1
2 3