KR2 ROV

What are you working on .... Show off your Rov's Projects here.
User avatar
KR2_Diving
Posts: 391
Joined: Aug 30th, 2012, 11:43 am
Location: Currently: NW Suburbs of Chicago. Originally: NE Wisconsin

Re: KR2 ROV

Post by KR2_Diving »

Video Selector Switch!

EDIT: Video Link Added below!

This is just a brief update... more details to follow!

Tonight I tried out (with a HIGH level of success <>< ) my onboard video selector switch. I plan on having 3 cameras onboard my ROV, and this little gadget will do the trick for selecting which one to show on my topside display.

I found this trinket on this site.

The RCCC v2 allows me to select one of 3 video feeds to display, as well as control a flash and the shutter on my GoPro.

The GoPro live feed, power, and shutter control are all controlled via the dock connector on the back. The same site had this cable preassembled and ready to go! I have not tested the shutter, but the power and live feed out work great!

I also tested my video quality when transmitted via my tether. My tether is approximately 75m of 1 core, twisted pair, shielded cable. It "fell of the back of a truck" and my buddy thought I might like it!

Here is the layout that I have. The image is not great...
System Configuration
System Configuration
videoSwitchSm.jpg (300.55 KiB) Viewed 13724 times
Here is a quick video.


The three cameras feed into the RCCC. The RCCC then feeds the selected video through the tether to my TV. Baluns are used throughout. I picked up a bag of them from Amazon for peanuts. [url]Here [/url] is the link.

The RCCC determines which feed to transmit based on the signal from the Arduino. The code is so simple!

Code: Select all

/*
Code by: KR2_DIVING (Ryan)

          )    O
         (   o . O
          )   () .
          /  O   o
       _.|._ o .()                    ***********************
      / _:_ \                         *****             *****
     |.(_ _).|                        *****     UNO     *****
     _\. : ./_                        *****   SURFACE   *****
    / |..:..| \                       *****             *****
   /_/ `---' \_\                      ***********************
   \_)        \_)
     \   T   /   
     _)__|__(_   
    /....|....\  
    """"" """""  
  ---KR2_DIVING---

I don't mind if you use this code for your own use.  I have made it freely available online.
However, please be sure to credit my work if you use it in the public domain.

Please direct any questions to: kr 2 diving (at) gmail (dot) com

Version  History     Mega
Version  Date        Match  Notes  
-------  ----------  -----  -----
  1.0    2014-08-14  v1.0   Test run of RCCC v2 Video Switch
*/

#include <Servo.h>

Servo VideoSwitch;


int PB = 2;
int PBState = 0;
int OldPBState = 0;

int V1 = 0;      //Servo Commanded position for Video Ch1
int V2 = 180;    //Servo Commanded position for Video Ch2
int V3 = 90;     //Servo Commanded position for Video Ch3

int cam = 0;              //Video in Channel. 0=CH1, 1=CH2, 2=CH3

void setup()
{
  Serial.begin(9600);
  pinMode(PB, INPUT);       // set button to be in input
  VideoSwitch.attach(9);    // attach RCCC CH1 to ArduinoPin 9
}

void loop()
{
  PBState = digitalRead(PB);
  
  if ((PBState == HIGH) && (OldPBState == LOW)) {++cam;} // increment feed based on button
  if (cam > 2) {cam=0;}
  if (cam == 0) {VideoSwitch.write(V1);}
  if (cam == 1) {VideoSwitch.write(V2);}
  if (cam == 2) {VideoSwitch.write(V3);}
  
  OldPBState = PBState;
  Serial.println(cam);
  delay(10);
}
This little gadget saved a load of time and money and SPACE in the hull of my ROV! A HUGE thanks to the guys at ReadyMadeRC!
User avatar
KR2_Diving
Posts: 391
Joined: Aug 30th, 2012, 11:43 am
Location: Currently: NW Suburbs of Chicago. Originally: NE Wisconsin

Re: KR2 ROV

Post by KR2_Diving »

FIRST MAJOR HICCUP:
Well, last night I thought I would hook up my OSD and test it... well.. that turned into a 5hr session of pulling my hair out and overall frustration... I cant for the life of me get the thing to work... I am beginning to think I might have a faulty unit...
Anyone else use the SparkFun OSD breakout board? (I am sure someone on this forum gave me the idea!)
SparkFun OSD Breakout Board
SparkFun OSD Breakout Board
OSD BOB.jpg (107.97 KiB) Viewed 13681 times
https://www.sparkfun.com/products/9168

I have managed to get my video to pass though it... but I cant get ANY characters to display on the screen... I've tried a number of libraries and sample codes... nothing. ANY thoughts? Anyone?

Ryan
"KR2_Diving"
kenl
Posts: 153
Joined: Oct 19th, 2013, 8:50 am
Location: South Western Australia

Re: KR2 ROV

Post by kenl »

I did get it working Ryan and as you have there was a lot of hair pulling.

I will see if I can dig up what I did, I can't seem to find it right now.

Try this Sketch to see if you have it wired up correctly

Code: Select all

[quote]
[color=#7E7E7E]/*[/color]

[color=#7E7E7E]  MAX7456 OSD Display Test Program for Arduino[/color]
[color=#7E7E7E]  [/color]
[color=#7E7E7E]  Hobbytronics.co.uk[/color]
[color=#7E7E7E]  [/color]
[color=#7E7E7E]  Nov-2013[/color]
[color=#7E7E7E]  [/color]
[color=#7E7E7E]  Setup is for PAL but NTSC settings are shown in the program.[/color]
[color=#7E7E7E]  Displays text on the screen in to following format (30 chars x 16 lines)[/color]
[color=#7E7E7E]  The program is completely self contained and requires no library files[/color]
[color=#7E7E7E]  [/color]
[color=#7E7E7E]  '------------------------------`[/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  | Hobbytronics.co.uk       OSD |[/color]
[color=#7E7E7E]  |                         Test |[/color]
[color=#7E7E7E]  |                              |  [/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  |                              | [/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  |                              | [/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  |                              |[/color]
[color=#7E7E7E]  | ####                00:00:00 |  <- Clock counts up from boot [/color]
[color=#7E7E7E]  |                              |  [/color]
[color=#7E7E7E]  '------------------------------`[/color]
[color=#7E7E7E]  [/color]
[color=#7E7E7E]*/[/color]

[color=#7E7E7E]// SPI pins[/color]
#define DATAOUT                   11 [color=#7E7E7E]//MOSI[/color]
#define DATAIN                    12 [color=#7E7E7E]//MISO [/color]
#define SPICLOCK                  13 [color=#7E7E7E]//sck[/color]
#define MAX7456SELECT             10 [color=#7E7E7E]//ss[/color]

[color=#7E7E7E]//MAX7456 opcodes[/color]
#define MAX_DMM_REG             0x04
#define MAX_DMAH_REG            0x05
#define MAX_DMAL_REG            0x06
#define MAX_DMDI_REG            0x07
#define MAX_VM0_REG             0x00
#define MAX_VM1_REG             0x01
#define MAX_CMAH_REG            0x09
#define MAX_CMM_REG             0x08

[color=#7E7E7E]//MAX7456 commands[/color]
#define MAX_CLEAR_DISPLAY       0x04
#define MAX_CLEAR_DISPLAY_VERT  0x06
#define MAX_END_STRING          0xFF

[color=#7E7E7E]// PAL[/color]
[color=#7E7E7E]// all VM0_reg commands need bit 6 set[/color]
#define MAX_ENABLE_DISPLAY      0x48
#define MAX_ENABLE_DISPLAY_VERT 0x4C
#define MAX_RESET               0x42
#define MAX_DISABLE_DISPLAY     0x40

#define MAX_SCREEN_SIZE          480
#define MAX_SCREEN_WIDTH          30
#define MAX_SCREEN_ROWS           16

[color=#7E7E7E]// NTSC[/color]
[color=#7E7E7E]//#define MAX_ENABLE_DISPLAY      0x08[/color]
[color=#7E7E7E]//#define MAX_ENABLE_DISPLAY_VERT 0x0C[/color]
[color=#7E7E7E]//#define MAX_RESET               0x02[/color]
[color=#7E7E7E]//#define MAX_DISABLE_DISPLAY     0x00[/color]
[color=#7E7E7E]//#define MAX_SCREEN_SIZE          390[/color]
[color=#7E7E7E]//#define MAX_SCREEN_WIDTH          30[/color]
[color=#7E7E7E]//#define MAX_SCREEN_ROWS           13[/color]

volatile [color=#CC6600]byte[/color] osd_buffer[MAX_SCREEN_SIZE+1];
volatile [color=#CC6600]byte[/color] osd_writeOK;

[color=#7E7E7E]// Variables for counting time and displaying bar[/color]
#define BAR_LENGTH                15
[color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] counter=0;
[color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] currentTime;
[color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] cloopTime;
[color=#CC6600]unsigned[/color] [color=#CC6600]long[/color] bloopTime;
[color=#CC6600]unsigned[/color] [color=#CC6600]char[/color] barsize=0;

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
  [color=#CC6600]byte[/color] spi_junk;
  [color=#CC6600]int[/color] x;

  [color=#CC6600]pinMode[/color](MAX7456SELECT,[color=#006699]OUTPUT[/color]);
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]HIGH[/color]); [color=#7E7E7E]//disable device[/color]

  [color=#CC6600]pinMode[/color](DATAOUT, [color=#006699]OUTPUT[/color]);
  [color=#CC6600]pinMode[/color](DATAIN, [color=#006699]INPUT[/color]);
  [color=#CC6600]pinMode[/color](SPICLOCK,[color=#006699]OUTPUT[/color]);

  [color=#7E7E7E]// SPCR = 01010000[/color]
  [color=#7E7E7E]//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,[/color]
  [color=#7E7E7E]//sample on leading edge of clk,system clock/4 rate (4 meg)[/color]
  SPCR = (1<<SPE)|(1<<MSTR);
  spi_junk=SPSR;
  spi_junk=SPDR;

  [color=#7E7E7E]// force soft reset on Max7456[/color]
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]LOW[/color]);
  spi_send_byte(MAX_VM0_REG, MAX_RESET);   
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]HIGH[/color]);
  
  [color=#CC6600]delay[/color](200);
  
  [color=#7E7E7E]// osd_create_block_char();  // Run this once only as data is stored in eeprom[/color]
  
  [color=#7E7E7E]// make sure the Max7456 is enabled[/color]
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]LOW[/color]);
  spi_send_byte(MAX_VM0_REG, MAX_ENABLE_DISPLAY);
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]HIGH[/color]);

  [color=#7E7E7E]// clear the data array[/color]
  [color=#CC6600]for[/color] (x = 0; x <= MAX_SCREEN_SIZE; x++)
  {
    osd_buffer[x] = 0x00;
  }

  osd_writeOK = [color=#CC6600]false[/color];
  
  [color=#7E7E7E]// Setup default data to display[/color]
  [color=#7E7E7E]// 30 chars x 16 lines for PAL[/color]
  [color=#7E7E7E]// Line 1 = bytes 1-30, Line2 = bytes 31-60 etc up to 480[/color]
  osd_print(2,2,[color=#006699]"Well Hi There"[/color]);
  osd_print(2,25,[color=#006699]"OSD"[/color]);  
  osd_print(3,24,[color=#006699]"Test"[/color]);
  
  currentTime = [color=#CC6600]millis[/color]();
  cloopTime = currentTime;  
  bloopTime = currentTime;  
  osd_writeOK = [color=#CC6600]true[/color];
  osd_clear_screen();
}

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
  [color=#CC6600]int[/color] i;
  [color=#CC6600]unsigned[/color] [color=#CC6600]char[/color] hours, mins, secs;
  
  currentTime = [color=#CC6600]millis[/color]();
    
  [color=#CC6600]if[/color](currentTime >= (cloopTime + 1000))
  {  
      [color=#7E7E7E]// This loop runs once a second and display the time [/color]
      [color=#7E7E7E]// in the bottom right corner[/color]
      [color=#7E7E7E]// Increment counter every second and display time since bootup[/color]
      cloopTime = currentTime;  [color=#7E7E7E]// Updates cloopTime       [/color]
      hours = counter / 3600;
      mins = (counter % 3600) / 60;
      secs = counter % 60;
      [color=#CC6600]char[/color] ascii_str[10];
      sprintf(ascii_str,[color=#006699]"%0.2d:%0.2d:%0.2d"[/color],hours,mins,secs);
      [color=#CC6600]for[/color](i=0;i<8;i++)
      {
         osd_buffer[440+i] = convert_ascii(ascii_str[i]);
      }   
      counter++;    
      [color=#7E7E7E]// Update line 15 only[/color]
      osd_write_line(15); 
  }
  
  [color=#CC6600]if[/color](currentTime >= (bloopTime + 200))
  {  
      [color=#7E7E7E]// This loop runs every 200mS and simply uses the block character[/color]
      [color=#7E7E7E]// we created to display a bar across the screen[/color]
      [color=#7E7E7E]// Increment bar display[/color]
      [color=#7E7E7E]// Bar displayed at line 15 col 2 = (14*30)+2[/color]
      bloopTime = currentTime;  [color=#7E7E7E]// Updates cloopTime      [/color]
      
      [color=#CC6600]for[/color](i=0;i<BAR_LENGTH;i++)
      {
         [color=#CC6600]if[/color](i<barsize) osd_buffer[(14*30)+2+i] = 0xC0;
         [color=#CC6600]else[/color] osd_buffer[(14*30)+2+i] = convert_ascii([color=#006699]' '[/color]);;
      }    
      barsize++;
      [color=#CC6600]if[/color](barsize>=BAR_LENGTH) barsize=0;
      [color=#7E7E7E]// Update line 15[/color]
      osd_write_line(15);
  }  
    
  [color=#CC6600]if[/color] (osd_writeOK)
  {
    [color=#7E7E7E]// if osd_writeOK is set then rewrite full screen[/color]
    osd_writeOK = [color=#CC6600]false[/color];
    osd_write_screen();
  }
      
}

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#7E7E7E]// Print a string to position row/col[/color]
[color=#7E7E7E]// Places the text into the correct location in the display buffer[/color]
[color=#CC6600]void[/color] osd_print([color=#CC6600]unsigned[/color] [color=#CC6600]int[/color] osd_line, [color=#CC6600]unsigned[/color] [color=#CC6600]int[/color] osd_col, [color=#CC6600]const[/color] [color=#CC6600]String[/color] &s){
    [color=#CC6600]for[/color] ([color=#CC6600]int[/color] i = 0; i < s.length(); i++) {
      osd_buffer[((osd_line-1)*MAX_SCREEN_WIDTH)+osd_col+i] = convert_ascii(([color=#CC6600]byte[/color]) s[i]);
    }  
} 

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]byte[/color] spi_send_byte([color=#CC6600]byte[/color] address, volatile [color=#CC6600]byte[/color] data)
{
  SPDR = address;                      [color=#7E7E7E]// Start the transmission[/color]
  [color=#CC6600]while[/color] (!(SPSR & (1<<SPIF))) {};   [color=#7E7E7E]// Wait the end of the transmission  [/color]
  SPDR = data;                      [color=#7E7E7E]// Start the transmission[/color]
  [color=#CC6600]while[/color] (!(SPSR & (1<<SPIF))) {};   [color=#7E7E7E]// Wait the end of the transmission[/color]
  [color=#CC6600]return[/color] SPDR;                      [color=#7E7E7E]// return the received byte[/color]
}

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]byte[/color] convert_ascii ([color=#CC6600]int[/color] character)
{
[color=#7E7E7E]// for some reason the MAX7456 does not follow ascii letter[/color]
[color=#7E7E7E]// placement, so you have to have this odd lookup table[/color]

  [color=#CC6600]byte[/color] lookup_char;

  [color=#CC6600]if[/color] (character == 32)
    lookup_char = 0x00; [color=#7E7E7E]// blank space[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 48)
    lookup_char = 0x0a; [color=#7E7E7E]// 0[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] ((character > 48) && (character < 58))
    lookup_char = (character - 48); [color=#7E7E7E]// 1-9[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] ((character > 64) && (character < 90))
    lookup_char = (character - 54); [color=#7E7E7E]// A-Z[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] ((character > 96) && (character < 123))
    lookup_char = (character - 60); [color=#7E7E7E]// a-z[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 34)
    lookup_char = 0x48; [color=#7E7E7E]// "[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 39)
    lookup_char = 0x46; [color=#7E7E7E]// '[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 40)
    lookup_char = 0x3f; [color=#7E7E7E]// ([/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 41)
    lookup_char = 0x40; [color=#7E7E7E]// )[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 44)
    lookup_char = 0x45; [color=#7E7E7E]// ,[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 45)
    lookup_char = 0x49; [color=#7E7E7E]// -[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 46)
    lookup_char = 0x41; [color=#7E7E7E]// .[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 47)
    lookup_char = 0x47; [color=#7E7E7E]// /[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 58)
    lookup_char = 0x44; [color=#7E7E7E]// :[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 59)
    lookup_char = 0x43; [color=#7E7E7E]// ;[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 60)
    lookup_char = 0x4a; [color=#7E7E7E]// <[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 62)
    lookup_char = 0x4b; [color=#7E7E7E]// >[/color]
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] (character == 63)
    lookup_char = 0x42; [color=#7E7E7E]// ?[/color]
  [color=#CC6600]else[/color]
    lookup_char = 0x00; [color=#7E7E7E]// out of range, blank space[/color]

 [color=#CC6600]return[/color] (lookup_char);

}

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]void[/color] osd_create_block_char()
{
  [color=#7E7E7E]// Create a solid White block char at character location 0xC0[/color]
  [color=#7E7E7E]// This function only need to be called once as the character[/color]
  [color=#7E7E7E]// is stored in the MAX7456 eeprom[/color]
  [color=#7E7E7E]// Check out https://sites.google.com/site/qeewiki/projects/q-s-max7456-img-gen/QMIG_v1.10.rar?attredirects=0[/color]
  [color=#7E7E7E]// for a free character creation tool for the MAX7456[/color]
  [color=#CC6600]unsigned[/color] [color=#CC6600]char[/color] i;
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]LOW[/color]);
  [color=#7E7E7E]//  disable display  [/color]
  spi_send_byte(MAX_VM0_REG, MAX_DISABLE_DISPLAY);
  [color=#7E7E7E]// Create Character at 0xC0 - See MAX7456 datasheet for character locations[/color]
  spi_send_byte(MAX_CMAH_REG, 0xC0);   [color=#7E7E7E]// Write to address 0xC0[/color]
  
  [color=#7E7E7E]// We need to send 54 bytes of data to store the character. Our 'block' character[/color]
  [color=#7E7E7E]// is all the same, so we can loop here[/color]
  [color=#CC6600]for[/color](i=0;i<54;i++)
  {
    spi_send_byte(0x0A, i);
    spi_send_byte(0x0B, 0b10101010);
  }  

  spi_send_byte(MAX_CMM_REG,0xA0);

  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]HIGH[/color]);
  [color=#CC6600]delay[/color](200);
}

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]void[/color] osd_clear_screen()
{
  [color=#7E7E7E]// clear the screen[/color]
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]LOW[/color]);
  spi_send_byte(MAX_DMM_REG,MAX_CLEAR_DISPLAY);
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]HIGH[/color]);
}

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]void[/color] osd_write_line([color=#CC6600]unsigned[/color] [color=#CC6600]int[/color] linenum)
{
  [color=#7E7E7E]// Instead of redrawing the whole screen, we may only need to [/color]
  [color=#7E7E7E]// change one or more lines. [/color]
  [color=#CC6600]unsigned[/color] [color=#CC6600]int[/color] x, local_count, start_address;
  [color=#CC6600]byte[/color] char_address_hi, char_address_lo;
  [color=#CC6600]byte[/color] osd_char;
  
  local_count = MAX_SCREEN_WIDTH;
  start_address = (linenum-1) * MAX_SCREEN_WIDTH;
  
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]LOW[/color]);

  spi_send_byte(MAX_DMM_REG,0x01);   [color=#7E7E7E]//16 bit trans w/o background[/color]
  spi_send_byte(MAX_DMAH_REG,([color=#CC6600]unsigned[/color] [color=#CC6600]char[/color])(start_address>>8));  [color=#7E7E7E]// set start address high[/color]
  spi_send_byte(MAX_DMAL_REG,([color=#CC6600]unsigned[/color] [color=#CC6600]char[/color])(start_address));  [color=#7E7E7E]// set start address low[/color]

  x = 0;
  [color=#CC6600]while[/color](local_count) [color=#7E7E7E]// write out full screen[/color]
  {
    osd_char = osd_buffer[((linenum-1)*MAX_SCREEN_WIDTH)+x];
    spi_send_byte(MAX_DMDI_REG,osd_char);
    x++;
    local_count--;
  }

  spi_send_byte(MAX_DMDI_REG,MAX_END_STRING);

  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]HIGH[/color]);
}

[color=#7E7E7E]//////////////////////////////////////////////////////////////[/color]
[color=#CC6600]void[/color] osd_write_screen()
{
  [color=#7E7E7E]// Change the data for the whole screen[/color]
  [color=#CC6600]int[/color] x, local_count;
  [color=#CC6600]byte[/color] char_address_hi, char_address_lo;
  [color=#CC6600]byte[/color] osd_char;
  
  local_count = MAX_SCREEN_SIZE;
  
  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]LOW[/color]);

  spi_send_byte(MAX_DMM_REG,0x01);   [color=#7E7E7E]//16 bit trans w/o background[/color]
  spi_send_byte(MAX_DMAH_REG,0x00);  [color=#7E7E7E]// set start address high[/color]
  spi_send_byte(MAX_DMAL_REG,0x00);  [color=#7E7E7E]// set start address low[/color]

  x = 0;
  [color=#CC6600]while[/color](local_count) [color=#7E7E7E]// write out full screen[/color]
  {
    osd_char = osd_buffer[x];
    spi_send_byte(MAX_DMDI_REG,osd_char);
    x++;
    local_count--;
  }

  spi_send_byte(MAX_DMDI_REG,MAX_END_STRING);

  [color=#CC6600]digitalWrite[/color](MAX7456SELECT,[color=#006699]HIGH[/color]);
}

[/quote]
kenl
Posts: 153
Joined: Oct 19th, 2013, 8:50 am
Location: South Western Australia

Re: KR2 ROV

Post by kenl »

I've been a bit distracted lately so I'm trying to remember what I did here, the following picture shows how I connected it up.
arduino7456.gif
arduino7456.gif (63.25 KiB) Viewed 13657 times
The following are extracts from my code, I have commented them out at the moment because I don't have a spare breakout to use on my test bench and it was causing problems without it being there.

Code: Select all

#include <Servo.h>
#include <Wire.h>
#include <CMPS10.h>
#include <SPI.h>
//#include <MAX7456.h>
CMPS10 compass;
#include <EasyTransfer.h>
EasyTransfer ETin,ETout;


// Pin Mapping /////////////////////////////////////////////////////////////////
// const byte osdChipSelect             =   10;
// const byte masterOutSlaveIn          =   11;
//const byte masterInSlaveOut          =   12;
//const byte slaveClock                =   13;
//const byte osdReset                  =    0;

Code: Select all

//MAX7456 OSD( osdChipSelect );
void setup()
{


  //SPI.begin();
  //SPI.setClockDivider( SPI_CLOCK_DIV2 );      
  //OSD.begin();
  //OSD.display();
  //OSD.setDefaultSystem(MAX7456_PAL);
  //OSD.clear();

Code: Select all

 //OSD.setCursor(0,0);                        
  // OSD.print( depthM/10 );
  // OSD.print( "M" );
  // OSD.setCursor(10,0);                        
  // OSD.print( heading );

  // OSD.setCursor(18,0);                        
  // OSD.print( voltage2*3.125);
  //OSD.print("Bv");



  //OSD.setCursor(18,1);                        
  //OSD.print( Tvolt2*3.125);
  //OSD.print("Tv");

  if (leakState == HIGH) // if it is, the leakState is HIGH:
  {     
    dataUp.leak=1 ;
    //OSD.setCursor(7,8);                        
    //OSD.print( "LEAK" );
  } 
  else
  {
    dataUp.leak=0;
    //OSD.clear();     // new test to see if it clears screen after leak pin is dried
  }
My coding skills are very poor but the above finally got me going so I hope that in some way it may help you, another thing I had to do was to delete all the various libraries I had tried and start again. I think there are about 3 core libraries for this max7456 and if you have a go at using them all it seems to mess stuff up. I ended up going with the one recommended by Sparkfun.
User avatar
zotta
Posts: 14
Joined: Jul 22nd, 2013, 12:41 pm
Location: Palermo Italy

Re: KR2 ROV

Post by zotta »

Rayan've corrected the code from bugs. I'll wait.
My cries rov want to go to sea.

Ciao

Zotta
User avatar
KR2_Diving
Posts: 391
Joined: Aug 30th, 2012, 11:43 am
Location: Currently: NW Suburbs of Chicago. Originally: NE Wisconsin

Re: KR2 ROV

Post by KR2_Diving »

Hey kenl,
Thanks for the tips! I see you wired the unused pins of the OSD unit to to +5V... Interesting as you are the first to show that... hmmm....

I will try all this on Sunday when I have a chance to get back to it... I will let you know what I come up with!

P.S. Your coding skills look good to me, there are comments!!

Ryan
"KR2_Diving"
kenl
Posts: 153
Joined: Oct 19th, 2013, 8:50 am
Location: South Western Australia

Re: KR2 ROV

Post by kenl »

hey Ryan,

I had help from RoarRoar here on the forum, if you check his build thread you will see on pages 3 & 4 our discussion and his results, a truly impressive machine he has built.

Also try a separate/additional power supply for the OSD, it seems to need more than the Arduino can comfortably supply.

Ken
User avatar
KR2_Diving
Posts: 391
Joined: Aug 30th, 2012, 11:43 am
Location: Currently: NW Suburbs of Chicago. Originally: NE Wisconsin

Re: KR2 ROV

Post by KR2_Diving »

kenl wrote:I had help from RoarRoar here on the forum, if you check his build thread you will see on pages 3 & 4 our discussion and his results, a truly impressive machine he has built.
Also try a separate/additional power supply for the OSD, it seems to need more than the Arduino can comfortably supply.
Sadly... nope... not even this worked... I got "Hello World" to show once... no idea how... I was fiddling with something... looked up... it was there... tried again... nothing...

Is there any chance that modern TV's would detect the OSD data as "noise" and try to filter it out?
User avatar
KR2_Diving
Posts: 391
Joined: Aug 30th, 2012, 11:43 am
Location: Currently: NW Suburbs of Chicago. Originally: NE Wisconsin

Re: KR2 ROV

Post by KR2_Diving »

GREAT NEWS!
Finally got an OSD to work!!!
Hello World!
Hello World!
OSD HelloWorld.jpg (321.02 KiB) Viewed 13447 times
I scrapped the one I got from SparkFun and went with the MAX7456 OSD breakout board from HobbyTronics in the UK.
MAX7456 all wired up.
MAX7456 all wired up.
MAX7456 OSD.jpg (469.93 KiB) Viewed 13447 times
(I use to live in the UK and these guys are great!! Highly recommend for anyone living in the EU! I still order from them occasionally, even though I am now in the States.)

I used the same code I used on the SparkFun OSD, and the HobbyTronics OSD worked right away! No issues... no fumbling... no guessing... just worked!

Code: Select all

/*
  HelloWorld.ino
   Demonstrates most simple use of the MAX7456 Library.
    This example code is in the public domain.
    Requires Arduino 1.0 or later.
    History :
      1.0 ~ Creation of HelloWorld from MAX7456Demo 0.4
            2013.01.301 - F. Robert Honeyman <www.coldcoredesign.com>
*/
// Included Libraries //////////////////////////////////////////////////////////

  #include <SPI.h>
  #include <MAX7456.h>

// Pin Mapping /////////////////////////////////////////////////////////////////
  
  // pinValue = 0 means "not connected"

  //  FDTI Basic 5V                   ---  Arduino  VCC      (AVCC,VCC)
  //  FDTI Basic GND                  ---  Arduino  GND      (AGND,GND)
  //  FDTI Basic CTS                  ---  Arduino  GND      (AGND,GND)
  //  FDTI Basic DTR                  ---  Arduino  GRN
  //  FDTI Basic TXO                  ---> Arduino  TXO [PD0](RXD)
  //  FDTI Basic RXI                 <---  Arduino  RXI [PD1](TXD)
  
  //  Max7456 +5V   [DVDD,AVDD,PVDD]  ---  Arduino  VCC      (AVCC,VCC)
  //  Max7456 GND   [DGND,AGND,PGND]  ---  Arduino  GND      (AGND,GND)
  //  Max7456 CS    [~CS]            <---  Arduino  10  [PB2](SS/OC1B)
  //  Max7456 CS    [~CS]            <---  Mega2560 43  [PL6]
  const byte osdChipSelect             =            10;
  //  Max7456 DIN   [SDIN]           <---  Arduino  11  [PB3](MOSI/OC2)
  //  Max7456 DIN   [SDIN]           <---  Mega2560 51  [PB2](MOSI)
  const byte masterOutSlaveIn          =                      MOSI;
  //  Max7456 DOUT  [SDOUT]           ---> Arduino  12  [PB4](MISO)
  //  Max7456 DOUT  [SDOUT]           ---> Mega2560 50  [PB3](MISO)
  const byte masterInSlaveOut          =                      MISO;
  //  Max7456 SCK   [SCLK]           <---  Arduino  13  [PB5](SCK)
  //  Max7456 SCK   [SCLK]           <---  Mega2560 52  [PB1](SCK)
  const byte slaveClock                =                      SCK;
  //  Max7456 RST   [~RESET]          ---  Arduino  RST      (RESET)
  const byte osdReset                  =            0;
  //  Max7456 VSYNC [~VSYNC]          -X-
  //  Max7456 HSYNC [~HSYNC]          -X-
  //  Max7456 LOS   [LOS]             -X-

// Global Constants ////////////////////////////////////////////////////////////

  const unsigned long debugBaud = 9600;         // Initial serial baud rate for 
                                                //   Debug PC interface

// Global Variables ////////////////////////////////////////////////////////////
  
  HardwareSerial Debug = Serial;                // Set debug connection
  
  MAX7456 OSD( osdChipSelect );

// Hardware Setup //////////////////////////////////////////////////////////////

  void setup() 
  {
    
    // Initialize the Serial connection to the debug computer:
    Debug.begin( debugBaud );
    
    
    // Initialize the SPI connection:
    SPI.begin();
    SPI.setClockDivider( SPI_CLOCK_DIV2 );      // Must be less than 10MHz.
    
    // Initialize the MAX7456 OSD:
    OSD.begin();                                // Use NTSC with default area.
    //OSD.setCharEncoding( MAX7456_ASCII );       // Only needed if ascii font.
    OSD.display();                              // Activate the text display.
    
  }
  // setup()

// Main Code ///////////////////////////////////////////////////////////////////

  void loop() 
  {
    
    while (OSD.notInVSync());                   // Wait for VSync to start to 
                                                //   prevent write artifacts.
    OSD.print( "Hello World!" );                // The '!' will not display
                                                //   because it does not come 
                                                //   in the factory font.
    while (true);
    
  } 
  // loop()
I have put more info into a thread in the CAMERA section of the Forum.

Now... time to play with it to get it to do what I want it to do...
Tal
Posts: 47
Joined: Feb 7th, 2013, 8:10 pm

Re: KR2 ROV

Post by Tal »

Wow, Great to see you back Ryan! :) You've definately motivated me to drag out my unfinished project and continue!
Post Reply