1.8" TFT Display to Baby-O with LSM303DLH Compass

Support for the A-Star and the Orangutan family of robot controllers.

1.8" TFT Display to Baby-O with LSM303DLH Compass

Postby streichre » Sun Jan 22, 2012 7:24 pm

I started a new post to differentiate between the different projects for the 1.8" TFT display. This one focuses on the LSM303DHL Compass module from Pololu to a BabyO using Arduino code.

This sketch sets up the display to show the output from the compass. The accelerometer data for the XYZ planes is displayed in text and by a graphical bar. The accelerometer data ranges from -2048 to +2047. The bar graph is setup to convert the accel data to +/-2g. The heading is displayed in text as degrees and by a compass dial. The Arduino sketch code is posted below.

I kept some of my Serial Monitor debug code in the sketch.

I plan on mounting this to my "tank" platform and using Wixels to send the information back to my computer.

Keep having fun,
Charlie

IMAGE_171.jpg
IMAGE_171.jpg (84.36 KiB) Viewed 10331 times


Code: Select all Expand
streichre
 
Posts: 15
Joined: Tue Jan 11, 2011 7:19 pm

Re: 1.8" TFT Display to Baby-O with LSM303DLH Compass

Postby ryantm » Mon Feb 13, 2012 1:16 pm

Hello.

Cool project. Your display looks very nice. I have added your project to our list of community projects!

- Ryan
User avatar
ryantm
Pololu Employee
 
Posts: 1268
Joined: Mon May 19, 2008 1:00 pm
Location: Las Vegas, NV

Re: 1.8" TFT Display to Baby-O with LSM303DLH Compass

Postby streichre » Tue Feb 14, 2012 1:40 pm

Ryan,

Thanks for the posting to the community projects.

I am willing to answer any questions that anybody has. Has anyone else purchased one of these displays?
Just curious.

Charlie
streichre
 
Posts: 15
Joined: Tue Jan 11, 2011 7:19 pm

Re: 1.8" TFT Display to Baby-O with LSM303DLH Compass

Postby povray6 » Fri Dec 14, 2012 3:48 am

Hi charlie,

I have tried to the implement a similar compass graphics on mikromedia 3.5" display, once. Out of curiosity part of my question is , how did u get the compass needle to rotate to the degree that you wanted.and the other other part of my question is ,the needle of the compass when it moves ,say from positionX to positionX+1,how do u handle the deletion of the needle line at positionX.


thankx ,

Vikram
povray6
 
Posts: 3
Joined: Wed Dec 12, 2012 11:03 pm

Re: 1.8" TFT Display to Baby-O with LSM303DLH Compass

Postby streichre » Wed Feb 19, 2014 5:45 pm

OMG It has been a couple of years since I've been able to get back to check on things. So sorry that I didn't answer the previous question.

To answer the last question first... Just in case anyone was curious, I used to use a C++ XOR pen command to delete the old needle, but since the option doesn't exist for arduino code, I did a trick. I keep track of the current needle position and if the needle needs to move, I write the needle using the background color. In this case it was CREAM. In the function, drawNeedle, the first thing I do is to use the tft.drawLine command with the color CREAM which is the background on my compass display.

Code: Select all Expand


The first part of the question, "how did u get the compass needle to rotate to the degree that you wanted"

The folowing is from the code. I use these variables to calculate the needle position based upon the degree.

Code: Select all Expand


The getCompass function returns the degree. This is passed to the drawNeedle(degree) function. I then convert the degree to radians for the sin() function:
Code: Select all Expand


Here is the trick to calculating the needle (code from the program):
Code: Select all Expand


There is an IF statement for each quadrant of the circle because I need to determine the left and right endpoint for x_to and the up/down endpoint for y_to. So the command,

Code: Select all Expand


draws the needle using x and y as the center of the needle and "x+x_to" and "y+y_to" are the endpoints of the needle.

I hope this helps.

Charlie
Last edited by JonathanKosh on Thu Feb 20, 2014 8:47 am, edited 1 time in total.
Reason: Added code blocks.
streichre
 
Posts: 15
Joined: Tue Jan 11, 2011 7:19 pm

Re: 1.8" TFT Display to Baby-O with LSM303DLH Compass

Postby Derrill » Thu Feb 20, 2014 12:16 pm

Thank you for sharing your solution and updating this thread.

-Derrill
User avatar
Derrill
Pololu Employee
 
Posts: 438
Joined: Thu Jan 10, 2013 12:47 pm
Location: Las Vegas, NV


Return to A-Star and Orangutan Robot Controllers

Who is online

Users browsing this forum: No registered users and 0 guests