Hello, I have a system with multiple sensors and step motors. The data sheet says that A4 and A5 have PWM signal. When I hook up my step motor to them through a driver A5642 to direction and step pins the step motor do not work it only works on D0 and D1. Does anyone know what can I do to turn PWM on A4 or A5.
Thank you
Just for the records: Is this a Photon?
Would be good to state that in the OP
And it would help to see your code too.
Why do you need PWM for the direction pin?
Have you got a link to the driver’s datasheet? Google seems to know as little about that driver as I do
Is the motor driver.
I need PWM only for stepping and i am using photon. thank you
Code:
// This #include statement was automatically added by the Particle IDE.
#include <SHT1x.h>
#define dataPin D0
#define clockPin D1
int relayMotor1 = D6; // used by particle relay shield
int relayMotor2 = D5;
int relayHeater1 = D4;
int relayHeater2 = D3;
int Dir1 = D7;
int Step1 = D2;
int Dir2 = A6;
int Step2 = A5;
int relayPump = A7;
int relayFan = A0;
int motor1up = A1;
int PWM = 0;
int motor1down = A2;
int motor2up = A3;
int motor2down = A4;
int Distance = 0;
SHT1x sht1x(dataPin, clockPin);
void setup() {
pinMode(A5,OUTPUT);
pinMode(D6,OUTPUT);
pinMode(D5,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D7,OUTPUT);
//pinMode(D1,OUTPUT);
//pinMode(D0,OUTPUT);
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
//analogWrite(A5,LOW);
digitalWrite(A5,LOW);
digitalWrite(D6,LOW);
digitalWrite(D5,LOW);
digitalWrite(D4,LOW);
digitalWrite(D3,LOW);
digitalWrite(A4,LOW);
digitalWrite(D1,LOW);
digitalWrite(D0,LOW);
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
digitalWrite(A3,LOW);
analogWrite(A5,LOW);
digitalWrite(A4,LOW);
2^(analogWriteResolution(A5))-1;
analogWriteMaxFrequency(A5);
}
void ventClose(){
delay(1);
Particle.publish("close","close");
digitalWrite(Dir1,HIGH);
digitalWrite(relayMotor1,HIGH);
digitalWrite(Step1,1) ;
delay(1);
digitalWrite(Step1,0);
delay(1);
Distance = Distance + 1;
delay(1);
if ( digitalRead(motor1up) == HIGH){
delay(1);
digitalWrite(relayMotor1,LOW);
}
if (Distance ==2000){
while (true)
{
delay(1);
digitalWrite(relayMotor1,LOW);
delay(10);
Distance = 0;
return;
}}}
void ventOpen(){
delay(1);
Particle.publish("open", "open");
delay(1);
digitalWrite(Dir1,LOW);
digitalWrite(relayMotor1,HIGH);
digitalWrite(Step1,1) ;
delay(1);
digitalWrite(Step1,0);
delay(1);
Distance = Distance + 1;
delay(1);
//if ( digitalRead(SWITCH) == HIGH){
// delay(1);
// digitalWrite(D6,LOW);
// }
if (Distance ==2000 ){
while (true)
{ ;
delay(1);
digitalWrite(relayMotor1,LOW);
delay(10);
Distance = 0;
return;
}}}
void loop() {
float temp_c;
float temp_f;
float humidity;
// Read values from the sensor
temp_c = sht1x.readTemperatureC();
temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();
// Print the values to the serial port
Serial.print("Temperature: ");
Serial.print(temp_c, DEC);
Serial.print("C / ");
Serial.print(temp_f, DEC);
Serial.print("F. Humidity: ");
Serial.print(humidity);
Serial.println("%");
Particle.publish("Celsius", String(temp_c));
Particle.publish("Humidity", String(humidity));
Particle.publish("Fahrenheit", String(temp_f));
if (temp_f <=79 && digitalRead(Dir1)== LOW){
delay(1000);
ventClose();
delay(1000);
digitalWrite(relayHeater1, HIGH);
delay(1000);
digitalWrite(relayHeater2, HIGH);
delay(1000);
digitalWrite(relayPump, HIGH);
delay(1);
digitalWrite(relayFan,LOW);
}
if (temp_f >=80 && digitalRead(Dir1) == HIGH){
delay(1000);
ventOpen();
delay(1000);
digitalWrite(relayFan,HIGH);
delay(1);
digitalWrite(relayHeater1, LOW);
delay(1000);
digitalWrite(relayHeater2, LOW);
delay(1000);
digitalWrite(relayPump, LOW);
delay(1000);
}
delay(2000);
}
I see, this is a motor driver I actually do know - reading this I'd never had guessed
Not sure what these lines are supposed to do
I know what the commands do, but they are not usually used that way.
This also seems confusing
Why an indefinet while()
which will always finish on first iteration?
I can also not see any real PWM use on A4 or A5 - so I'm utterly confused about this code.
BTW, proper code indentation makes it also easier to follow the code.