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

Why is int only 2 bytes?

When using C/C++ on other platforms, the int type is typically 4 bytes (or potentially more). However, on Arduino, it's only 2 bytes. Why is it different? Does it affect performance if I always use ...
8
votes
2answers
27k views

How to retrieve the data type of a variable?

I am using Arduino and I would like to know if there is a function that returns the data type of a variable. That is, I would like to run something as like the following: // Note: 'typeof' is a ...
8
votes
3answers
9k views

arduino - millis()

Copied from the Arduino reference - millis() Tip: Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ...
8
votes
4answers
25k views

Convert to and from Unix Timestamp

What is the best way to convert between date, hours, min, seconds to Unix timestamp in milliseconds in Arduino? I need to have this conversion, since I'm using RTC (date, hours, min, secs etc) and ...
5
votes
3answers
5k views

How can I convert Arduino String to C string type?

I got a String which as I understand is an Arduino object, and got some C++ code: #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <string.h> LiquidCrystal_I2C lcd(0x20,...
3
votes
5answers
5k views

Serial.print() is slower than it should be

I'm trying to use Arduino as a DAQ but the Serial.print() is not working as fast as I expected. How many bits are sent if you are using a int, because if I use a uint8_t, it's taking the same amount ...
3
votes
2answers
2k views

inttypes vs Arduino defined integral types

In my Arduino projects I use both Arduino types and types defined in the "inttypes.h" file, which #includes stdint.h. So far I've always written code only for the ATmega328P microcontroller (either in ...
3
votes
2answers
309 views

Can I have help interperting this code? char variable somehow storing big numbers

I have this GSM module I got for my arduino project and I am trying to access the call feature, but the function makes no sense. boolean Adafruit_FONA::callPhone(char *number) { char sendbuff[35] ...
3
votes
1answer
168 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 ...
2
votes
3answers
81 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 ...
2
votes
2answers
6k views

Convert uint8_t array to uint32_t array

I have this array of bytes, that I need to convert to an array of unsigned ints. Also the function (btea) that needs it, seems to need a pointer. I'm currently using reinterpret_cast which seems to ...
2
votes
4answers
3k views

Assemble or typecast byte array to float

The serial port on my Arduino Mega is receiving 3 floats as bytes (total of 12 bytes, 4 per float) over serial. Unfortunately I cannot assemble the 4 Bytes in a float, as the serial monitor only ...
2
votes
2answers
118 views

How does an 8bit MCU make use of data-types over 8bits?

how does an 8bit MCU handle 16bit output? How does an 8bit MCU store values higher than 8bits? I am using an attiny, on an adafruit trinket. and other 8bit MCUs. http://www.atmel.com/devices/attiny85....
2
votes
2answers
5k views

Since double and float represent the same data type (usually), which is preferable?

It looks like on ATMega based boards, float and double are equivalent 32-bit (4-byte) data types. However, on the Arduino Due, doubles are 64-bit (8-byte) where floats are 32-bit (4-byte), same as ...
2
votes
2answers
1k views

Arduino Variable Data Type?

Is there a variable data type available for Arduino? I have a class that should have a member that will differ in data type, in the past I have used the "variable" keyword in c++ but when I tried to ...
2
votes
1answer
23 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]; ...
2
votes
2answers
167 views

How can i do something like multi threathing in arduino?

I am checking for ways to implement multi threathing in Arduino, I have also tried using the library TimerOne but it doesn't seem to work, what I'm trying to make is an Arduino application then, every ...
2
votes
1answer
1k views

How to pass value of a function from the RFID-RC522 library into a variable then be sent into either serial or ethernet?

I'm using an RC522 RFID reader with an Arduino UNO. There is a function?? (or whatever it's called :)) in Miguel Balboa's new MFRC522.h library which is mfrc522.uid.uidByte[i] that prints the bytes of ...
2
votes
3answers
1k views

Sending struct from Arduino to Raspberry Pi - wrong types

I'm using Raspberry Pi and Arduinos for my home automation project where Raspberry Pi is the controler of Arduino nodes. I use nRF24 wireless transceivers to communicate. My problem is that when I ...
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
29 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: // ...
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
1answer
2k views

Cast from long to int

How does arduino uno cast from long to int? Does it truncate the bits? (Does it just delete the 16 most left bits?)
1
vote
1answer
1k views

square root of large number

I've got 2 int16_t numbers, say 388 and 10288, which are sensor readings from an accelerometer. I want to estimate the angle of the device on that, but seemingly there are some type overflow issues: ...
1
vote
1answer
66 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 ...
1
vote
1answer
73 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
2k views

Trouble with large numbers

Probably something stupid, but I can't figure out how to work with these large numbers, then cast the result (which will be small) to an integer. I keep getting negative numbers, which I think means I'...
1
vote
2answers
218 views

Is this assignment valid or needs casting?

I have this assignment and while i don't get any error not even warning from the compiler. uint16_t Buffer[40000]; for (int n=0; n<40000 ; n++){ Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n); } ...
1
vote
2answers
2k views

invalid conversion from 'char' to 'const char*'

My intention was to overload a function to handle optional parameters. My code looks like void functionA(const char *errorMsg) { functionA('0', errorMsg); } void functionA(char errorCode, const ...
1
vote
1answer
795 views

IR trouble with raw buffer

I am attempting to send a RAW IR code using the IRremote.h library. The process for capturing IR pulses is easy to find on the web, but the process for sending them again is not. After a few days, i ...
1
vote
1answer
2k 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 ...
1
vote
1answer
2k 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 ...
1
vote
2answers
885 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 ...
1
vote
1answer
110 views

Determine whether a variable is of an arithmetic type

Is there a way to determine whether a variable is of an arithmetic type or not? arithmetic: integer, floating point numbers, boolean values not arithmetic: pointers, references; e.g. strings, and ...
1
vote
1answer
1k views

Using union to return a range of bits from a data frame: wrong approach?

I'm working on an adaptation of Jason Leyrer's Guitar Hero Library for Arduino. My version is for a DJ Hero controller, and I've also borrowed some code from this Arduino forum thread: topic=120527 (...
1
vote
1answer
2k views

Modbus slave data into word

I have simple code. The library downloaded from github:smarmengol/Modbus-Master-Slave-for-Arduino. I wanted to store floating point. In the code blow, I type casted to integer value. As I know ...
1
vote
0answers
142 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
2answers
862 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 ...
1
vote
1answer
1k views

What does 16u and 128u mean?

The below is a snippet of a code for operating SI4455 Rf module with Arduino. I have some doubts which I'd like to seek some help in clearing. byte numOfBytes = *pSetPropCmd++; if (numOfBytes &...
1
vote
0answers
81 views

incoming GSM data stored as variable in code [closed]

I am using an Arduino Mega board with a SIM900 GSM. My goal is to be able to text the GSM with a value of two digits (ex: 79) and then store that value as a variable in the code. I know how to set ...
1
vote
0answers
318 views

How to get Type name of a variable on Arduino [duplicate]

I found this post and implemented the code in a separate classed and then passed different variables to it in an attempt to get the type name printed to serial. The code compiled and worked fine but ...
0
votes
4answers
3k views

Multiplication, division. What is wrong?

const unsigned long C1 = 30 * 1000; const unsigned long C2 = (300 * 1000)/C1; // must be = 10 void setup() { Serial.begin(57600); Serial.println("\n-------"); Serial.print("C1 = "); Serial....
0
votes
1answer
34 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
2answers
75 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
3answers
95 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
2k 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
2answers
93 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 ...
0
votes
2answers
60 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
71 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
131 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]); ...