Questions tagged [struct]

Refers to a basic data structure (also called record).

In computer science, a record (also called struct or compound data) is a basic data structure. A record is a collection of fields, possibly of different data types, typically in fixed number and sequence.

46 questions
22
votes
5 answers

What overheads and other considerations are there when using a struct vs a class?

C on embedded systems has traditionally use structs to hold structured data. Arduino brings C++ to the table, so we can use classes instead. Lets say we have two different data structures which could be considered very similar: typedef struct { …
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51
9
votes
5 answers

Same structure taking different memory space on Uno and NodeMCU ESP8266, leading to data corruption when transferring via nRF24L01+

I'm trying to transfer data between a Arduino Uno board to a NodeMCU ESP8266 board, using nRF24L01+ transceivers module and RF24 library on both side. The data I'm transferring are stored in a struct defined this way: // Struct declared in both…
Vincent
  • 232
  • 2
  • 10
5
votes
1 answer

Last element of a struct disappearing on write/read

I'm building a weather station with two UNOs, using NRF24l01+ radios. Communications are fine. I'm sending a struct from one to the other. The struct has three elements: struct weather { float tempData; float humData; float…
brorobw
  • 71
  • 2
5
votes
2 answers

Using PROGMEM to store array of structs

I am hitting the limits of my arduino's SRAM and found that SRAM usage can be reduced by storing static stuff in flash memory instead of SRAM. My project can (optionally) be built with an included SimulatorClass. I use this to 'playback' data at…
Alex
  • 181
  • 2
  • 3
  • 9
4
votes
2 answers

Initializing Array of structs

I defined myself a struct: typedef struct { unsigned char current; unsigned char start; unsigned char target; unsigned long startTime; unsigned int duration; } led; I was able to initialize an instance of that like this: led h_red =…
iGEL
  • 143
  • 1
  • 1
  • 4
3
votes
3 answers

How to get the sizeof array of structs

I'm trying to make a use of a relay module, I want a clear way to configure and control my relay module I've defined the struct and filled it with some info about id, pin number, title, and relay state I can't loop with for in the array of controls,…
Moktar
  • 31
  • 1
  • 2
3
votes
0 answers

How to properly pass struct as argument?

This is my first question! i'm sorry if i'm doing something wrong. I'm trying to write a code that blinks some leds, but i cant quite work out how to use structs as arguments. This is the code: void setup(){ pinMode(2, OUTPUT); pinMode(3,…
3
votes
1 answer

sending ctrl-z in a struct?

I have a set of buttons wired to an arduino leonardo that are meant to send either single keystrokes to a computer "a, b, c..." etc, or a key sequence like ctrl+z (to perform an undo command.) Effectively this is a little usb keyboard with pre…
sylcat
  • 65
  • 6
2
votes
2 answers

Own type definition using a struct does not name a type

I need to initialize several buttons and LEDs connected to my Arduino. To store data related to an individual button or LED, I decided to define my own data type using two different structs. One for a button and another one for a LED. As I need to…
albert
  • 205
  • 2
  • 13
2
votes
2 answers

Send structure through Serial

Suppose that one defined a data structure and wanted to send it through serial. struct Gyro_data_structure { char command_name[5]; float gyro_X; float gyro_Y; float gyro_Z; }; Gyro_data_structure Gyro_data; int…
2
votes
2 answers

Why does a variable size struct not compile in the Arduino IDE?

This sketch does not compile in the Arduino IDE void setup() { // put your setup code here, to run once: } struct test { int i; char variable[]; }; typedef struct test test; test t = { 0, "hi" }; void loop() { // put your main code…
2
votes
0 answers

Erratic behavior from 'randomly' generated values in array

Currently working on a data collection algorithm on the Arduino MEGA (ATMega1280) and I've run into a problem with some of the code I've written. I feel my problems may be stemming from the way in which I'm storing the sample points I've generated…
2
votes
4 answers

Transfer a struct's data to an external struct via serial?

Using two boards of similar architecture I would like to send the contents of a struct from the sending board to the receiving board. I am using UART to transfer. My plan was to populate an array with the starting structs data. Transfer that, than…
Womble
  • 199
  • 2
  • 9
2
votes
1 answer

XBee, external libraries and passing structures as arguments

I have very weird problem with a library I am creating. The library will be used to communicate between Arduino modules using XBee Series 1 modules. Library is very simple wrapper library around Arduino XBee library. I have one function that reads…
MichalG
  • 121
  • 1
1
vote
1 answer

How do I convert a structure to a char[] for use in Wire.h, or is there a better way?

I need to interface an ATTiny88 MCU configured as an I²C slave with a Raspberry Pi configured as an I²C master. I may be using the wrong approach, but I have a structure consisting of four different fixed length data types I want to pass back to…
LesRhorer
  • 115
  • 8
1
2 3 4