TV out doesn't use whole screen

Hi everyone,

I encountered a problem while I was programming a mock-up of a soon-to-be motorcycle LCD dashboard. I'm using a generic E-bay in-car dashboard mount TFT (lots of words), 4.3 inch with a composite connection. I hooked it up to my arduino duemilanove using the TV-out library. The screen works, and it displays what I want to BUT it doesn't use the whole screen. I attached a photo; the dots in the corners should be in the very corners of the screen, but as you can see, they aren't.

I've tested the program with another screen (a 3.5" car tft) and it did the same thing. I tested the screen with a raspberry pi and a TV receiver, and those did use the whole screen.

My question is: has anyone encountered this problem as well and/or does anyone know what's causing this (and, if at all possible, how to solve it)?
I've added my code as well.

#include <TM1638.h>
#include <TVout.h>
#include <fontALL.h>
#include "oili.h"
// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(3, 2, 4);


TVout TV;

int oil=0;
int neutral=0;
int speedd=0;
void setup() {
  // display a hexadecimal number and set the left 4 dots
   TV.begin(PAL,128,96);
  
}

void loop() {
  TV.clear_screen();
  TV.draw_circle(40,40,40,1);
  TV.draw_circle(100,20,15,1);
 TV.set_pixel(0,0,1);
 TV.set_pixel(127,0,1);
 TV.set_pixel(127,95,1);
 TV.set_pixel(0,95,1);
  if( module.getButtons() == 0b00000001) //links
  oil=!oil;
  if (module.getButtons() == 0b10000000) //rechts
  speedd++;
  if(oil==1)
  TV.bitmap(10,30,oili);
  
  TV.select_font(font8x8ext);
  TV.print(20,50,speedd);
  TV.select_font(font4x6);
  TV.print(50,46,"KMH");
  delay(50);
}

128x96 is a 4:3 ratio, so I suspect the timings are based on generating a 4:3 image. Your screen looks more like 16:9. Have you tried changing the horizontal resolution number from 128 to, say, 170? 170x96 is approximately 16:9. You are also initialising TVout with PAL timings. Is your screen PAL, or is it NTSC? You don't say where you are, or where the screen came from, so I can't tell.

Hi! Thanks for your reply. I'm in the Netherlands, so TV's PAL here. The box of the monitor said it was NTSC and PAL compatible; it was compatible with my PAL (I assume?) tv-receiver, so I used that value to initialise the screen.
You're right about the 4:3 ratio; 170*96 doesn't work however (no image), maybe too little memory?. I'll try it with a lower 16:9 resolution and report the results!

It looks like horizontal resolution has to be a multiple of 8, so you could try 168 or 176.

EDIT. Assuming TVout uses 1 bit per pixel, 168*96 needs 2016 bytes, so won't fit on a non-Mega Arduino.

Well, I tried a low 16:9 resolution on the duemilanove , but sadly to no avail. I then loaded the program onto a Mega 2560 and tried the resolutions you suggested, but those didn't work either. I'm not sure what the cause can be.. It's like the screen is active, but just starts drawing away from the edges.

Is there any way to adjust the horizontal/vertical size of the LCD (ie "stretch" the image)? Can you give us any more info on the LCD itself?

I was just about to post something along the lines of this, as I'm also using the TV out library (to overlay text and graphics data over a composite video signal), and the fact that the pixel data doesn't go all the way to the edge of the screen is very frustrating.

Firstly, this is nothing to do with incorrect PAL/NTSC settings. The TV out library correctly produces the analogue PAL/NTSC signal so that a TV can detect it and display it properly. The issue is that there is a blank border around the text/graphics that the library produces. This is something to do with where the frame buffer is positioned on the screen. If you use the member function

TVout::force_linestart(uint8_t time)

You can change the horizontal position of the generated image. This is because it changes the start time of a line with respect to the horizontal sync.

I don't think this is the way to solve the problem, but it's definitely something to do with when the pixel data is output.

So, now, examining video_properties.h reveals some parameters to play with (I've only put the PAL ones):

//Timing settings for PAL
#define _PAL_TIME_SCANLINE			64
#define _PAL_TIME_OUTPUT_START		12.5

#define _PAL_LINE_FRAME				312
#define _PAL_LINE_START_VSYNC		0
#define _PAL_LINE_STOP_VSYNC		7
#define _PAL_LINE_DISPLAY			260
#define _PAL_LINE_MID				((_PAL_LINE_FRAME - _PAL_LINE_DISPLAY)/2 + _PAL_LINE_DISPLAY/2)

#define _PAL_CYCLES_SCANLINE		((_PAL_TIME_SCANLINE * _CYCLES_PER_US) - 1)
#define _PAL_CYCLES_OUTPUT_START	((_PAL_TIME_OUTPUT_START * _CYCLES_PER_US) - 1)

_PAL_LINE_FRAME determines the number of lines per frame (i.e. the video signal frame), best not to touch that. However, _PAL_LINE_DISPLAY can be changed, setting this to 312 means that the generated display matches the video frame. For some reason this cuts off things at the top, so perhaps 300 would be better... Now I have a feeling that the horizontal position is defined by these two:

#define _PAL_TIME_SCANLINE 64
#define _PAL_TIME_OUTPUT_START 12.5

Will report back if I can get something to work...

Well, I tried editing the video_properties.h file. I read on some pages that PAL actually displays 288 lines per frame, so I changed the

#define _PAL_LINE_DISPLAY			260

to #define _PAL_LINE_DISPLAY 288 This helped somewhat, as it seemed to stretch the screen vertically, i.e. not crop it.

Then, I changed

#define _PAL_TIME_OUTPUT_START		12.5

to

#define _PAL_TIME_OUTPUT_START		9

which was basically just trial and error, and now my frame starts where it should, in the leftmost part of the display. It stretches almost to the right, i.e. allmost full screen, but I still can't see the upper boundary of my frame. I can't figure out why. Can any of you check these modifications and see what they do on your screens? Thanks!

/*
 Copyright (c) 2010 Myles Metzer

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the "Software"), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
*/

/*
 This File contains the timing definitions for the TVout AVR composite video
 generation Library
*/
#ifndef VIDEO_TIMING_H
#define	VIDEO_TIMING_H

#define _CYCLES_PER_US			(F_CPU / 1000000)

#define _TIME_HORZ_SYNC				4.7
#define _TIME_VIRT_SYNC				40
#define _TIME_ACTIVE				64
#define _CYCLES_VIRT_SYNC			((_TIME_VIRT_SYNC * _CYCLES_PER_US) -1 )
#define _CYCLES_HORZ_SYNC			((_TIME_HORZ_SYNC * _CYCLES_PER_US) - 1)

//Timing settings for NTSC
#define _NTSC_TIME_SCANLINE			63.55
#define _NTSC_TIME_OUTPUT_START		12

#define _NTSC_LINE_FRAME			262
#define _NTSC_LINE_START_VSYNC		0
#define _NTSC_LINE_STOP_VSYNC		3
#define _NTSC_LINE_DISPLAY			216
#define _NTSC_LINE_MID				((_NTSC_LINE_FRAME - _NTSC_LINE_DISPLAY)/2 + _NTSC_LINE_DISPLAY/2)

#define _NTSC_CYCLES_SCANLINE		((_NTSC_TIME_SCANLINE * _CYCLES_PER_US) - 1)
#define _NTSC_CYCLES_OUTPUT_START	((_NTSC_TIME_OUTPUT_START * _CYCLES_PER_US) - 1)

//Timing settings for PAL
#define _PAL_TIME_SCANLINE			64
#define _PAL_TIME_OUTPUT_START		9

#define _PAL_LINE_FRAME				312
#define _PAL_LINE_START_VSYNC		0
#define _PAL_LINE_STOP_VSYNC		7
#define _PAL_LINE_DISPLAY			288
#define _PAL_LINE_MID				((_PAL_LINE_FRAME - _PAL_LINE_DISPLAY)/2 + _PAL_LINE_DISPLAY/2 + 4)

#define _PAL_CYCLES_SCANLINE		((_PAL_TIME_SCANLINE * _CYCLES_PER_US) -1)
#define _PAL_CYCLES_OUTPUT_START	((_PAL_TIME_OUTPUT_START * _CYCLES_PER_US) -1 )

#endif

this is my video_properties.h

Any luck with fixing this?
I'm having the same exact problem. I've tried it on two different screens with no luck.

Hello. I have a few of these screens unused so don't really want to buy a nextion, have been searching on how to wire the screen upto Arduino but having no joy, could you please tell me how you connected this screen and do I need an adaptor
Kind regards