Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pointer]

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

0
votes
1answer
22 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
24 views

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

topicArray defined as follows: const char* msgTopic = "Home/Messages"; const char* groupTopic = "Home/All"; char* deviceName = deviceTopic; const char* topicArry[2] = {deviceTopic, groupTopic}; But ...
0
votes
0answers
31 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
30 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
43 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
35 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
43 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 extremly but the problem is still there. My classes are defined as followes: ...
0
votes
2answers
103 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
111 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
24 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
111 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
251 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
86 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
196 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
1k 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
46 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
124 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
298 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
621 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
168 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
5k 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
629 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 ...
1
vote
2answers
182 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 ...
0
votes
2answers
5k views

Setting a pointer to NULL in Arduino library - error: ‘NULL’ was not declared in this scope

I am writing my own library for using with my Arduino. In my code, if I set a pointer I have declared to NULL, such as int *ptr=NULL; I get the error error: ‘NULL’ was not declared in this scope I ...
0
votes
3answers
462 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 ...
-1
votes
1answer
60 views

Keep References Between Objects

I'm trying to recreate a small tween engine so I can interpolate values, leds hue, saturation and brightness in a easy way. I'm having trouble to reference the value to interpolate into my tween ...
2
votes
1answer
3k 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 ...
0
votes
1answer
59 views

Pass custom element of an array from an inherited class to main sketch

I'm building a base class that creates color patterns using FastLed's CRGB structure. I use the base class as inheritance for another more specific class that modifies a vector of colors (Pixels[]) ...
2
votes
2answers
126 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 ...
0
votes
2answers
117 views

Pros and Cons of using a non-pointer class object

In this example I have an one object which uses a pointer and one object which does not. class MyClass { public: void myMethod() { // do nothing } }; MyClass* mc1; MyClass mc2; void ...
2
votes
3answers
3k 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(); ...
0
votes
1answer
3k views

Remove certain characters from char*

I've got an array of char* with serial data that I'm trying to remove ':' from. I have tried to iterate through the char*, find and remove any colons but it just comes out as garbage. char* espData[...
4
votes
2answers
6k 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 ...
2
votes
3answers
164 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, ...
1
vote
1answer
1k 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((...
6
votes
3answers
2k 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 ...
3
votes
1answer
738 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 { ...
0
votes
1answer
113 views

Why doesn't my object's method return back to my caller method?

I am creating a miniature computer using an Arduino, and I am creating a full-scale interpreter for it. Everything works, and the code begins to run after calling the runCode method, but once the run ...
2
votes
1answer
41 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 ...
2
votes
2answers
9k 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 ...
3
votes
1answer
293 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.) ...
2
votes
1answer
269 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 ...
1
vote
1answer
268 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][...
0
votes
2answers
6k views

Pass a member function pointer to a method of a foreign class (EDB Lib)

I'm currently working on my own arduino library and I'm becoming exasperated with the following problem: I want to store data with the extended database library (https://code.google.com/p/arduino-edb/)...
1
vote
2answers
167 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 '...
0
votes
2answers
104 views

Use pointer in calculation results in error

I'm building a project to measure/track flyball dog races. The dogs timings are measured by photoelectric sensors at the start/finish line of the racing lane. I have most of my code working (available ...
1
vote
3answers
1k 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()...
0
votes
1answer
1k views

Wrong Mouse.move() output in Arduino Leonardo

I'm using my Arduino Leonardo as a Mouse but I'm experimenting a strange behaviour. I put my mouse at (-1, -1) (absolute) coordinates and then I execute this code: Move.move(com[curr_cmd_id].x, com[...
1
vote
3answers
852 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; ...
10
votes
2answers
822 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 ...