Skip to main content

Questions tagged [pointer]

A variable in C/C++ which stores the type and location of data in memory.

Filter by
Sorted by
Tagged with
12 votes
4 answers
8k views

Why is it considered bad practice to use the 'new' keyword in Arduino?

I previously asked this question: Is it required to delete variables before going to sleep? On that question, @Delta_G posted this comment: ... Really on a microcontroller I would create the object ...
Tono Nam's user avatar
  • 938
12 votes
2 answers
9k views

Why can I not use pointers instead of array with PROGMEM?

I'm currently changing some libraries to use flash instead of RAM for string storage so that I do not run out of SRAM on a project. Some strings in the library are declared in this manner: const ...
Cybergibbons's user avatar
  • 5,380
11 votes
2 answers
1k views

Are function pointer assignments atomic in Arduino?

The following snippets are from TimerOne library source code: // TimerOne.h: void (*isrCallback)(); // TimerOne.cpp: ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined ...
Joonas Pulakka's user avatar
6 votes
2 answers
12k views

User callback functions

I want to write a class that allows the user to attach his own function to a member function that listens for messages coming from a wireless module, so that the user's function can be called ...
Vasil Kalchev's user avatar
5 votes
3 answers
6k views

Works with gcc, not with Arduino. error: taking address of temporary array

I need to hard code 8 byte addresses into char arrays of length 8. This must be done many places in my code (in function scope), so I have tried to come up with a one-liner. The following works ...
Mads Skjern's user avatar
  • 1,125
5 votes
1 answer
3k views

Is there any working analogue to the pair std::function and std::bind in Arduino?

Both ArduinoSTL and StandardCplusplus don't support them. They implement the version that is compatible with c++03 (not c++11). This functionality is handy when you design libraries that work with ...
Adam Ryczkowski's user avatar
3 votes
1 answer
2k views

How do string pointers work in Arduino?

To the best of my understanding, when I declare String s = "This is a string."; what happens is that space is allocated on the stack for a pointer which points to some String object which internally ...
Samuel S's user avatar
3 votes
1 answer
4k views

ArduinoJSON v6 - Passing buffer as function parameter

I'm new to ArduinoJSON - so perhaps it is a newbie's question.... but I wish to pass a StaticJsonDocument into a function as a parameter ( later on it should be implemented in a library ). exmaple ...
guyd's user avatar
  • 1,049
3 votes
1 answer
12k views

Using pointers with Arduino

I am learning about pointers. I was wondering how the memory address is defined in programming. I get different outputs depending on the format I choose for memory address. So I was wondering if it ...
Jack's user avatar
  • 143
3 votes
1 answer
860 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
3 votes
1 answer
123 views

writting to buffer from serial input

Can some one explain this behaviour please, i have the following code byte buffer[512]; byte block; byte len; Serial.setTimeout(60000L) ; // wait until 20 seconds for input from serial ...
DevilWAH's user avatar
  • 143
2 votes
3 answers
6k views

Storing an array of function pointers

I have some Arduino code that looks like: char packet = ser.read(); switch(packet){ case 'a': someobj.somefunc(); break; case 'b': otherobj.otherfunc(); ...
Cerin's user avatar
  • 1,648
2 votes
2 answers
4k views

Issues converting an uint32_t into a char*

I'm using a capacitive touch sensor that as 12 touch points and stores it's state data as a binary number. I want to take that state, add a bit of data onto the front, and then send it up to a server ...
Chris Schmitz's user avatar
2 votes
1 answer
1k views

Dereferencing char into a struct

I am sending some data over an NRF24 link, using the RF24Network library. So far I have only sent numbers, now I also want to send a string, so I have set up my payload struct as struct payload_t { ...
MortenSickel's user avatar
2 votes
1 answer
345 views

C++ Pointer Issues - Mangled Data

I am having trouble getting my head around pointers in C++, specifically how they behave when passed around or used within objects. As far as my understanding goes as long as pointers, or more ...
Etzeitet's user avatar
  • 123
2 votes
1 answer
1k views

Converting c string to integer to unsigned char

I'm grappling 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 an LED ...
Chris Schmitz's user avatar
2 votes
1 answer
57 views

Mysterious behavior when using objects

I am writing a project that involves using complementary filters to combine gyroscope and accelerator readings in 3 directions. The relevant code is below. class CompFilter { public: long ...
Charles Vorbach's user avatar
2 votes
1 answer
63 views

Dynamic allocation/ Pointer to Pointer to update an Array containing parameter [closed]

topicArray defined as follows: const char* msgTopic = "Home/Messages"; const char* groupTopic = "Home/All"; char* deviceName = deviceTopic; const char* topicArry[2] = {deviceTopic, groupTopic}; But ...
guyd's user avatar
  • 1,049
2 votes
1 answer
101 views

How to pass Encoder object to constructor of a different class

I am trying to create a class (Arm) that controls an arm. The arms have 2 motors, each with an encoder, so I pass 4 integers for the pins and I am trying to pass 2 pointers (one for each encoder ...
EricWeissman's user avatar
2 votes
3 answers
724 views

How do I create global pointers with low memory overhead?

Problem I have a few large objects in my code that need global visibility, but creating them seems to eat up memory significantly faster than simple math would dictate, and furthermore, using them ...
sgbrown's user avatar
  • 123
2 votes
3 answers
310 views

Integer goes garbage after iteration. struct pointer manipulation messed up other variables in memory

I'm writing a library for Charlieplexed LED display (trying to write a common one actually). The library is working quite fine. In my arduino sketch, I'm using an integer to keep track of the LED, ...
Tamal Patra's user avatar
2 votes
2 answers
16k views

How can I pass a char array as the parameter to a function?

I am creating a menu for adjusting system variables. The menu is made up of pointers like so: char* options4[] = {"hMin1", "hMax1", "refr1", "fSpeed1"}; I want to pass the selected string as the ...
xeuari's user avatar
  • 87
2 votes
0 answers
142 views

Program crashes when calling external library code via function pointer

I've written a user library for the Pi Pico that uses the TaskScheduler library to abstract timing away from the user. The user provides a function in their sketch which the library calls periodically ...
Joe of Loath's user avatar
2 votes
2 answers
3k views

Compute SHA256 of string and output to string

In my Arduino project I want to compute the SHA256 hash of a string and store the result to a string, and do this recursively many times (i.e. compute hash of hash of hash etc...). So my goal is to ...
Panos's user avatar
  • 123
2 votes
0 answers
245 views

Using pointer to a Global function

I am trying to store and use a pointer to a global function. The function global_f returns a String and takes an object as parameter: String global_f(Request r){ // ... return "This is it"; } ...
Kostas C.'s user avatar
2 votes
0 answers
248 views

Storing an array of objects

I followed the instructions of this post: Storing an array of function pointers. To show my problem I shorted my code extremely but the problem is still there. My classes are defined as followes: ...
vocaris's user avatar
  • 21
2 votes
2 answers
186 views

Problem with wrapping Adafruit Motor Controller function calls in a class

I'm working on an Arduino robot and I ran into a problem when reorganizing my code. I have an Adafruit Motor Shield v2.3 connected to an Arduino Uno. My robot can be controlled using a bluetooth ...
hubbabubba's user avatar
1 vote
1 answer
12k views

Call by reference

I am trying to learn 'call by reference'. I want to call a function fcn1 from the main loop and pass a reference of the local variable var to the function fcn1. Next step is to call a second function ...
piiq's user avatar
  • 11
1 vote
4 answers
1k views

How do arrays work?

It's been days now I'm trying to figure out how arrays work in Arduino IDE. For better understanding, I assembled some pieces of code I found here and there to write this sketch: #define arrayLength(...
MrCabana's user avatar
1 vote
1 answer
758 views

Can you create an array for functions? [closed]

Let's say I want to create 10 functions, named Function1, Function2 until 10. Each function is used if a certain variable is equal to its number. Rather than using individual functions, I was ...
AndroidV11's user avatar
1 vote
2 answers
2k views

Difference between (*(volatile unsigned int *) and (volatile unsigned int)?

I have been watching tutorials on STM32 bare metal programming. I couldn't understand the purpose of the below code #define RCC_AHB1EN_R (*(volatile unsigned int *)(RCC_BASE + AHB1EN_R_OFFSET)) and ...
Just doin Gods work's user avatar
1 vote
3 answers
2k views

ISR executes even though an interrupt is not triggered

I am trying to implement a function queue scheduling system. INT1 is connected to a button and int1task causes an LED to flash. typedef void (*funcptr)(void); TPrioQueue *queue = NULL; void int1ISR()...
sharon's user avatar
  • 21
1 vote
1 answer
96 views

How to specify a timer's name depending on the chip it will be compiled to?

I need to enable a timer interrupt for a chip, and in the mean time, I am testing the code on Arduino Nano rather than (feed the chip, test the chip)++. So as part of the code I have to TIMSK0 |= (1 &...
B7th's user avatar
  • 167
1 vote
1 answer
184 views

Problem with passing string pointer from child to parent

I am trying to pass a pointer to a const char * from a child to its parent, but I am clearly not understanding how to do this correctly. Here is the code which contains three classes: 1) parent 2) ...
Bob Jones's user avatar
  • 131
1 vote
1 answer
711 views

Initialize and read from a PROGMEM array of pointers to PROGMEM arrays

I'm working on a project for the arduino uno for which I need multiple constant arrays of bytes. Such an array is initialized like so: const byte charR[] PROGMEM = { B01111111,//top half ...
Bo Thompson's user avatar
1 vote
2 answers
476 views

Send a polymorphic object over serial

I am sending a polymorphic object over serial between two Arduinos. The transmission should be fine, indeed if on the receiver side I static_cast the pointer to the Derived class it works properly. On ...
DarioP's user avatar
  • 142
1 vote
2 answers
560 views

Initializing pointer to vector of objects inside another object

i want to create a somewhat complex structure of classes in an arduino. The short story is: a Device has Presets, and each Preset has a Patterns. For that i created the following structure (i am only ...
Luis Ferreira's user avatar
1 vote
3 answers
1k views

How is a local variable address retrieved/returned inside the CPU of Arduino?

How is the address of a local variable retrieved in Arduino's ATMEGA328 micro-controller? Lets say somewhere inside the main we have lines as: int x = 5; //a variable declared and value of 5 stored ...
user16307's user avatar
  • 237
1 vote
2 answers
245 views

cannot convert error with pointers

I write a code to store patterns for LED blinking, but I got this error: led_basics:39: error: cannot convert 'char (*)[17][2]' to 'char*' in initialization led_basics:39: error: cannot convert '...
Peter's user avatar
  • 13
1 vote
1 answer
7k views

How to use String.substring?

I have the following code in which requestLine is always empty and I can't figure out why. request contains a raw HTTP request, and I want to get the first line of the request which contains the ...
3k-'s user avatar
  • 111
1 vote
1 answer
2k views

converting an unsigned integer into a const char pointer

I know this is simple basic C stuff, but I can't quite figure it out or find a solution when searching and reading. I have a method I want to call from a library that wants a const char pointer ...
Chris Schmitz's user avatar
1 vote
1 answer
720 views

I can't receive string that I have sent through nrf correctly

I'm using arduino uno and nrf24l01. to monitor sensor data. But this is the message that master receives: ⸮ this is my slave code. void monitoring() { delay(10); radio.stopListening(); ...
alireza's user avatar
  • 45
1 vote
2 answers
750 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
1 vote
1 answer
839 views

Dynamically modifying the call stack using pointers

In a C++ Arduino library, can we modify the call stack from inside a function by intentionally decrementing a pointer to a stack variable so that it's out of range? Like this: void FooBar() { char ...
AlexKven's user avatar
1 vote
1 answer
139 views

Runtime Error when using array of structs of unknown size as variable within class - some kind of overflow issue?

I have a class defined as below, it's basically a simple ring buffer, with some methods for getting useful statistics from the data held in the buffer. enum BalanceMsgType{ BAL_MSG_NOT = 0, ...
JRVeale's user avatar
  • 125
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
1 answer
322 views

String operators

I have a section of code that I am unsure of what it is doing. static int bufindw = 0; static char buffer[4][96]; static char *strchr_pointer; int result; result = (int)strtod(&buffer[bufindw][...
Sebastian Freeman's user avatar
1 vote
3 answers
2k views

Is it bad coding practice to design a buffer using pointers?

I coded a ring buffer for my Arduino to buffer data from either the SPI or TWI ports. In the .h file I used a pointer for the buffer: typedef uint8_t *ring_buffer_t; typedef uint8_t ring_count_t; ...
tiger19tony72's user avatar
1 vote
1 answer
126 views

Programfault when dereferencing a 64bit int on due

I am running into a strange behaviour with my code. The following works without problems on an Arduino Nano but it seems to crash on a DUE void putData64(byte* packet, int pos, uint64_t data) { ...
user2912328's user avatar
1 vote
1 answer
2k views

Sketch with multiple classes (.h and .cpp) - how to interconnect classes

I wanted to move most functionality of my sketch into different classes, to keep things better organized. One class worked just fine, but when I had to use multiple classes and pass information ...
Emil Jacobsen's user avatar