Hi all.
I am in the middle of teaching myself how a NEMA17 stepper motor works.
I used code that I found online to run the motor.
It was rotating as expected fora while and then after breakfast, it stopped rotating. Then it was working for a while and then stopped.
I read that I need to check the I2C bus.
So I took out my scope manuan d and the manual says, to set the I2C clock signal’s threshold voltage. The threshold voltage level is for decoding, and it will be regard as the trigger voltage level when set the trigger type to serial.*
From what I know, the threshold voltage needs to be 1 volt? Can you guys tell me if 1Volt is the correct threshold voltage? ( I don't remember setting the I2C threshold voltage any where in the code. I feel it is a pre-defined hardware defined value.)
Yes, I am using a UNO as a MASTER and a pro-mini as a slave. Yes, I am using I2C as the communication protocol.
Just want to reiterate taht it was working 100 % for a while and then I moved the entire thing to the basement and now it is not working. LOL.
Ty for the replies.
Thanks for the details but it would have been better if you had explained the exact details in the first place
What do you see when you print the messages received by the Pro Mini ?
Can you control the stepper directly with the Pro Mini ?
How much was the project disturbed when you moved it ?
Is the project in a permanent form such on PCBs or is it on breadboards ?
I assume that you have checked every single wire for continuity and a good connection at each end
well making a stepper-motor rotate doesn't requires multiple microcontrollers.
So what is the special reason to use two microcontrollers?
As long as you only want to make the steper-motor rotate this could even be done
in a "hand-coded" loop.
It is even possible to use a timer-interrupt to setup a certain amount of steps and then give a a "start"-command and let do the timer-interrupt create the stepper-pulses until all pulses are created and then creation of the step-pulses will stop
There are several libraries like accelStepper or mobaTools that make controlling a stepper-motor easier.
So are you still in the state of just make a stepper-motor rotate or are you beyond that to realise a project that does multiple things in parallel to creating step-pulses?
here is a deo-code that shows this
// this demo-code belongs to the public domain
// this code demonstrates how to blink the onboard-LED
// of an Arduino-Uno (connected to IO-pin 13)
// in a nonblocking way using timing based on function millis()
// and creating step-pulses for a stepper-motor "in the backround"
// through setting up a timer-interrupt through configuring timer2
// A T T E N T I O N ! R E M A R K
// some other libraries that make use of timer2 may conflict with this
const byte stepperPulsePin = 9;
unsigned long stepFrequency = 300;
// on fullstep-mode on a 1.8° per Step motor 800 steps means 800 / 200 = 4 full turns
// on halfstep-mode on a 1.8° per Step motor 800 steps means 800 / 200 = 2 full turns
unsigned long numberOfSteps = 800;
//nbt nonblockingtimer
boolean TimePeriodIsOver (unsigned long &expireTime, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - expireTime >= TimePeriod )
{
expireTime = currentMillis; // set new expireTime
return true; // more time than TimePeriod) has elapsed since last time if-condition was true
}
else return false; // not expired
}
unsigned long BlinkTimer = 0;
const int onBoardLED = 13;
unsigned long DebugTimer = 0;
volatile long HighCounter = 0;
volatile long StepCounter = 0;
volatile boolean CreateStepSignal = false;
void setupTimerInterrupt(unsigned long ISR_call_frequency) {
const byte Prescaler___8 = (1 << CS20);
const byte Prescaler__32 = (1 << CS21) + (1 << CS20);
const byte Prescaler__64 = (1 << CS22);
const byte Prescaler_128 = (1 << CS22) + (1 << CS20);
const byte Prescaler_256 = (1 << CS22) + (1 << CS21);
const byte Prescaler1024 = (1 << CS22) + (1 << CS21) + (1 << CS20);
const unsigned long CPU_Clock = 16000000;
const byte toggleFactor = 2;
unsigned long OCR2A_value;
cli();//stop interrupts
TCCR2A = 0;// set entire TCCR2A register to 0
TCCR2B = 0;// same for TCCR2B
TCNT2 = 0;//initialize counter value to 0
TCCR2A |= (1 << WGM21); // turn on CTC mode
TIMSK2 |= (1 << OCIE2A); // enable timer compare interrupt
// the prescaler must be setup to a value that the calculation
// of the value for OCR2A is below 256
TCCR2B = Prescaler___8;
OCR2A_value = (CPU_Clock / ( 8 * ISR_call_frequency * toggleFactor) ) -1;
if (OCR2A_value > 256) { // if value too big
TCCR2B = Prescaler__32; // set higher prescaler
OCR2A_value = (CPU_Clock / ( 32 * ISR_call_frequency * toggleFactor) ) -1;
}
if (OCR2A_value > 256) { // if value too big
TCCR2B = Prescaler__64;// set higher prescaler
OCR2A_value = (CPU_Clock / ( 64 * ISR_call_frequency * toggleFactor) ) -1;
}
if (OCR2A_value > 256) { // if value too big
TCCR2B = Prescaler_128;// set higher prescaler
OCR2A_value = (CPU_Clock / ( 128 * ISR_call_frequency * toggleFactor) ) -1;
}
if (OCR2A_value > 256) { // if value too big
TCCR2B = Prescaler_256; // set higher prescaler
OCR2A_value = (CPU_Clock / ( 256 * ISR_call_frequency * toggleFactor) ) -1;
}
if (OCR2A_value > 256) { // if value too big
TCCR2B = Prescaler1024; // set higher prescaler
OCR2A_value = (CPU_Clock / ( 1024 * ISR_call_frequency * toggleFactor) ) -1;
}
OCR2A = OCR2A_value; // finally set the value of OCR2A
sei();//allow interrupts
}
void setup(){
//set pins as outputs
pinMode(stepperPulsePin, OUTPUT);
Serial.begin(115200);
Serial.println( F("Setup-Start") );
delay(500);
pinMode(onBoardLED, OUTPUT);
digitalWrite(stepperPulsePin,LOW);
digitalWrite(onBoardLED,LOW);
setupTimerInterrupt(stepFrequency);
}//end setup
ISR(TIMER2_COMPA_vect){
if (CreateStepSignal) {
if (StepCounter > 0) {
if (HighCounter < 2) {
digitalWrite(stepperPulsePin,HIGH);
}
else {
HighCounter = 0;
digitalWrite(stepperPulsePin,LOW);
StepCounter--;
}
HighCounter++;
}
else // StepCounter was counted down to 0
{CreateStepSignal = false;}
}
}
void loop(){
if ( TimePeriodIsOver(DebugTimer,500) ) {
digitalWrite (onBoardLED, !digitalRead(onBoardLED) ); // Blink OnBoard-LED
Serial.println( F("Steps left to go ") );
Serial.println(StepCounter);
}
// start new step-Pulse-train every x milliseconds
if ( TimePeriodIsOver(BlinkTimer,4000) ) {
Serial.println("testing set and forget step-output");
if (StepCounter <= 0) {
StepCounter = numberOfSteps;
CreateStepSignal = true;
}
}
}