I have an Arduino Motor Shield R2 and am trying to read the current draw on the motors as they are running.
Questions:
The SNS0 and SNS1 are sent to the A0 and A1 one pins automatically correct? or do I need code to tell it that?
I can read the A0 and A1 using analogread() do I need any other code?
Do I need to connect 3.3V to the AREF input?
My motors are working correctly, changing speed as the pwm value changes and that is showing up on my LCD screen. However I expect the current to the motor to also change but the value is not being updated on the LCD screen.
I borrowed this code from this post "Arduino Motor Sheild & DC Motor"
Code as follows:
#define DIRA 12 // Direction motor pin
#define DIRB 13 // Direction motor pin
#define PWMA 3 // PWM motor pin
#define PWMB 11 // PWM motor pin
#define BREAKA 9 // Break A
#define BREAKB 8 // Break B
#define CURRENTA A0 // Current Sensing A
#define CURRENTB A1 // Current Sensing B
#include "SoftwareSerial.h"
const int TxPin = 6; //Output signal to LCD
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
int PWM_val = 0; // (25% = 64; 50% = 127; 75% = 191; 100% = 255)
int Val1 = 0;
int Val2 = 0;
void setup()
{ pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
mySerial.begin(9600); //Transmit at 96000 baud
delay(100);
Serial.begin(9600);
mySerial.write(17); // Turn backlight on
mySerial.write(22); // disable cursor disable blink
mySerial.write(12); // clear screen and place cursor at upper left corner
delay(5); // Required delay
{
// analogReference(EXTERNAL); // Current external ref is 3.3V
// Serial.begin(115600);
Serial.begin(9600);
pinMode(DIRA, OUTPUT);
pinMode(DIRB, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
//pinMode(CURRENTA, INPUT);
//pinMode(CURRENTB, INPUT);
//digitalWrite(CURRENTA, HIGH);
//digitalWrite(CURRENTB, HIGH);
analogWrite(PWMA, PWM_val);
analogWrite(PWMB, PWM_val);
digitalWrite(DIRA, HIGH);
digitalWrite(DIRB, HIGH);
delay(500);
} /* setup */
}
void loop() {
for (PWM_val = 0; PWM_val <= 255; PWM_val = PWM_val +10)
{
analogWrite(PWMA, PWM_val); // send PWM to motor
analogWrite(PWMB, PWM_val);
analogRead (CURRENTA);
analogRead (CURRENTB);
mySerial.write(128);
mySerial.print("PWM:");
mySerial.write(133);
mySerial.print(PWM_val);
mySerial.write(148);
mySerial.print("AMP:");
mySerial.write(154);
mySerial.print(CURRENTA);
mySerial.print("\n");
delay(500);
} /* for */
} /* loop */