Hello,
I have a servo motor that is controlled through a PCA9685 chip with commands sent from the Arduino (Mega 2560 R3) using the SDA/SCL ports. The data coming from the joystick (only 1 axis) hits the Arduino on A0 and gets sent to both the PCA motor and printed on the I2C LCD2004A.
The LCD seems to be successfully displaying information but there is some weird numbers/artifacts (e.g 512,534,557) displayed on the first row of the LCD, blocking initial text coded to appear on that row. This number changes only when Arduino is reset but it never goes away.
This does not happen when I print stock sketches like Helloworld only for when this specific sketch is introduced leading me to believe that the LCD is functioning properly.
I've attached a picture of the LCD showing the problem along with the code below.
thanks!
// Include Wire Library for I2C Communications
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Include Adafruit PWM Library
#include <Adafruit_PWMServoDriver.h>
#define MIN_PULSE_WIDTH 650
#define MAX_PULSE_WIDTH 2350
#define FREQUENCY 50
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Define Potentiometer Inputs
int controlA = A0;
// Define Motor Outputs on PCA9685 board
int motorA = 0;
int potPin1 = A0;
void setup()
{
Serial.begin(9600);
pinMode(potPin1, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor ( 0, 0 );
lcd.print(" ETAG V 1.3 ");
lcd.setCursor ( 0, 1 );
lcd.print("CONTROL 1: ");
lcd.setCursor ( 0, 3 );
lcd.print("HELP: (XXX) XXX-XXXX ");
pwm.begin();
pwm.setPWMFreq(FREQUENCY);
}
void moveMotor(int controlIn, int motorOut)
{
int pulse_wide, pulse_width, potVal;
// Read values from potentiometer
potVal = analogRead(controlIn);
// Convert to pulse width
pulse_wide = map(potVal, 0, 1023, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
pulse_width = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
// Control Motor
pwm.setPWM(motorOut, 0, pulse_width);
}
void loop()
{
// Control Motor A
moveMotor(controlA, motorA);
// Print Value from potPin and Refresh LCD segment
lcd.print(analogRead(potPin1));
lcd.setCursor ( 10, 1 );
int sensorValue = analogRead(potPin1);
Serial.println(sensorValue);
lcd.print(" ");
delay(100);
lcd.setCursor ( 0, 1 );
lcd.print("CONTROL 1:");
lcd.setCursor ( 10, 1 );
lcd.print(" ");
delay(100);
lcd.print(analogRead(potPin1));
lcd.setCursor ( 10, 1 );
Serial.println(sensorValue);
lcd.print("");
delay(100);
}