Hot answers tagged

2

If you have any code you want to run only once at the beggining of your program you can use the setup() method. It can actually do much more than just setting up pins and default values. The code of main function of Arduino (main.cpp) looks like this: int main(void) { //(...) I cut some stuff from here setup(); for (;;) { loop(); ...


2

Generic solution: void loop() { static bool yes_we_did_the_one_time_job = false; if (yes_we_did_the_one_time_job) { do_the_other_jobs(); } else { do_the_one_time_job(); yes_we_did_the_one_time_job = true; } }


1

Another answer chrism didn't mention is to use an "absolute position rotary encoder". It's a device that outputs a bit pattern using "gray code" or "grays binary" that tells you the position of the shaft. The more bits in the encoder, the more precisely you can measure the position. The "gray code" bit pattern enables you to read the changing position ...


1

There are multiple ways to to this. The easiest and most commonly used way is to use a limit switch as home position sensor. At startup the device will first drive the motor in the direction of the limit switch, until the switch get's activated. Now the the absolute position on this axis is known and you can go on from there. (CNC machines and 3D printers ...


1

When motors stuck their current draw increases, you can sense that increase in the current and then change the rotation of the motor. The simplest way to measure current is with using a shunt resistor, for sensing high currents, current sensors based on hall effect sensors is usually used. ACS712 is one example. How to sense current using a shunt? ...


1

I had a project where I needed to run two steppers at the same time as they were moving a heavy load and were moving the same piece. While a servo is going to move the desired spot, a stepper will not. In the process of setting up the stepper you designated steps per rev and amount of steps to take at a time. The stepper is only going to move the "amount ...


1

Like @chris! suggested, you could include two Stepper variables. So in the line where you were initializing the variable, you could instead have: Stepper steppermotor1(stepsPerRevolution, 8, 10, 9, 11); Stepper steppermotor2(stepsPerRevolution, 4, 5, 6, 7); and then continue on with the code for speed, rotation and so on for each motor.


Only top voted, non community-wiki answers of a minimum length are eligible