MAX7456 library update

hello

first thank you alot kg4wsv and dfraser and zitron for putting up this code and libraries, this saved me.

i'm having the same kind of problems than you btmcmahan, exept that i still don't have any characters displayed. i've managed to burn a new ascii table( i was thinking that would be the most difficult) i'm using an arduino mini with the atmel328, the max7456 board from sparkfun , already read every thread about it( arduino cc forum and sparkfun forums) my wirings are:
arduino==== max7456
pin10 ====cs
pin11====dout
pin12====din
pin13====sck
pin2====vsync
+5v to +5v and gnd to gnd i've tried rst to +5v with a resistor and without
i'm using the last libraries that you kg4wsv have posted here, the sketch that you have posted here, i've included the line for the pal mode and corrected the first line as i've a new ascii table.
i have no input
and the problem is my display is still black, flashing white every second( almost) and flashing blue every 10secs or so cause my tv is a kind of hightech thing and tries to understand the signal( normally she can switch on the right entry and to the right signal type(ntsc /pal/secam)
so i've opened up the lib and as i'm pretty new to c++ i was wondering what was the " #if ARDUINO > 22" at the begining? where did you specify the pin n° for the arduino it seems that it's in an integrer but i can't found it...? and in the comments of the sketch you speak about the 8mhz of the arduino, mine is 16mhz do this can cause problems for communication with the max7456? and how can i write something in the middle of the screen? i think maybe the writings are some kind of "off the screen" cause it's doing the same when my computer tries to send a signal with a wrong frequency/resolution.

i know there is a lot of questions and please excuse my bad english.
i hope thoses questions can lead to the solution.

Here is a link to the code I posted previously.

Here is the schematic:

This might be a bit confusing because it's not a true arduino; it's a complete arduino-compatible solution. You can ignore the part about an 8MHz clock; that's just my notes on which hardware matches the sketch. It does not matter at all from the MAX7456 standpoint.

This is a schematic for a shield I designed and built:

This one shows arduino pin numbers. The jumpers on pins 4 - 10 allow me to select a different digital output as slave select, so that the shield is compatible with other SPI shields.

what was the " #if ARDUINO > 22" at the begining?

The structure of the arduino code internals changed at version 22; this preprocessor directive allows the library to be compatible with both old and new versions of the arduino system, without you even knowing that it happens. (I mention it because you ask, but you don't have to care about this if the code compiles.)

where did you specify the pin no for the arduino it seems that it's in an integrer but i can't found it...?

It's in the library near the top of MAX7456.h. The arduino pin numbers for lines other than slave select are hard coded in the library to the ATmegaxx8 family SPI pins. Note that the slave select here is a default, and VSYNC is not used. Here is the pertinent code:

#define MAX7456_DATAOUT 11//MOSI
#define MAX7456_DATAIN  12//MISO
#define MAX7456_SCK  13//sck
#define MAX7456SELECT 10//ss
#define MAX7456_VSYNC 2// INT0

Let me emphasize that I have no idea if my PAL support code is correct - I haven't heard from anyone that has used it successfully, and I have no way to test it.

If your TV is super-smart about mode matching, try it with NTSC mode. Even if you live in a PAL part of the world, many of the TV manufacturers find it easier to design a unit that supports both NTSC and PAL, rather than designing (and manufacturing and distributing and supporting...) two different TVs that are identical except for PAL vs. NTSC, so your TV may accept NTSC.

As for "off the screen", I'd print 15 or 20 lines (long lines, like 20 or 25 characters) to make sure the screen was full.

-j

thank you alot! its working now! i don't really know what was wrong, i've re-wired everything, re-uploaded the sketch , changed the video cable and changed the tv, and now everything is ok( exept that apparently the new character table was not burned on the max7456.... dunno, gonna try again....) so a really big thank you!
it's alive! it's allliiiiiiiveeeeee!!!!!

Hey guys, I got the osd working on my Mega. But one thing I still don't get, why does print() and println() work when neither one is defined in the H file or cpp file? How does that work?

Thanks for the help.

why does print() and println() work when neither one is defined in the H file or cpp file?

It's the magic of C++ inheritance. I define a write() function that accepts a single byte to be displayed, then inherit all the nifty functions in the Print class with

class MAX7456 : public Print

All I have to do for the 7456 is keep up with where the cursor is, and displaying the bytes that get sent to write(). Converting ints and floats and strings to a sequence of printable ASCII characters is magically (from my point of view) done by Print.

-j

Okay, I have some updates to the library if anyone wants to check it out. First, it now works with both Mega and Uno! Just select the correct board in Arduino IDE, and it's gonna work!

The font upload program works with Mega & Uno (or deci)

Next, I changed some stuff:

blink() & no_blink(), invert() & no_invert() to
osd.blink_on & osd.blink_off
osd.invert_on() & osd.invert_off()
osd.write_to_screen() is now osd.print_full_screen("characters",x,y,blink,invert,char_bg)

Also, I added:
char_bg_on() and **char_bg_off()**for individual character backgrounds.
osd.cursor(x,y) and
osd.cursor(x,y,blink,invert,char_bg)
this will look like:osd.cursor(5,2,1,0,1) and gives you column 5, row 2, blink on, invert off, and character background on.

Here's the big additions:

osd.set_vm1(blink_duty, blink_time, gray_lvl, bg_mode
this function sets your video mode 1 options (see max7456 datasheet)
you can use this function anytime, in the setup or during the loop.
It looks like this: osd.vm1_set(75,3,7,0)
the blink_duty can be set to 25, 33, 50, or 75. This would be for the blink "on time"... like (33% on & 66% off).
the blink_time can be set from 0 to 3, where 0 blinks the fastest, and 3 blinks the slowest.
the gray_lvl can be set from 0 to 7, where 0 is the darkest (black) and 7 is the lightest (very light gray).
the bg_mode can be set at 0 or 1, where 0 gives you the video_in background, and 1 gives you gray background.

osd.set_screen(x_min, x_max, y_min, y_max, x_offset, y_offset)
this function lets you adjust the area to accommodate your screen.
it looks like this: osd.set_screen(1,28,2,11,-5,-8)
x_min & x_max let you set your first & last viewable column, y_min & y_max set your first & last viewable rows.
x can be 0 to 29, and y can be 0 to 12. I don't have a PAL tv, but I assume y could be 0 to 15 if needed.
**in my example, column 1 becomes column 0, and row 2 becomes row 0...
**so if you use cursor(0,0) you will actually write to column 1 and row 2.
**this way you don't have to over-think the locations, just set your screen and everything else works okay with it
x_offset lets you shift your screen left & right, -32 for 32 pixels left, 0 for no shift, and 31 for 31 pixels right.
y_offset lets you shift your screen up & down. -16 for 16 pixels up, 0 for no shift, and 15 for 15 pixels down.
like my other functions, this can be used anywhere in your sketch.
the osd.print_full_screen () function is the only function this is not limited to your defined screen area.

osd.set_white_level(row,white_level)
this function lets you change the white level brightness on any row.
you can set any row, and the white_level can be 0 to 3, with 0 being brightest white, and 3 being dullest white.
it looks like this: osd.set_white_level (2,3) to set row 2 to the dullest white,
OR osd.set_white_level(all_rows,0) to set all rows to the brightest white.

last, osd.put**(hex, x,y,blink,invert, char_bg)**
OR osd.put(hex,x,y)
these functions let you print a hex character with the normal options
it looks like osd.put(0x8F,3,6,0,1,0)

osd.PALmode ( ) can be used if you have a PAL display. You may have to use osd.set_screen ( ) to change the number of rows from (13 on NTSC) to (15 on PAL). The code will default to a NTSC setup.

I think that's everything that needs explaining. I just expanded on work done by Please let me know what you think, but be gently, this is my first library upload!

Thanks to dfraser, zitron, and kg4wsv. I'm really just expanding on work they did first.

P.S. If your video goes in and out, try uploading a new font. That magically solved my problem. Don't know why, don't care.

I'am a new one and my first post is for you : What a great job !!!!!
Just a question in your last release the PAL mode is missing. Can you indicate what I need to modfied ?

Thanks a lot

actually i have the same problem, great job btmcmahan but adding the palmode( i've tried copy/paste in the cpp file, i guess this was a stupid idea^^) isee how you print a character with its hex adress " 0x**" thanks to your demo sketch, but how to do the same with the lib of kg4wsv?
i have a small issue with my screen, i have some empty space on the bottom, the video is really full screen but it's seems that it's missing two lines, they are wrapping on top of the screen, over the first lines. any idea? is there a way to " offset" the display?
i'm trying to make a HUD, with a reticle in the center, and some displays on the sides, i've done a new char set,and put it successfully on the chip. any hint on how to display these? some sort of general idea to put everything together( i' was thinking to put some variables on strings to display different icons but thre is maybe a better way to go...)
anyway lot of thanks, iwould never been able to go so far without your work.

yes, you can set the amount of rows displayed with the osd.set_screen( ) function, and you can also do the offset with this function. But if your rows are wrapping around to the top, I would suggest using set_screen to remove. 12th and 13th rows. As for the PAL, if someone wants to post the old code I will integrate it into my cpp and h file. I don't have any versions with PAL support to look at.

thanks i will try this today, i'm wondering if it's not the fault to my screen( a cheap 4" tft screen from hk) and i've read that pal has a row less than ntsc.
the lib with the pal code is on the reply #11 of kg4wsv on this thread. there is a few lines on the begining of the .cpp concerning the pal code but i've never done a lib so there may be something elsewere.
i haven't checked but have you left the boolean to use the original and modified ascii .mcm? this can be useful too.

Okay, I added PALmode( )....someone please let me know if it works, I have no way of testing it!

Plasmawall : PAL mode should allow you to write 15 rows (instead of 13 for NTSC) But did you have any luck with the
set_screen ( ) feature?

I'm re-posting a link to the Max font editing program.

Also, I found this terminal program very helpful for transmitting my new font files to the arduino. I had to use the XonXoff setting.
http://www.hyperserialport.com/

And here is a good starting ASCII font file, I think dfraser made it, it was on the old forum. There's plenty of open characters so you can start building your own.

My setup never worked correctly until I uploaded the ASCII font.

wondefull!

i'm gonna try pal mode right now! i will let you know in few hours if everything is ok.

anyway my ccd cam ouputs only pal but without input, ntsc works really fine so i think my screen is in bad mood with pal ( religion related i think^^).

i've managed to get a sketch to burn a new font file and then i use teraterm for sending mcm files( very easy, open teraterm and file-> send file-> pick your mcm and here we go!) i can pm you the sketch if you want to.

on my side i'm using the software from remzibi( it was intented to program a osd for a drone) the f2 let you use a great font editor with nice features like miroring characters, and you can see 2 characters at the same time, side to side without gap it's very useful to draw some icons or large letters wich takes 2 normal characters.

okay, everything works fine! pal mode is working 100% and the set screen size solved my problem. anyway in pal the osd has a lower resolution( not big difference but the outline of letters are flicking a little, making text not so readable( interlacing problem i think)
thank you so much btmcmahan
a last question, how( if possible) do you write a sentence with 0x** form? the fact is my font table is pretty big and i have to use some unpritable characters, i can use them with" osd.write(0xf1a);" but do i have to set the cursor and osd.write for every character or you, master of the code , have a solution to lighten my burden?

again thanks

you can use this:
osd.put(0xF4,5,7); will print the character to column 5 row 7
osd.write(0xF5); will print the character to the next position

So you only have to set the position once with osd.put () and then osd.write () for the other characters.
I'm happy to hear everything else is working good for you.

you made my day sir!

hello do you know how i could control two max7456? i know i should declare another slave select pin to send signal on the other max but how should i modify tour library? it's in order to drive a stereoscopic device so the most of characters are the same on both ic could duplicate your library with another name and another pin for SS and copypaste my code linking to the new lib like:

#include "MAX7456_osd.h"
MAX7456 osdright;
MAX7456 osdleft;
void loop(){
osdright.write(0x91);
osdleft.write(0x92);

but it's memory expensive and pretty slow to run. is there a better way?

thanks for any advice

Define "memory expensive" and "slow".

There are about 7 "byte" variables per instance, and it writes at an SPI rate of1/4 of the system clock.

At least that's how it is in my version of the code. Not sure about btmcmahan's version.

-j

my sketch is pretty large and on the way i'm seeing stereoscopy i've had to double it ( one part for the right and one part for the left camera) so basically it's going to take twice memory and twice time to execute( i'mworking with a mini arduino328) there is maybe a bit of superstition here but i think there is a better/smoother way ( and if i have to change something i don't want to do it twice on my sketch so i was looking to add a "side_byte" for "left" "right" and "both" to "void MAX7456::cursor(byte side,byte x, byte y, byte blink, byte invert, byte char_bg){" ( i've take cursor as an exemple but adding it to all functions and dependencies) right now it's not working.( i'm pretty new to c++ and arduino coding so i make a lot of mistakes and misunderstanding and it takes me times to really comprehend your work^^)

okay, I think this will do it. There was something similar in the kg4wsv-zitron-dfraser version, but I didn't know what it did so I took it out! Now I know what it did. This should allow you to use as many OSD's as you want, but I only have one, so you'll have to let me know if it is working correctly.

In your H FILE, insert this:

class MAX7456 : public Print
{
 public:
  MAX7456();
  void begin();
  void begin(int ss_pin);          //************INSERT THIS LINE
  void slave_select(int ss_pin);   //************INSERT THIS LINE
// Setup Funtions
  void PALmode();

In your CPP FILE, insert this (near the beginning):

MAX7456::MAX7456(){
  _slave_select = MAX7456SELECT;
  _char_attributes = 0x01;
  _cursor_x = CURSOR_X_MIN;
  _cursor_y = CURSOR_Y_MIN;}

void MAX7456::slave_select(int ss_pin){  //************INSERT THIS LINE
  _slave_select = ss_pin;                //************INSERT THIS LINE
  pinMode(_slave_select,OUTPUT);}        //************INSERT THIS LINE

void MAX7456::begin(int ss_pin){         //************INSERT THIS LINE
  _slave_select = ss_pin;                //************INSERT THIS LINE
  begin();}                              //************INSERT THIS LINE

void MAX7456::begin(){
  byte spi_data;
 // int x;

In your sketch, you will have to "begin" each osd device in the setup:

osd.begin (14);  // Where one osd has slave select on pin 14
osd.begin (18);  // Where another osd has slave select on pin 18

In your loop, you can switch between each osd like this:

osd.slave_select(14);
osd.println("Stuff for the left screen");

osd.slave_select(18);
osd.println("Stuff for the right screen");

yeah it works! i still haven't received my second max7456 but with one , switching between slave select pins and reseting the whole build i have 2 different displays.there is a slight problem,the PALmode() code isn't working on the second osd
the first one i'm using in my sketch is in pal but the second is set in ntsc.