Questions tagged [data-type]

Identifies the size and nature of information held by a variable in a program. It is language-dependent. Examples for C/C++ include: `int`, `float`, and `char`.

Filter by
Sorted by
Tagged with
0
votes
1answer
32 views

What else is consuming Data Segment reported by avr-size?

I am facing a low memory available problem in arduino. I am compiling a big sketch for arduino mega 2560. Analysing a .elf file, the avr-size tool gives: text data bss dec hex filename ...
1
vote
1answer
135 views

Int64_t aka long long acts as int32_t and overflows at 2^31

I have an int64_t variable. When I add another int64_t variable and convert it to a double to print it on the serial monitor, it acts as if it was a int32_t variable. This is the program: int64_t a =...
0
votes
0answers
22 views

ModbusMaster - Read 64 Bit integer

i'm using ModbusMaster library (Repo) to read from a device some registers. Many of them are float and i've no problem to read them using the following code: //for float conversation union { ...
1
vote
1answer
22 views

Data type explanation regarding analogRead of a photoresistor

This is a fundamental question - very new (1st post) and trying to learn. I have a photocell connected in series with a 10kOhm resistor between 5v & Gnd (to make a voltage divider) and the ...
0
votes
1answer
50 views

How to convert four uint16_t to double float IEEE754?

I am working in a Modbus project where I have to read modbus Holding and Input registers using ESP8266, I am using ModbusMaster232 library. I returns a response buffer array of uint16_t. I need to ...
0
votes
1answer
36 views

Boolean function call with character pointer input - dont understand how to get updated pointer value

Thank you for everyone's help in trying to find a solution. This library I'm working with was prewritten and is one of the most buggy hardware libraries I've had the misfortune to use. I have now ...
3
votes
4answers
121 views

Can I use 1-byte datatypes to store digital input?

I am reading the docs on DigitalRead() and wondering why it stores seemingly boolean HIGH and LOW inputs in int data type variable. I have two issues with that: int is 2-byte, while bool and ...
0
votes
1answer
60 views

Keyboard.write writing ASCII integer value as a String

I have the following code: #include <SoftwareSerial.h> #include <Keyboard.h> SoftwareSerial ttySerial(10, 11); // RX, TX void setup() { // Open serial communications and wait for port ...
1
vote
2answers
68 views

Why does Arduino IDE recommend storing 0-255 numbers in “byte” instead of “char”?

I bumped into byte datatype recently. My knowledge of C/C++ is shallow, but I know char and I couldn't find much on byte in C++ docs. I looked it up in the Arduino docs: It’s recommended to only ...
1
vote
1answer
825 views

cast double to long leads to unexpected results

I wrote a little program to show my problem: void setup() { Serial.begin(9600); double K=39.85; double a=K*100; Serial.print("a= "); Serial.println(a); long val_long = 0; val_long = ...
0
votes
0answers
44 views

Arduino Lib doesn't recognize String type

I use the following code snippet in a library I wrote: int MyClass::Send(MyMessage* message) { String rev = func(); // Do Work } And in a different library I wrote: String func(){ ...
1
vote
3answers
743 views

Set and extract individual bytes of a number (lowByte() and highByte())

You can extract the low-order (rightmost) byte of a variable or the high-order (leftmost) byte of a word with the functions lowByte() and highByte() respectively (the quotes are from the ...
0
votes
2answers
48 views

What is the best data type to be used through i2C

i'm trying to send multiple commands to multiple slaves controlling motors. Slave Controller(Arduino Nano) will receive the command, and returns the current position of the motors to the Master(...
0
votes
1answer
34 views

What kind of data type can be use store a binary bit-stream which is more than 64-bits?

I'm wondering if one needs to assign a bit-stream of 78 bits to a variable(later on to be processed), what datatype can be used? What is the max bit can be stored into a variable in C?
0
votes
1answer
23 views

What are the sizes of each primitive datatype on a Metro M4 Express SAMD51?

What are the data sizes of all the primitive datatypes on a Metro M4 Express SAMD51 C++ implementation? In some C++ implementations, int has 16 bits and in other implementations it has 32 bits. Is
2
votes
1answer
38 views

double to char* conversion. Weird results from dtostrf

Here’s the code: void setup() { Serial.begin(9600); delay(300); double lat = 1111.11; double lon = 4444.44; const byte len{10}; char sLat[len]; char sLon[len]; ...
0
votes
2answers
153 views

SoftwareSerial receives beginning of data mangled

I'm using SoftwareSerial to communicate with a Sigfox module. Documentation for the read function assigns its value to a char. However using it I get mangled characters and also have read in other ...
0
votes
1answer
36 views

arithmetic operation outcome differs from the expected outcome

I am writing a function void Sound_Play(int frequency,int millisec) A part of this function is: counting=(millisec*frequency/1000); //counting is type int Serial.println((String)"millisec="+...
0
votes
0answers
39 views

Data Structures and Color Data Types in FastLED

So i'm doing something wrong but i don't exactly know what and hope somebody can give me a quick pointer: I declared a starting color for my fastled animation: CHSV startcolor(100, 255, 255); and ...
0
votes
1answer
71 views

Unexpected results when creating 32-bit int from byte array

I'm having problems creating a 32-bit integer from a 4-byte array. In the following complete, minimal, and verifiable example, converting a byte array containing 0x00, 0x04, 0x04F, 0x45 results in ...
1
vote
1answer
134 views

Change data-type String

I'm currently working with an ESP8266 NodeMCU V3 and an IR transmitter breakout board. The module receives NEC IR commands trough a HTTP request and then sends them trough the IR transmitter. Getting ...
3
votes
1answer
547 views

Print unsigned long long in ESP8266

I need to print an unsigned long long variable: unsigned long long t = 1559072327000ULL; I have tried the following: Serial.println(t); // call of overloaded 'println(uint64_t&)' is ambiguous ...
0
votes
2answers
81 views

Problem in defining a variable as multiplication

I have a simplest code to turn on and off a led. The variable holding time definition is onTime, using Arduino Nano. When it is written as: onTime=1000*30, all is good. When onTime is greater than ...
0
votes
1answer
55 views

Data type conversion problem

I have a Wemos D1 board with a OLED display using the u8g2 library. I am printing my MAC-adress on the serial port & would like to print the same information on the OLED: #include <...
0
votes
1answer
322 views

invalid conversion from 'uint16_t* error when creating an array of uint16_t items

I'd like to create an array of remote control codes provided by the raw read feature of the irlib2 library. irlib2 provides the following uint16t arrays using the following format: #define ...
0
votes
2answers
452 views

What data type are the analog pin labels (A0, A1, etc)?

Arduino Mega I would like to have an array containing analog pin labels something like... int analog_pins[] = {A0, A1, A2, A3}; int num_analog_pins = sizeof(analog_pins) / sizeof(analog_pins[0]); ...
0
votes
0answers
129 views

Buffer to string

I'm a bit of a noob, so excuse if this is more obvious to me than to you. I want to convert a u16 to a string. The u16 is the data coming in from the sensor. I need it as a string, or anything else ...
-1
votes
1answer
138 views

How to parse multi line serial data with an unknown number of lines? [closed]

Here's the example data I've read in H-Term: \r\n \r\n NO:0015\r\n G: 5.97kg\r\n T: 0.00kg\r\n N: 5.97kg\r\n \r\n \r\n How to save the number including "kg" to each variable (NO, G,...
1
vote
0answers
159 views

Integer corruption

I use a sensor to measure the temperature. This is returned as float. I feed this float using typecasting (int) to a blink function. This works fine. But the next is step is using this same unchanged ...
1
vote
1answer
3k views

Can't create an array of type const char*

I have something being returned as a const char* and would like to save it to an array. I've tried this: const char* book[amtBooks] = ""; and get this error: error: array must be initialized with ...
2
votes
3answers
88 views

Is the strange problem I'm having to do with comparing floats?

I have a timer interrupt that controls a stepper motor, on an UNO board. In the interrupt handler it checks the speed of the motor and compares it to the target speed. This allows the motor to ...
0
votes
3answers
133 views

How to map 6 bytes of raw data to long long type?

I'm trying to solve some problems for a contest, and I have a problem with it. I have to implement a function that has 3 arguments like this: void foo(unsigned char* A, unsigned char* B, unsigned ...
0
votes
1answer
214 views

Casting custom shared_ptr object

I am using custom shared_ptr class for some program on Arduino, and I need to do something like this: shared_ptr<Base_class> b_ptr; shared_ptr<Child_class> ptr((shared_ptr<Child_class&...
0
votes
1answer
262 views

Arduino variables loaded from SD card

I am trying to load some variables from an SD card on the start up of my arduino Uno. I have been given some advice but am unable to communicate at the same hours. Using this advice, I have the ...
0
votes
1answer
2k views

Arduino: load variables with values read from SD card

I am having a bit of trouble loading values stored on an SD card and assigning them to variables within my program. I can achieve this as one big block of data, but would much prefer them to be saved ...
1
vote
2answers
32 views

Comparing custom variable type definitions

In a library I am using with an OBD adapter, they define a public function to get the state of the OBD connection using some strange (and, in my opinion, useless) custom defined variable type: // ...
0
votes
3answers
10k views

How can i get rid of the error “cannot convert 'String' to 'const char*'”

I want to get this code to recognise different commands and be able to parse the rest of the command, fore example I send "/sleep 5", and it will sleep for 5 seconds. However, I keep on getting this ...
1
vote
1answer
94 views

DS18B20 sending variable via Enthernet shield

I am trying to send temperature read from DS18B20 to a web server. I know two things: to read a temperature, and to send something to web server. What I don't know is how to convert float that ...
1
vote
1answer
3k views

Put integer and double into char array

I want to print text and numbers mixed in a table with Serial.print(); from a char array. My problem is the conversion between the different data types. My idea is to print the data of the rows in a ...
0
votes
1answer
644 views

Store values in array

I'm trying to implement the "BNO055 9 Axes Motion Shield". There is an existing Arduino sketch GitHub that reads out the Euler data, I changed it a bit to print out quaternion data. #include "...
0
votes
2answers
5k views

Converting (char*)variable to int

I have the following code: uint8_t buf[1]; uint8_t buflen = 1; if (driver.recv(buf, &buflen)) // Non-blocking { int i; // Message with a good ...
0
votes
1answer
2k views

RF receiver for integer only, how to cast uint8_t to int?

I'm using the RadioHead library with ASK Driver to transmit/receive data with generic RF modules. It works fine, but I'm lacking some knowledge in programming the code to use the data received. Most ...
1
vote
2answers
1k views

How can I write an integer to a Mifare RFID card using the RFID library?

I'm a beginner to C++ and I'm clearly missing some fundamental knowledge of data types. As such, I'm struggling to adapt the examples in the miguelbalboa/rfid library to my use case. I'm simply trying ...
0
votes
1answer
4k views

Receiving hex data from terminal [closed]

I am trying to transmit serial data from terminal to Arduino and I want to reconfirm that its the same data. But I am not able to get the right answer. I want data to be HEX. I want to check only the ...
1
vote
2answers
1k views

Const data optimisation for Arduino

I'm taking a course on Arduino Uno programming and on today's talk I heard that the const data is optimized by Arduino, so that it occupies less space than the actual data type (namely, a const int ...
1
vote
3answers
2k views

Why char 0x80 == 0xFFFFFF80?

As far as I know a char is an 8 bit variable void setup() { Serial.begin(9600); } void loop() { char x = 0x80; if(x != 0x80){ Serial.println(x, HEX); } delay(1000); }
1
vote
2answers
1k views

Unable to compare two integer values in Arduino Mega

I wrote Arduino code (code is given at the end) to compare two integer values. The steps I took was: Give input to DC motor to rotate it using serial port. Input was: G254 Then I store it in XX ...
0
votes
1answer
3k views

String to unsigned long conversion

I'm trying to use strtoul() to convert an Arduino String to an unsigned long (like the return of millis();) using the following code snippet: unsigned long foo (String time) { unsigned long mili; ...
0
votes
1answer
4k views

What is causing this 'narrowing conversion' warning?

Because I'm still figuring out 'Arduino C' I leave all warnings on. Recently I got this one: narrowing conversion of '(int)(((unsigned char)bx_0) | ((unsigned char)bx_1))' from 'int' to 'const byte.....
0
votes
2answers
119 views

Arithmetic types in Arduino

I'm looking for a complete list of the arithmetic types in the Arduino framework. On the Internet I found various incomplete lists: sometimes there is short, sometimes word, but other types are ...