Hey guys, I'm trying to run a simple sketch with an Arduino Uno and a Pololu Max14870 driver
(https://www.pololu.com/product/2961), running a 24v dc motor. I have 24v supplied to the VIN, the dc motor is connected to M1 & M2, common ground with Arduino, Arduino D8 to PWM and Arduino D9 to DIR.
I am getting +5v to the PWM and 0v to the DIR pin at the correct time, and +5v to the PWM pin and +5v to the DIR pin at the correct time.
Here is my code:
int in1 = 8;
int in2 = 9;
int state = 1;
void setup ()
{
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(0,INPUT);
int ldr = (0);
Serial.begin(9600);
}
void TurnMotorA()
{
digitalWrite (in1, HIGH);
digitalWrite (in2, LOW);
I recommend you to add some more Serial.println() to the if blocks, then run your code with Serial Monitor open to make sure the program is working as you expect it to. Make sure to add braces ({}) to your if statements before adding the Serial.println().
One thing that seems strange to me is that you print the value of ldr multiple times. The value will be the same for all three, so what's you're reasoning for doing it three times?
Thank you for responding. I have been running the sketch with serial monitor open, and the sketch is working as expected. I added Three serial print so I could see what level the ldr is registering more frequently (every 5 seconds as apposed to every 15), maybe it's unnecessary.
When I run the sketch, I check voltage on the 8 & 9 pin as I watch the serial monitor, and I get +5v on each at the appropriate times.
This is my first time using the MAX14870 and I keep thinking it's a wiring problem rather than a code problem, but the wiring seems pretty straight forward.
The value of ldr is only updated once each time the loop() function runs, right here:
int ldr = analogRead (0);
[/quote]
So printing the value of ldr multiple times per loop doesn't give you any better idea of what the LDR is registering, since it will always print the analog reading from the start of the loop.
Since you are getting the expected voltages, it is likely that your code is running as you expect it to and I think you're right to look more closely at the hardware side of things.
Thank you. I'll delete the unnecessary serialprints. Are you familiar with the MAX14870? I have it wired as per the "minimal wiring diagram" found on their website. With Arduino pin 8 -> PWM and pin 9 -> DIR.
I've checked voltage at the pins on the MAX14870 end and it's good. Pololu's site says it does not need additional logic input, but I feel like I'm still missing something...