Questions tagged [pointer]

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

Filter by
Sorted by
Tagged with
10
votes
5answers
3k 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 ...
0
votes
2answers
29 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 &...
0
votes
1answer
64 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 ...
0
votes
1answer
39 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 ...
0
votes
1answer
30 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]) { } ...
0
votes
1answer
35 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 = ...
0
votes
2answers
28 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 }, {...
0
votes
1answer
36 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 ...
0
votes
1answer
47 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/...
0
votes
1answer
56 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 ...
-1
votes
1answer
40 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....
1
vote
1answer
22 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(); ...
0
votes
1answer
32 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: ...
1
vote
4answers
302 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(...
0
votes
0answers
416 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 ...
0
votes
1answer
82 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 ...
0
votes
1answer
44 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 ...
3
votes
1answer
50 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 ...
1
vote
1answer
60 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) ...
0
votes
1answer
37 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 ...
1
vote
2answers
263 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 ...
1
vote
1answer
52 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) { ...
1
vote
1answer
810 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 ...
0
votes
1answer
91 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 ...
1
vote
1answer
678 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 ...
1
vote
0answers
87 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"; } ...
0
votes
0answers
58 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 ...
1
vote
2answers
279 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 ...
0
votes
1answer
205 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 ...
1
vote
1answer
53 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 ...
2
votes
0answers
592 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 ...
0
votes
1answer
59 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 {...
1
vote
1answer
213 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 ...
1
vote
1answer
654 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 ...
1
vote
0answers
97 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: ...
0
votes
2answers
480 views

passing arrays via function returns wrong values [closed]

I am trying to use the values of an array in some other function, but when I return via a function the contents is wrong. This is the external function file I'm trying to use #include "Arrayreturner....
0
votes
1answer
484 views

Pointer memory allocation in function

I would like to know how Arduino allocate memory for pointers in function arguments. For instance. I have this code that use 192 bytes (Arduino IDE compiler: Global variables use 192 bytes (9%) of ...
1
vote
1answer
54 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, ...
0
votes
1answer
388 views

Assigning Pointers to arrays - incorrect results?

I'm trying to build a transmission frame for a workshop library for the Arduino Uno. I have the byte frame inside an array, give it to another function that builds a bit frame and then want to ...
0
votes
1answer
821 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 ...
0
votes
0answers
177 views

Overwrite image buffer (inside Adafruit SSD1306)

I'd like to add a method that replaces the entire image buffer into the Adafruit_SSD1306 library. I haven't worked with dynamic memory handling for ages and I'm not sure how to just simply overwrite ...
0
votes
1answer
695 views

Selecting different arrays using a list of pointers

I have different arrays of different sizes, and a list of pointers to the addresses of each array. How do I select each array using the list of pointers, and access it's elements. On Teensy 3.2 board. ...
0
votes
1answer
5k 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 ...
0
votes
1answer
67 views

Error with pointer in array

I am currently learning pointers. I am following a book (Says Teach Yourself "Arduino Programming") in which there is an exemple about pointer and array. void setup() { // put your setup code here, ...
2
votes
3answers
356 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 ...
0
votes
1answer
671 views

How do I properly convert a pointer (uint8_t* or void*) to a “normal” integer?

I'm writing a program for arduino that needs dynamic memory allocation frequently, but as I don't want the memory to get fragmented, I'm also writing a "memory handler" for it. This memory handler ...
0
votes
2answers
1k views

Receive an array of characters using SIM900 module

I tried to receive an array of characters using SIM900, but I couldn't. I can receive just one character like 'G', but I want to receive a string "abcd". When I used char* to save the SMS, I failed. ...
1
vote
2answers
280 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 ...
0
votes
3answers
10k views

How to pass a string pointer to a function

I'm working on a project, where I wish to use pointers. I had a very quick overview of using pointers in C in collage, but I don't know how to use them. I want that function uses input String (answer)...
0
votes
1answer
948 views

How can I store the received data from nRF24l01+ module in an array (code in description)?

This is my sample RX code for 4 Tx and 1 Rx nRF24l01+ modules. I want to store all the data received from 4 pipes into an array (recArray). #include <SPI.h> #include <nRF24L01.h> #include ...