On both my Orion and Megapi boards, my servos (connected through a MePort) twitch every time a print is issued to the TFT. I thought it had something to do with low memory (i don’t know why I thought that) on the Orion, but the behavior has continued on the Megapi. I’ve swapped ports, MePort and TFT modules and all wiring. Today I’m gonna write a quick sketch involving just these two to see if it happen in isolation.
Anyone else ever seen this?
Twitching servos caused by TFT writes?
Wrote the test sketch - definitely happens on each TFT write.
Anyone else with this combo? Wondering if it’s a softwareSerial issue or a TFT module issue. Not a huge problem except it looks goofy. I don’t update the TFT during servo operations.
Here’s the test sketch. Tried it today, just to make sure and it produces the twitch. The servos twitch about 20-30 degrees at each TFT write. Again, this is present in both Orion and Megapi (with the RJ25 block). I’ve switched ports, tho to be fair, I’ve not tried every port combination. I’ve also tried both boards with ONLY these two modules connected.
(Interestingly, the code format does something weird to the include statements. Seen that other places here on the forums, too. The two includes are for MeMegaPi.h and SoftwareSerial.h. Both in angle brackets.)
`#include <MeMegaPi.h>
#include <SoftwareSerial.h>
MeSerial myTFT(PORT_6); // creates TFT object
MePort port(PORT_5); // creates the MePort object
Servo tiltServo; // create servo object to control tilt servo
Servo panServo; // create servo object to control pan servo
int16_t tiltServoPin = port.pin1(); // attaches the tilt servo on SLOT1 to servo object
int16_t panServoPin = port.pin2(); // attaches the pan servo on SLOT2 to the servo object
void setup() {
panServo.attach(panServoPin);
tiltServo.attach(tiltServoPin); // attaches the servo on servopin1
myTFT.begin(9600);
delay(1000);
myTFT.print(“CLS(0);”); //clears screen before setting up TFT
myTFT.print(“DR2;”); //sets TFT orientation
CenterServos();
delay(5000);
}
void loop() {
double upNum = 0.00;
String upTXT = “Testing”;
upNum = upNum + 10;
myTFT.print(“DS24(0,44,‘Test Run: “); //prints line to pixel line 44
myTFT.print(upNum);
myTFT.println(”’,4);”);
myTFT.println(“DS24(0,180,‘0000000000000000000000000000000’,0);”); // clears the line
myTFT.print(“DS24(0,180,‘Executing: “); //prints line to pixel line 180
myTFT.print(upTXT);
myTFT.println(”’,4);”);
delay(1500);
}
void CenterServos()
{
String upTXT = “Centering Servos”;
myTFT.print(“DS24(0,180,‘Executing: “); //prints line to pixel line 180
myTFT.print(upTXT);
myTFT.println(”’,4);”);
panServo.write(70);
tiltServo.write(90);
}`
I’ll be very interested to hear what you find. The only pieces that are common across my testing are the pan/tilt servos. I’ve replaced boards, MePort modules, MeTFT modules (cause one died!), and sketches. I’ve also powered it (the boards) through USB, 6 AA battery and 12v LiPo.
Single point of failure is servos. I might pull my pan-only assembly off my mBot and try that. If it twitches too…
While the sketch is executing, the servos twitch just as the write is happening on the TFT.
Finally a quite evening to play.
I don’t have the MegaPi, but I do have an Orion. Here is what I found out.
The MeTFT ‘prefers’ Port_5 (grey). I have had some other issues with the MeTFT on other ports in the past, but nothing like this.
-
I have tested your code with various port combinations and have only had success with the MeTFT on Port_5 (i.e. no twitching of the servos).
-
I have only tested the servos on Ports 3,4,6.
Both the MegaPi and the Orion show Port_5 as grey. I am including your modified code (which is working for me).
#include "MeOrion.h"
#include <SoftwareSerial.h>
MeSerial myTFT(PORT_5); // creates TFT object
MePort port(PORT_4); // creates the MePort object
Servo tiltServo; // create servo object to control tilt servo
Servo panServo; // create servo object to control pan servo
int16_t tiltServoPin = port.pin1(); // attaches the tilt servo on SLOT1 to servo object
int16_t panServoPin = port.pin2(); // attaches the pan servo on SLOT2 to the servo object
double upNum = 0.00;
void setup() {
panServo.attach(panServoPin);
tiltServo.attach(tiltServoPin); // attaches the servo on servopin1
myTFT.begin(9600);
delay(1000);
myTFT.print("CLS(0);"); //clears screen before setting up TFT
myTFT.print("DR2;"); //sets TFT orientation
CenterServos();
delay(5000);
}
void loop() {
String upTXT = "Testing";
upNum = upNum + 10;
myTFT.print("DS24(0,44,'Test Run: "); //prints line to pixel line 44
myTFT.print(upNum);
myTFT.println("',4);");
myTFT.println("DS24(0,180,'0000000000000000000000000000000',0);"); // clears the line
myTFT.print("DS24(0,180,'Executing: "); //prints line to pixel line 180
myTFT.print(upTXT);
myTFT.println("',4);");
delay(1500);
}
void CenterServos()
{
String upTXT = "Centering Servos";
myTFT.print("DS24(0,180,'Executing: "); //prints line to pixel line 180
myTFT.print(upTXT);
myTFT.println("',4);");
panServo.write(70);
tiltServo.write(90);
}
Hope this helps.
Mike
P.S. To format code, paste your code into the comment area, select it, then use the </>
button.
You clued me into something I’d suspected, but never tested. If you have the TFT on a I2C port (any marked with white), the twitching happens. Move it to the hardware serial port and all is well. Just moved it on my MegaPi and, boom. No twitch. I wasn’t able to test that combo before due to the MeWifi using that port. On the MegaPi I’m using the Bluetooth module, freeing up that port.
Thank you very much!