Questions tagged [string]

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

Filter by
Sorted by
Tagged with
62
votes
12answers
372k views

How do I split an incoming string?

I am sending a list of servo positions via the serial connection to the arduino in the following format 1:90&2:80&3:180 Which would be parsed as: servoId : Position & servoId : Position ...
50
votes
13answers
246k views

How do I print multiple variables in a string?

Say I have some variables that I want to print out to the terminal, what's the easiest way to print them in a string? Currently I do something like this: Serial.print("Var 1:");Serial.println(var1); ...
10
votes
1answer
90k views

Convert int to char[]

I'm looking to convert an int value to a char array. currently I've found the following will return [number] int num = [number] str = String(num); str.toCharArray(cstr,16); Serial.println(cstr); ...
9
votes
1answer
6k views

Is it better to use c_str or toCharArray?

When reading/trying a recent answer, I was surprised to see that Arduino's String class supports the c_str() method, just like the C++ std::string class. As expected, it appears to get a pointer to ...
8
votes
3answers
1k views

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 ...
8
votes
2answers
2k views

Convert a Bitstring into an integer value

I have got a String filled up with 0 and 1 and would like to get an Integer out of it: String bitString = ""; int Number; int tmp; bitString = ""; for (i=1;i<=10;i++) { tmp= analogRead (...
8
votes
1answer
10k views

Arduino Convert std:string to String

I'm working on BLE project with espressif library. And It returns me founded BLE device. std::string getManufacturerData(); std::string getName(); int getRSSI(); BLEScan* getScan(); When ...
6
votes
6answers
8k views

Understanding why should avoid “String” and alternative solutions

Why “Strings” are bad for Arduino? Which is the most efficient and fastest solution to read and store the data from Accelerometer and GPS? Stings are evil for Arduino An Uno or other ATmega328-...
5
votes
1answer
22k views

How do I send a string to master using i2c

I want to write an Arduino program that simply recieves a string (via the I2C wire library) from a master Arduino, then waits for a request, and sends that string back. Here is my code: #include <...
5
votes
3answers
6k views

Arduino String memory allocation

When a String variable is declared and modified inside a function, where does it go? To the heap(as string declaration is a part of dynamic memory allocation) or to the stack(as it is a part of ...
5
votes
2answers
15k views

Creating formatted String (including floats) in Arduino-compatible C++

I'm using a Mega2560 and a generic SSD1306 OLED display with the Adafruit_SSD1306 (and by extension, Adafruit_gfx) library. I need to print a bunch of float values (ranging between 30.0 and 99.9) to ...
5
votes
1answer
31k views

How to append float value of into a string ?

I have a float variable lng = 33.785469 and lat = 78.126548. Now can I convert them to String and append in a String variable "my_location" as "your location is \nlng = 33.785469 \nlat = 78.126548". I ...
5
votes
1answer
3k views

Serial.write and Serial.println return different values? Cannot use correct ones

I have a text file on an SD card, and I am trying to print the lines to the serial monitor. This Code Works: #include <SPI.h> #include <SD.h> File myFile; void setup() { Serial.begin(...
5
votes
1answer
4k views

Format Integer in Arduino

How to format an integer as 3 digit string? If I give 3 formated string should be 003 printf("%03d\n", 3); // output: 003 This doesn't work in Arduino.
4
votes
5answers
13k views

formatting strings in Arduino for output

I wander what is the best option for formatting strings in Arduino for output. I mean what's a preferable way in the point of view of performance, memory usage – things like that. I see, people ...
4
votes
4answers
24k views

What is better: one sprintf() or multiple strcat() and itoa()?

I was creating Arduino function which sends two int and additional chars between them and at the beginning and end of char array - then print that array to the serial port in almost real time. (For ...
4
votes
2answers
5k views

Simple URL decoding

How can I do a readable, small, smart and good URL decoder in Arduino? Now I'm using this code: String GetRidOfurlCharacters(String urlChars) { urlChars.replace("%0D%0A", String('\n')); ...
4
votes
3answers
38k views

Very Basic Arduino Uno Serial.readString() operation

I am very new to Arduino Programming. I am trying to identify the input string from serial monitor and printing the output to the console accordingly Code is : void setup() { Serial.begin(...
4
votes
3answers
2k views

eval() function for Arduino?

I plan to do the following: void setup(){ String term = "12 + (2 * 5)"; int result = eval(term); // eval function (from Python) Serial.println(result); // expecting 22 } However there is no ...
4
votes
1answer
3k views

Check contents of buffer after serial read

I would like to test the contents of data received over a serial connection. In my loop() I store the data in bffr; and afterwards I would like to test to see if there are some predefined words in it. ...
3
votes
2answers
3k views

Concatenation of non constant character array with a string

I have an Arduino Duemilanove. I read this page on string concatenation. Yet, it didn't include my case. I have a non constant character array, that later gets a value. char clat[11]; dtostrf(gps....
3
votes
5answers
7k views

How to compare a string

How to compare a string coming from serial monitor with some predefined text stored as a local variable? If I say: int led = 2; String a = " abcds"; void setup(){ Serial.begin(9600); } void loop(...
3
votes
3answers
3k views

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?
3
votes
2answers
2k views

What is the memory expense of creating a String from a char array?

I'm writing a little API for processing email messages in Arduinos. Obviously, I need to keep memory use down, but I also want to allow the end user to use the String functions (like indexOf) to ...
3
votes
1answer
120 views

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

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',...
3
votes
2answers
536 views

Understanding memory fragmentation due to char arrays in functions

This is similar to: Is this function subject to memory fragmentation? I am trying to get my head around Memory fragmentation in Arduino's and embedded systems in general. Currently I have a ...
3
votes
1answer
17k views

Split string into an array of string

I have a SIM900 module connected to an Arduino Uno, using an AT command for listing the SMS I get this output, how can i split this based on (,) to store each data in an array? AT+CMGL="ALL" +CMGL: ...
3
votes
2answers
11k views

Problems on convert byte[] to String

I'm reading a RFID Card from RC522 and send the data to my computer. My problem is the conversion of byte[] to String or std::string. #define SIZE_BUFFER 18 #define MAX_SIZE_BLOCK 16 byte ...
3
votes
1answer
950 views

Declaring literal strings

When I want to write a literal string in Python, I use r before the string (or @ in C#): in [1]: print r'\no esca\pe ch\ara\cters' out [1]: \no esca\pe ch\ara\cters In straight c++ I can use R, but ...
3
votes
1answer
811 views

Using UART to Set RTC

I'm using an Adafruit NRF8001 Low Energy Bluetooth module and a Real Time Clock module with my Arduino board. I want to connect to the BLE module using UART to set the clock. I'll also be using UART ...
3
votes
4answers
6k views

Convert String to IPAddress

How can i convert a String to IPAddress on arduino / esp ? etc. "192.168.1.2" -> IPAddress(192, 168, 1, 2) Tried this void setup() { Serial.begin(115200); IPAddress apip; const char *...
2
votes
3answers
6k views

Send multiple sensor values over serial

I want to send a JSON string over serial from arduiono device to my computer. The JSON string contains a sensor value array. To fill this array I use String.concat("value") function. But If I have ...
2
votes
2answers
3k views

The most effective way to format numbers on Arduino

I made a big search about how to Format Numbers with the Arduino. I want to format unsigned Longs into a String in this format: "23,854,972". The most of the snippets I found work only with the ...
2
votes
3answers
2k views

Arduino IDE c++ 11 raw string literal have issues with // in http://, complier thinks // is comment

char webpage[] PROGMEM = R"=====( <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js"></script> </head> <body> &...
2
votes
3answers
241 views

How to actually concatenate two Strings?

I'm using the SPISlave library, and I have the following code snippet: String arg; SPISlave.onData([arg](uint8_t *data, size_t len) { data[len] = 0; arg += String((char *)data); // ... } The ...
2
votes
3answers
19k views

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 ...
2
votes
1answer
1k views

Using c_str() on String for IPAddress with NTPClient provides wrong values

Libraries NTPClient Board Olimex ESP32-POE board Behaviour I have written a code that connects the board to a local NTP Server (which is an embedded board). I tried assigning the IP Address of ...
2
votes
1answer
9k views

How do you convert a formatted print statement into a string variable?

I'm using the following routine to print the current time on the com port. I would like to capture this as a string so I can display it using ePaper. void printLocalTime() { time_t rawtime; ...
2
votes
2answers
305 views

How do I isolate numbers in text?

I need to separate numbers from the text where my string of numbers will always be of length 8: string text = "77953505HELLO THIS IS A MESSAGE"; //my string of numbers will always be of length 8 My ...
2
votes
1answer
2k views

Does the StringObject.reserve() function prevent memory fragmentation/leaks?

I'm currently writing and testing a professional Arduino application, I'm aware of the dangers of using the String class, so I began to implement C-style strings in some places, but it's just way ...
2
votes
1answer
6k views

Sending string over serial to nodejs app. Why does it get chunked?

I'm sending a string from my sketch over Serial port as follows: Serial.println(F("Found ILI9341 LCD driver")); On the other side, I have a nodejs app using the serialport npm module, with something ...
2
votes
2answers
161 views

A question about chars and Serial

I have the following code: int count = 0; char serial_char; char serial_message[96]; void setup(){ Serial.begin(9600); } void loop(){ while(Serial.available() > 0){ serial_char = Serial....
2
votes
1answer
58 views

Why are characters with value above 127 “padded” with 1s to be 16 bits long, while ones with values 0-127 aren't?

I am using the Arduino IDE to run and monitor, with an Arduino Nano clone. This code shows what I mean by the question: char foo = 127; char bar = 128; Serial.println(String(foo, BIN)); Serial.println(...
2
votes
2answers
8k views

function returning String-Array

i'm still new to arduino and also to C++ and have a short question. What i want to do is to write a function (in my case to parse the query-string of an URL) to get the parameter names and values (...
2
votes
2answers
90 views

Help with a Memory Issue

Below is some code that I'm writing to concurrently run "animations" on the same strip of NeoPixels. When I try to make use of the Serial monitor to control the program functions, I just get a bunch ...
2
votes
1answer
95 views

Converting c string to integer to unsigned char

I'm Trying to grapple with types between two different libraries. The gist is that I'm using the ArduinoWebsockets library to receive information coming from my api that I then want to render out to ...
2
votes
1answer
233 views

Comparing a String after reading it from Serial fails

I have bought an Arduino starter kit online, everything seem to work but when I try for example to use ifs (and other conditional statements), the LEDs do not turn on. Here is a code for a little ...
2
votes
1answer
660 views

Arduino String: use a non-null-terminated char array?

I'm using a library that takes a String as it's parameter (https://github.com/gmag11/painlessMesh) I want to pass char arrays that is binary (UTF-8) data that also contains null-bytes (0x00). Right ...
2
votes
2answers
690 views

Send String to a function inside a class

I made a little class for handling menus. When creating a new instance, I pass a reference to the oled object made in main.cpp. Yet when I want to render a string using a variable, it throws an error. ...
2
votes
3answers
14k views

How do I send a string from an Arduino Slave using SPI?

I have an Arduino Uno acting as a master with 3 Arduino Nano's acting as a slaves. Looking at this example: http://www.gammon.com.au/forum/?id=10892, it tells me how to send a string from the master ...

1
2 3 4 5
7