Artificial Horizon display using a gyro

Hello. I´m using arduino pro mini. I din´t make any changes to the code. I´m also using the sketch and LIB you suggeted.

I´ve wired this way:

sclk -13 mosi -11 cs - 9 dc - 8 rst - 7

The display module that I´m using is this one:

http://forum.arduino.cc/index.php?topic=125034.0

thanks

Run the sketch here.

What does it report?

What voltage are you running the pro mini on?

Have you used series resistors in the data/control lines?

Report:

TFT driver register values:

Register 0x01: 0x00 Register 0x04: 0x7C89F0 Register 0x09: 0x610000 Register 0x0A: 0x08 Register 0x0B: 0x00 Register 0x0C: 0x06 Register 0x0D: 0x00 Register 0x0E: 0x00 Register 0x0F: 0x00 Register 0x2E: 0x281400 Register 0xDA: 0x7C Register 0xDB: 0x89

Register 0xDC: 0xF0

Looks like driver chip is: ST7735 (empirical value)

I´m running on 5V and I didn´t use resistors in the data/control lines.

https://drive.google.com/file/d/0BzKrt8UWkNbRZFJqQlVKQ21GTlk/view?usp=sharing

In the link above, you can see the problem I´m having.

The display driver is not 5V tolerant. Put series resistors in the control and data lines as follows:

pro mini digital pin 7 through a 1K2 resistor to display RST pro mini digital pin 8 through a 1K2 resistor to display DC pro mini digital pin 9 through a 1K2 resistor to display CS pro mini digital pin 11 through a 1K2 resistor to display MOSI pro mini digital pin 13 through a 1K2 resistor to display SCLK

Did all that. Still presenting the same symptoms. Any other suggestions?

Which version of the Arduino IDE are you using?

Do other example sketches that come with the library work OK?

One problem is that your display shows random pixels on two edges, this is indicative of the wrong setup. Try different TAB_COLOUR options in User_Setup.h and find which one gets rid of those bad edge pixels. Edit the file, save, recompile and upload the sketch to try each option.

bodmer:
@Leonardoxms

Are you using the sketch attached to post #27?

What changes have you made?

Are you using this graphics library?

If so, do all the other example sketches work OK?

Which Arduino are you using?

How have you wired the display to your Arduino?

Hi!

I use your sketch from post #27 on Uno with ILI9341 2.8’’ 320x240 and have a similar problem with unwanted pixels. I have successfully changed resolution and orientation in the code, already tried different settings in User_Setup to get rid of them. Graphics test sketch running fine. Adafruit library render good image without any troubles, but really slow.

I hope you could help me. Thanks in advance!

@imolodkin

The redraw technique used works best on small displays but if you make the following changes to the post #27 sketch then it should fix your missing pixels. If it does not then post your sketch so I can run it and see what changes you have made.

Near the start of sketch change the line as follows:

#define HOR 400    // Horizon vector line length ### was 172

Then use this adapted drawHorizon() function:

// #########################################################################
// Draw the horizon with a new roll (angle in range -180 to +180)
// #########################################################################

void drawHorizon(int roll, int pitch)
{
  // Calculate coordinates for line start
  float sx = cos(roll * DEG2RAD);
  float sy = sin(roll * DEG2RAD);

  int16_t x0 = sx * HOR;
  int16_t y0 = sy * HOR;
  int16_t xd = 0;
  int16_t yd = 1;
  int16_t xdn  = 0;
  int16_t ydn = 0;

  if (roll > 45 && roll <  135) {
    xd = -1;
    yd =  0;
  }
  if (roll >=  135)             {
    xd =  0;
    yd = -1;
  }
  if (roll < -45 && roll > -135) {
    xd =  1;
    yd =  0;
  }
  if (roll <= -135)             {
    xd =  0;
    yd = -1;
  }

  if ((roll != last_roll) || (pitch != last_pitch))
  {
    xdn = 6 * xd;
    ydn = 6 * yd;
    tft.drawLine(XC - x0 - xdn, YC - y0 - ydn - pitch, XC + x0 - xdn, YC + y0 - ydn - pitch, SKY_BLUE);
    tft.drawLine(XC - x0 + xdn, YC - y0 + ydn - pitch, XC + x0 + xdn, YC + y0 + ydn - pitch, BROWN);
    xdn = 5 * xd;
    ydn = 5 * yd;
    tft.drawLine(XC - x0 - xdn, YC - y0 - ydn - pitch, XC + x0 - xdn, YC + y0 - ydn - pitch, SKY_BLUE);
    tft.drawLine(XC - x0 + xdn, YC - y0 + ydn - pitch, XC + x0 + xdn, YC + y0 + ydn - pitch, BROWN);
    xdn = 4 * xd;
    ydn = 4 * yd;
    tft.drawLine(XC - x0 - xdn, YC - y0 - ydn - pitch, XC + x0 - xdn, YC + y0 - ydn - pitch, SKY_BLUE);
    tft.drawLine(XC - x0 + xdn, YC - y0 + ydn - pitch, XC + x0 + xdn, YC + y0 + ydn - pitch, BROWN);
    
    xdn = 3 * xd;
    ydn = 3 * yd;
    tft.drawLine(XC - x0 - xdn, YC - y0 - ydn - pitch, XC + x0 - xdn, YC + y0 - ydn - pitch, SKY_BLUE);
    tft.drawLine(XC - x0 + xdn, YC - y0 + ydn - pitch, XC + x0 + xdn, YC + y0 + ydn - pitch, BROWN);
  }
  xdn = 2 * xd;
  ydn = 2 * yd;
  tft.drawLine(XC - x0 - xdn, YC - y0 - ydn - pitch, XC + x0 - xdn, YC + y0 - ydn - pitch, SKY_BLUE);
  tft.drawLine(XC - x0 + xdn, YC - y0 + ydn - pitch, XC + x0 + xdn, YC + y0 + ydn - pitch, BROWN);

  tft.drawLine(XC - x0 - xd, YC - y0 - yd - pitch, XC + x0 - xd, YC + y0 - yd - pitch, SKY_BLUE);
  tft.drawLine(XC - x0 + xd, YC - y0 + yd - pitch, XC + x0 + xd, YC + y0 + yd - pitch, BROWN);

  tft.drawLine(XC - x0, YC - y0 - pitch,   XC + x0, YC + y0 - pitch,   TFT_WHITE);

  last_roll = roll;
  last_pitch = pitch;

}

Since the larger display has ~ 4x the number of pixels to draw I would expect the code to run 4x slower than for a 160 x 128 display and thus the text/numbers will flicker when it is redrawn.

Your patch works perfectly, thank you!!! Speed is acceptable, no flickering.
But there are still random artifacts on the left and top sides. They were before my changes too, but only with this library. Do you have any suggestions?

@imolodkin

Post a copy of your sketch so I can run it and see what is happening.

@imolodkin

Missing pixels in lines is a problem encountered with the new 1.6.12 IDE, I have updated the ILI9341 library on Github to correct this.

@bodmer

I'm really sorry for the delay, didn't get any forum notifications.

I've updated the library and now it works great! Thank you so much for your support!

Hello
i test Demo

// Demo code for artifical horizon display
// Written by Bodmer for a 160 x 128 TFT display
// 15/8/16 GitHub - Bodmer/TFT_ST7735: Arduino graphics library for ST7735 displays with propotional fonts

#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define TFT_SCLK 13 // set these to be whatever pins you like!
#define TFT_MOSI 11 // set these to be whatever pins you like!

// #include <SPI.h>
// Use ONE of these three highly optimised libraries, comment out other two!
// For S6D02A1 based TFT displays
// #include <TFT_S6D02A1.h> // Bodmer’s graphics and font library for S6D02A1 driver chip
// TFT_S6D02A1 tft = TFT_S6D02A1(); // Invoke library, pins defined in User_Setup.h
// GitHub - Bodmer/TFT_S6D02A1: A fast Arduino TFT library for S6D02A1 based displays
// For ST7735 based TFT displays
// #include <TFT_ST7735.h> // Bodmer’s graphics and font library for ST7735 driver chip
// TFT_ST7735 tft = TFT_ST7735(); // Invoke library, pins defined in User_Setup.h
// GitHub - Bodmer/TFT_ST7735: Arduino graphics library for ST7735 displays with propotional fonts

// For ILI9341 based TFT displays (note sketch is currently setup for a 160 x 128 display)
//#include <TFT_ILI9341.h> // Bodmer’s graphics and font library for ILI9341 driver chip
//TFT_ILI9341 tft = TFT_ILI9341(); // Invoke library, pins defined in User_Setup.h
// GitHub - Bodmer/TFT_ILI9341: A fast Arduino IDE compatible graphics and fonts library including a driver for the ILI9341 based TFT displays.

Arduino Version 1.6.12

by Test

C:\Users\Heli\Desktop\Demo_artificial_horizon_7\Demo_artificial_horizon_9.ino:10:95: fatal error: TFT_S6D02A1.h: No such file or directory

#include <TFT_S6D02A1.h> // Bodmer’s graphics and font library for S6D02A1 driver chip

^

compilation terminated.

exit status 1
Fehler beim Kompilieren für das Board Arduino/Genuino Uno.

I am a beginner
And look for the error.
For many days

Thanks for any help

Trying to think of things which could slow down a lot of writes to an LCD, I see that you have quite a few pins in use, but ?no? mention of pullup resistors. Does the screen or adafruit recommend anything ? Your code looks as though it is going to presume 30k pullup built in, which might require comms to go slower than their best or be less reliable than ideal, especially if you have more than 6 inches of cabling from microcontroller to display. Various opinions abound about adding external pullup resistors from a digital pin to arduino Vcc, but I found 10kOhm or 3.3kOhm more likely to work than none at all and necessary when using a few feet of cables.

Hello, Was a copy error. There was wrong data in the file. For whatever reason. Thanks

Hello, hm work only with Arduino Duo i have Arduino Due ;o( But it is fine thx Ratlos

@olf5

As you are a beginner I would start by creating a simpler sketch! For example just draw a line though the centre of the screen at an angle that is output by the sensor. You will need to store the end coordinates of the last drawn line so you can erase it by over-writing with background before drawing the new line.

Hi there ... Does anyone here? I want to run this code for horizon indicator, any other updates? Hey guys, is this topic active?

Hello Bodmer:

I have been using your TFT eSPI library with a M5stack ESP32 320x240. Works quite well ! I was wondering - why not make a artificial horizon indicator using the sprites. The pitch scale and sky+earth image would be replotted as a sprite with the wings symbol static (along with other features). What do you think ?