Questions tagged [struct]

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

Filter by
Sorted by
Tagged with
-1 votes
1 answer
24 views

manage some output based on some parameter and rtc

i'm trying to create a program that given a configuration (i've used multiple struct nested) i need in loop() to check for each output if they need to be on or off and set the output accordingly let ...
Darkmagister's user avatar
0 votes
1 answer
162 views

Doest a local struct variable get destroyed?

For a RF project I need to split payload for a max predefined chunk size. For that I created a RFmsg struct. The unexplained part I need help in is why when I create a local instance of RFmsg, its ...
guyd's user avatar
  • 993
0 votes
0 answers
51 views

I'm looking for the StreamSend.h library for use in Arduino/ESP8266 serial communications using struct [duplicate]

I've come across an interesting yet old article within StackExchange which has great examples of sending structured variables over serial communications. The library StreamSend.h and it's source code ...
Brian's user avatar
  • 11
9 votes
5 answers
2k views

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 ...
Vincent's user avatar
  • 232
1 vote
1 answer
326 views

Trouble initializing a struct array

The goal for this is to create a struct that includes a name, ID, fileName, and a boolean, then create an array of that structs. Here's what I came up with: struct Amiibo { char *aName{}; char *ID{...
Ethan Braun's user avatar
1 vote
1 answer
52 views

Elements excluded from buffer array output after given structure (ESP8266 WifiSniffer) (snifferPacket)

I am currently trying to determine how the ESP8266 WifiSniffer program by Kalanda works. Here is the source code: #include <Arduino.h> extern "C" { #include <user_interface.h> ...
Lachlan Etherton's user avatar
1 vote
0 answers
940 views

incompatible types in assignment of 'const String' to 'char [32] using server.arg

I am trying to create a class and getting getting the error incompatible types in assignment of 'const String' to 'char [32] when I declare char inString[32]; and try to set it as inString = server....
brad's user avatar
  • 201
4 votes
2 answers
10k views

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 ...
iGEL's user avatar
  • 143
2 votes
2 answers
2k views

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 ...
albert's user avatar
  • 205
3 votes
3 answers
5k views

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 ...
Moktar's user avatar
  • 31
1 vote
2 answers
350 views

Accessing struct's variable parametrically on ESP8266

I have 2 instances of a struct. One has def values stored and second stores values read from a file on SPIFFS. I'm trying to use a for loop over all struct's variables - if file was read OK and key ...
guyd's user avatar
  • 993
0 votes
1 answer
295 views

Assigning value to a struct byte order

So i have struct: typedef struct sendPacketStruct { byte header = headerByte;//0x55 unsigned int time;//2 bytes int height;//2 bytes }; And i do this: sendPacketStruct sendPacket; ...
Hayden Thring's user avatar
3 votes
0 answers
22 views

How to properly pass struct as argument? [duplicate]

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 ...
Dariem Fabián Hidalgo Arias's user avatar
1 vote
2 answers
4k views

Typedef struct not working

I made this simple code but I'm getting the following error exit status 1 'RGB' does not name a type typedef struct RGB { double r; double g; double b; }; RGB led; RGB func(...
Ivan Taccadoli's user avatar
2 votes
2 answers
8k views

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; }; ...
ShoutOutAndCalculate's user avatar
0 votes
1 answer
65 views

Multi dimming led - figuring out which led is available for dimming

TL;DR: I tried to have a random fading pattern on several leds and it leads to flickering. Edited following @chrisl answer. I am in the process of creating a simple lamp that show some light ...
Guillaume_slize's user avatar
0 votes
1 answer
534 views

Second item in array not gets assigned from struct object, ArduinoJson

I got the below code generated this amazing tool. const size_t capacity = JSON_ARRAY_SIZE(2) + JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(4) + 2*JSON_OBJECT_SIZE(7); DynamicJsonDocument doc(capacity); ...
Anum Sheraz's user avatar
1 vote
2 answers
727 views

How do I implement reverse enumeration?

Basically I'm trying to output a string based upon a value in an array, the following code is what I have come up with to achieve my desired result, but I have a feeling that there is a better way to ...
H3xx1st's user avatar
  • 11
-1 votes
2 answers
94 views

Memory size issue with the struct

I am working on a project where I have to build an IR program that works with all of the AVR/Arduino boards to control the IR devices such as TV, DVD, etc. I am building a struct that can carry the ...
Alex Zhuravel's user avatar
2 votes
2 answers
2k views

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, ...
the_architect's user avatar
0 votes
2 answers
71 views

Is code in a class repeated for each instance? [closed]

I haven't needed classes before in programming for Arduino, but I now have a good use case. I'm not sure I grasp how this will affect code space, though. Currently I have a struct that holds the ...
Jim Mack's user avatar
  • 237
1 vote
2 answers
688 views

Creating an array of structures which store bitmaps to work with u8glib

I've tried reading the documentations and I'm getting desperate because I can't find anything. I need to create an array of structures, which contains a bitmap stored in PROGMEM space (because of ...
OM222O's user avatar
  • 199
0 votes
1 answer
81 views

Message Interpreter and Handler - How to store a function name in a struct?

For a project, I need to store an array of structures in PROGMEM. Array MessageTable[] will be composed of about ten struct InMessage elements. InMessage looks sort of like this: struct AvcInMessage {...
Bo Thompson's user avatar
0 votes
1 answer
2k views

Printing char array from array of structs in progmem to serial

(I apologize if this is a c++ question, I'm too green to know if this is unique to the Arduino IDE) I've moved an array of structs into my PROGMEM because I was running into memory issues: #define ...
Bo Thompson's user avatar
0 votes
1 answer
51 views

Constants within array of structs causes strange compiler errors?

In my sketch I have the following: #define HU_ADDR 0x190; #define ALL_AUDIO_ADDR 0x1FF; #define MY_ADDR 0x360; #define UNKNOWN_ADDR 0xFFF; typedef ...
Bo Thompson's user avatar
0 votes
1 answer
444 views

FastLED + structs + PROGMEM strange behavior

I'm afraid I have to post a lengthy bit of code, because I can't pinpoint what's causing my issues – in short, it appears repeatedly adding float position + float speed in a struct ends up borking the ...
Bogdan Stăncescu's user avatar
1 vote
2 answers
1k views

Function, struct or class?

I am trying to learn more about arduino programming, and recently i've written functions for randomizing and then modifying a single array. Now i'd like to do the same for four individual arrays. This ...
Erik's user avatar
  • 263
1 vote
0 answers
60 views

Analog Read gives Erratic behaviour in Struct

I'm getting some very strange behaviour from a Haptic feedback system I'm trying to make. The test code works fine as a Multiple-In One-Out in the main loop, but once I moved the code to the Struct, I ...
Minothor's user avatar
  • 111
0 votes
1 answer
3k views

Transfer serial data to struct variable in Arduino

I have declared a struct with some variables that right now are fixed, but one of the variables on the struct needs to be what the Arduino's serial port reads. struct testing_var { const char *...
Luz A's user avatar
  • 69
0 votes
1 answer
222 views

Unexpected results and hard crash when modifying and addressing arrays & variables within a struct

I'm trying to use a 2D array inside a struct on my arduino to store sensor readings. I'm having two main problems: 1: My Arduino is crashing and resetting when I try to access certain directories in ...
Gtingstad's user avatar
0 votes
1 answer
749 views

MIDIUSB - Why is the command put twice?

Consider this function: void noteOn(uint8_t pitch) { midiEventPacket_t noteOn = {0x09, 0x90 | 9, pitch, 127}; MidiUSB.sendMIDI(noteOn); } midiEventPacket_t is defined as: typedef struct { ...
Jonathan S. Fisher's user avatar
1 vote
1 answer
120 views

Can you pass the entries of a strut array to a int array? if so how?

typedef struct { uint8_t pitch; }LearnNote; #define MAX_NOTE 500 LearnNote Noteseq[MAX_NOTE]; int learnindex=0; void loop() { MIDI.read(); } void MyHandleNoteOn(byte channel, byte pitch, ...
Hjhk90's user avatar
  • 291
1 vote
1 answer
6k views

Help with struct variable

I made a struct like this: typedef struct { int color[3]; int positions[4]; char init[20]; void (*fn)(); } buttons; and a variable like this: button test[1] = { {{0,0,0},{0,0,100,100},...
onlygio's user avatar
  • 13
2 votes
0 answers
56 views

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 ...
Justin Shetty's user avatar
1 vote
2 answers
5k views

Use of struct and sizeof in C for Arduino

I am a newbie in C and I can not understand the point of using a structure in C. Could someone explain to me what is the point of defining a structure in C programming? For example, this code(written ...
Jack's user avatar
  • 143
1 vote
1 answer
3k views

Casting a struct member between uint8_t and char, with regard to serial transfer

Im simply trying to pass my payload to another device that has the same architecture and struct. I'm using UART to transfer, and modeling the protocol from EasyTransfer. When I call Serial.print((char*...
Womble's user avatar
  • 189
1 vote
4 answers
9k views

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 ...
Womble's user avatar
  • 189
3 votes
1 answer
821 views

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.) ...
sylcat's user avatar
  • 65
0 votes
1 answer
1k views

I2C_Anything String / Char Array issues

I've been working with the lovely I2C_Anything.h (thanks to the great work and support from Nick over at http://www.gammon.com.au/forum/?id=10896&reply=9#reply9).. All working great, I was using ...
Andology's user avatar
0 votes
2 answers
4k views

Assigning value inside structure array outside setup and loop functions

I'm having some difficulty assigning a value to a variable in a struct array outside the loop and setup functions. Assigning a value to an int or char array works completely fine but this doesn't. ...
oduffy's user avatar
  • 79
5 votes
2 answers
11k views

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 ...
Alex's user avatar
  • 181
2 votes
1 answer
393 views

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 ...
MichalG's user avatar
  • 121
22 votes
5 answers
79k views

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 ...
Cybergibbons's user avatar
  • 5,340
5 votes
1 answer
491 views

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 { ...
brorobw's user avatar
  • 71