How to store motor position & change values during execution.

Hi to all. I am using Arduino Due development board. In my case, I am using two stepper motors and want to store it's default position in in memory for different settings. Also the default position should get change from user using a keypad and should replace the previous default position stored in flesh memory/data structure.

My major, Confusion is that, With 40-50 types of different settings, Should I go with built in flesh memory or data structure. Suggest if any mechanism is there.

You have to remember steppers have no absolute position recording - you need some form of sensor to know where the motor is positioned ( eg operate a switch at the end point of travel, or if the motor will do it , stall it at the end of travel and count steps back from there).
You can store the position to which you’ve driven it ( eg 10 steps clockwise ) in a variable.
If you want that value after power down , store it in EEPROM, but remember you won’t know where the motor is next time you power it up and your sketch will need to first fund that

Hey, Thanks for the suggestion. I have a solution for power up, first time drive to zero position to sense the limit switch and clear the counter to zero. But, Tell me how can i write the algorithm for store the data. Should i go with structure or array?

But, Tell me how can i write the algorithm for store the data. Should i go with structure or array?

Give us an example of the data you want to store.

A struct is not equivalent to an array. An element of an array can only store one piece of data of one type such as byte or int.

A struct is a definition for a chunk of data that contains several pieces - for example, colour, type of material, width and height. If you design a stuct then you can create an array of the structs so that each element of the array holds the same group of data items.


Like, I would store the position count of the motor from limit switch. In the form of integer data. So, When ever I Start the machine it should take the initial zero position and then after one command from keypad it should achieve that assigned position by taking data from memory.

If the data is in the form of an integer (int) representing the position then you can store many integers (for different positions) in an array.

If you know the values when you are writing the program then just include them as part of the program code.

If you don't know the values until the program runs then, as @hammy said in Reply #1 store them in the EEPROM