Questions tagged [pointer]

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

Filter by
Sorted by
Tagged with
2 votes
0 answers
107 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
1 answer
82 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
1 vote
2 answers
841 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
0 votes
4 answers
420 views

How to send multiple bytes with Wire without copying

When I need to send multiple bytes via Wire, for example a long int, I cast it to a byte array and specify a length long int i; Wire.write((byte*)&i, 4); But if I want to send bytes from more ...
user88434's user avatar
-1 votes
1 answer
536 views

Cannot read values stored in bool* pointer [closed]

I'm trying to read values stored in a bool* pointer from a modbus coil call. I'm using modbus-esp8266 library. it's all ok with Input Registers and Holding Registers but i cannot read the result of a ...
MarioC's user avatar
  • 101
0 votes
1 answer
82 views

Failure using references variables in classes [closed]

Theoretical Q I'm having some trouble when using a referenced variable in a class. Class A have an int a=0. Class B has an instance of Class A, and referencing int &a=A.a, and in the same manner ...
guyd's user avatar
  • 993
0 votes
2 answers
1k views

Why I cant get sizeof a pointer Array

well I am trying to get array size to convert hex value to int value. but if I try to get size of array it returns every time 2. Actually .I dont understand. how to get array size, can you help me? ...
mehmet's user avatar
  • 277
0 votes
2 answers
895 views

Passing a two dimensional array to a function

I'm working on an led matrix project where I'm running a series of patterns made of bitmap frames. Here's an example: https://vimeo.com/564184465 Right now I'm using a series of method calls named per ...
Chris Schmitz's user avatar
1 vote
1 answer
546 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
0 votes
1 answer
483 views

esp32 crashes when trying to dereference a pointer value

I have a websocket listener that is giving me a std::string of my message payload (I want the bytes) and I wrote a function that pulls each of the bytes out and puts them into 32 bit integer variables,...
Chris Schmitz's user avatar
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
0 votes
1 answer
191 views

Accessing funcition in object via `->` is crashing (resetting) Arduino

I have several classes that call each other running on an Arduino Mega. I am using the ArduinoSTL library to get the std library, most notably the std::vector. The core problem is as follows: my ...
Mike's user avatar
  • 103
0 votes
3 answers
908 views

Run multiple function with different argument/return structure by one function pointer

Edit: I tried a simple code in Arduino IDE which should've done in the first place instead in doing it in a desktop compiler. Because the results are different by experiment. In the desktop C compiler,...
R1S8K's user avatar
  • 283
2 votes
1 answer
941 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
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
12 votes
4 answers
7k 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
1 vote
1 answer
79 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
0 votes
1 answer
1k views

Setting an array pointer to null on declaration

How can I set an array pointer to null? I have a pointer to a 3 int array that I am trying to set to null. int (*EXCLUSIVE_COLOR)[3]; Per this link I was trying to set it to null upon ...
VerySeriousSoftwareEndeavours's user avatar
0 votes
1 answer
179 views

Assigning an empty array row to reference [duplicate]

int colors[][3] = { { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 }, { 253, 7, 210 } }; int (*EXCLUSIVE_COLOR)[3]; I have a two-dimensional array to store some color values. I have a 2nd ...
VerySeriousSoftwareEndeavours's user avatar
0 votes
1 answer
399 views

Error taking address of temporary array when passing compound literal array

I have an Arduino sketch that passes an array into a method as a compound literal, but for some reason I keep getting the following error: void setup() { } void printConcatLine(char chunks[][20]) { } ...
VerySeriousSoftwareEndeavours's user avatar
0 votes
1 answer
688 views

Swap two arrays (using pointers, not copy)

I've got two arrays, defined as: uint8_t array1[10]; uint8_t array2[10]; I'd like to swap the arrays (actually the pointers to each array) using code like this: uint8_t *tmp = array1; array1 = ...
Andrew M.'s user avatar
  • 145
0 votes
2 answers
171 views

An array of existing arrays

I have a bunch of 3D arrays in the following form: byte lines[][4][2] { { {B00000000, B11110000 }, {B00000000, B11110000 }, {...
Ben Robinson's user avatar
0 votes
1 answer
118 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 ...
AidenDawn's user avatar
0 votes
1 answer
172 views

Function pointers that call one function

I'm reading a library file timer.h for STM core library that I just installed in Arduino hardware folder. Of course, there has to be a lot of questions for me as a beginner about many approaches/...
R1S8K's user avatar
  • 283
0 votes
1 answer
451 views

Passing a NeoPixel object reference to a custom library

I'm new to Arduino programming and haven't programmed in C++ in the past. I'm trying to create a custom library to cycle a rainbow on my NeoPixel LED strip. I want to pass a reference or pointer or ...
William's user avatar
  • 103
-1 votes
1 answer
199 views

Multiple Serial Ports Stream Switch

I am trying to define multiple serial ports (multiple BMS management boards) and select via a global variable the port which one is active, this is the sketch I am trying to modify. https://github....
Paul Fisher's user avatar
1 vote
1 answer
620 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
0 votes
1 answer
167 views

Calling functions from an array of pointers in a library causes 'undefined reference to' error

I am trying to create a library, where I have an array of pointers to functions in it. This array is used by other functions in the library. This is the code of the header file: class Lib { public: ...
LukasFun's user avatar
  • 295
1 vote
4 answers
929 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
0 votes
0 answers
2k views

No known conversion for argument 1 from 'Object*' to 'int*'

I'm terrible with pointers and need help passing an object to a library I'm writing. I'm getting the error no known conversion for argument 1 from 'LCDMenuItem*' to 'int*' when I try to compile. How ...
bwoogie's user avatar
  • 193
0 votes
1 answer
318 views

typedef function pointer array declaration problem

Thanks for all your feedback. It helped. I rewrote this yet another time and this time it works perfectly. I included three variations: a simple example using an array of function pointers, a Lambda ...
Bob Jones's user avatar
  • 131
0 votes
1 answer
186 views

Update `char* `

I have a class containing few char* variables: char* msgTopic = "myHome/MSGS"; char* groupTopic = "myHome/All"; char* errorTopic = "myHome/Err"; but, I wish to have it defined outside the ...
guyd's user avatar
  • 993
3 votes
1 answer
94 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
1 vote
1 answer
160 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
0 votes
1 answer
59 views

Having an issue accessing values from a pointer

Context This may be more of a C++ question than an arduino specific question, but it's dealing with arduino c++ so I thought I'd start here. I'm building a class to abstract some simple melody ...
Chris Schmitz'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
1 vote
1 answer
115 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
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
  • 993
0 votes
1 answer
229 views

Parsing array of an object in a library constructor

I am trying to develop an Arduino library that consists out of two classes. I want 'WayPointStack' to store an array of 'WPCommand', but I can't get it to work. WayPointStack.h #ifndef ...
Kruspe's user avatar
  • 103
0 votes
1 answer
2k views

Passing arrays, global arrays within functions, pointers, and declaring array sizes

I'm super confused right about now! I've been working on project involving Xbees in API mode, and I need to send different arrays of bytes to the Xbee depending on which buttons I press. Mostly what ...
AJ_Smoothie's user avatar
2 votes
0 answers
209 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
0 votes
0 answers
128 views

Losing value of variable

I am making a project involving the AutoConnect, ArduinoJSOn and LedControl libraries to fetch some values from an endpoint. Basically what I do is connect to the internet, fetch the values from a ...
PayToPwn's user avatar
  • 163
1 vote
2 answers
693 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
767 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
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
  • 993
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
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
1 vote
1 answer
646 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
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
2 votes
0 answers
242 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