Hi everyone,
So I have a basic robot, uses the bottom half of a wheelchair, an arduino mega to send servo PWM signals to a Sabertooth 2x25amp motor driver. I recently added a Parallax 2x16 LCD display that uses a serial port. I found an example program for the LCD, tested it on mine, and everything worked fine. I merged the LCD test program into my main program, and now every time the arduino writes or prints to the LCD, the motors do a hard twitch. So I went back to the example code, and brought over some code from the main program relating to the motors to try to duplicate the problem in the example code, and sure enough, they twitch still. Even when I comment out all the 'wheelL.write(wheelLpwmset);', so there's no writing to the motors, they still twitch. Is this because the arduino is crossing Tx wires somewhere? Right now the Sabertooth is in servo mode, and connected to the PWM pins 2 and 3, while the LCD Rx is on Tx pin 16. My guess is when the arduino needs to write serial, it has a hiccup of some sort on the PWM pins. Even when the LCD is disconnected and wires removed, still twitches. I've tried many modifications to my code but the only thing that seemed to make it stop was to comment out any 'mySerialLCD.write(' and 'mySerialLCD.print(' lines. Any insight to this would be really great!
My potential alternative might have to be to switch my Sabertooth to serial port mode also, but I'm trying to avoid this as it will take several hours of testing and re-configuring!
I have also tried digging around the Arduino site to learn what more I can about serial and servos but haven't found anything about serial causing interference with PWM.
- Trevor
const int TxPinLCD = 16;
int timer;
#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerialLCD = SoftwareSerial(255, TxPinLCD);
Servo wheelL;
Servo wheelR;
float wheelLpwm, wheelRpwm, wheelLpwmset, wheelRpwmset, wheelLmax, wheelRmax, wheeltemp;
void setup() {
wheelL.attach(2, 600, 2400);
wheelR.attach(3, 600, 2400);
wheelLpwmset = 90.0; wheelRpwmset = 90.0; wheelLmax = 1.0; wheelRmax = 1.0;
timer = 0;
pinMode(TxPinLCD, OUTPUT);
//digitalWrite(TxPinLCD, HIGH);
mySerialLCD.begin(9600);
delay(100);
mySerialLCD.write(12); // Clear
mySerialLCD.write(17); // Turn backlight on
delay(5); // Required delay
mySerialLCD.print("Hello, world..."); // First line
mySerialLCD.write(13); // Form feed
mySerialLCD.print("from Parallax!"); // Second line
mySerialLCD.write(212); // Quarter note
mySerialLCD.write(220); // A tone
delay(3000); // Wait 3 seconds
//mySerialLCD.write(18); // Turn backlight off
}
void loop() {
wheelL.write(wheelLpwmset);
wheelR.write(wheelRpwmset);
timer = int(millis() / 1000);
mySerialLCD.write(12);//clear screen
mySerialLCD.print("Hello, world...");
mySerialLCD.write(13);
mySerialLCD.print(timer);
wheelL.write(wheelLpwmset);
wheelR.write(wheelRpwmset);
delay(1000);
}