Can MeCompass and MeTFT live on the same bot?


#1

Greetings MB community!

I started last night making the mods for my (IR version) starter tank. To the original configuration, I added a MeCompass, MeTFT and MeWifi. I also added the pan/tilt servo kit to give the ultrasonic sensor some flexibility.

I started out testing each piece by loading the test sketches from the examples. The only modifications I made to them were to change port numbers, if needed. The compass worked great in the test script, displaying to the serial monitor the heading with no issues.

I then copied the necessary lines to my sketch. Right away, instead of getting past the “initializing i2c devices…” line, it hangs right there. The first line in the sketch was the call to initialize the TFT. So, I tried commenting out that line. Runs perfect.

I’ve heard stories of other sensors messing up the compass, so I’ve mounted it high above the board. At the bottom of the mount, I do have the TFT. I tried disconnecting the TFT from power with no effect, as long as the call exists to initialize it, the compass will not return from the Compass.begin call. If I comment out the TFT initialization, the compass returns to working fine. Even if the power is left on to the TFT.

In short, if I comment out the line initializing the TFT, the compass initializes and begins to send headings (though obviously in this script, just once - in the example sketch, it continues to send and change as I rotate the bot) . If I leave the line in, the compass simply blinks the blue led. The serial monitor stops at the “initializing i2c devices…” line. Nothing continues.

So can the TFT and compass live together on the same bot? Is the fact that the TFT uses serial communication causing the issue? Any mods you all might see that allows them to work together?

Above setup():
MeSerial mySerial(PORT_3); //connects TFT to Port3
MeUltrasonicSensor ultraSensor(PORT_4); //connects ultrasonic sensor (on tilt/pan) to Port4
MeWifi wifi(PORT_5); //connects MeWifi to Port5
MePort ptPort(PORT_6); //connects MePort to Port6

Servo panservo; //create servo object to control pan servo
int16_t servo1pin = ptPort.pin1();//attaches pan servo to slot1
Servo tiltservo;
int16_t servo2pin = ptPort.pin2(); //attaches tilt servo to slot2

MeCompass Compass(PORT_8); //attaches the MeCompass to Port8

void setup()
{
Serial.begin(9600);
Serial.println(“Initializing I2C devices…”);
Compass.begin();
Serial.println(“Testing device connections…”);
Serial.println(Compass.testConnection() ? “HMC5883L connection successful” : “HMC5883L connection failed”);

GetCompassHdg(); //gets compass heading and prints to serial monitor

panservo.attach(servo1pin); // attaches the servo on servopin1
tiltservo.attach(servo2pin);
}


#2

Moving the compass initialization line above the TFT fixed it. Go figure.

On to getting the TFT to display distances!


#3

OK, so it’s not fixed.
I have the MeCompass in port 8 and the TFT in port 3. If I initialize the TFT (MeSerial mySerial(PORT_3) above the intialization for the compass (meCompass Compass(PORT_8), then the compass will flash the blue led and nothing continues.
I thought all was well once I reversed the order. All that really happened was that the compass glowed a steady blue led.
In both cases, the program hangs right there.
I loaded the example sketch for testing the TFT from Makeblock examples. I corrected the port number and ran the sketch. Everything works fine. Of course, the only thing working is the TFT.
I then modified that sketch so that the compass was initialized. I also added the Wire.h header.
Everything, that is, the TFT, works fine.
Then I added the Compass.begin(); line (trying both before the mySerial and after) to the setup(). Hangs immediately on the compass. Compass light glows steady blue. Nothing else happens.
Since someone has a bot using both on YouTube and I’ve seen the bot in action, I’m guessing it CAN work. Any ideas on why mine isn’t working? His bot used port 4 for compass, serial on 5.
Could port numbers be the problem?
Any suggestions?


#4