Show Posts
Pages: [1] 2 3 ... 7
1  Products / Arduino Due / Re: VGA library - now with TV output on: March 10, 2014, 04:56:27 pm
I'm using Arduino IDE version 1.5.3.  After uploading the sketch, I disconnect the Arduino board from the computer entirely.  I have it connected to the TV via the RCA cable, and to the power outlet via the DC barrel jack.  I'm feeding it the picture data from a second Arduino over software serial.  So, the data comes in on Serial1 on the DUE.  Would using the second hardware serial port conflict with it somehow?

    The picture quality isn't an issue here.  I know what the resolution and color palette is, and am aware that the graphics will look somewhat old-school.  I did graphics programming in BASIC in 4 colors on an 8088 computer a long while back, and this is certainly better than that.  I can mess with the color palette once I get it to display any color at all.

2  Products / Arduino Due / Re: VGA library - now with TV output on: March 10, 2014, 02:38:19 pm
I uploaded the "DrawingTestNTSC" sketch provided with the library.  It also comes out black and white on both TVs.
3  Products / Arduino Due / Re: VGA library - now with TV output on: March 10, 2014, 02:14:20 pm
@Stimmer,
    I updated the circuit using the closest resistors I could find handy.  It didn't make much difference to the overall picture.  It's still just greyscale; no color whatsoever.

   I also tried to use a different TV in the house which is much newer (late '90s, early 2000s).  The picture stability was better, but the output was still black and white. 

    I'll try to get some digital pictures of my circuit and the TV output and post on here.

BKnight760
4  Products / Arduino Due / Re: VGA library - now with TV output on: March 10, 2014, 10:59:56 am
@Stimmer,
    I used the VGA mode to connect and display graphics in color on my PC monitor in the past.  That has worked great.  Recently I've been working with an older TV set (from the '80s) in NTSC mode.  I've gotten a stable picture to display on the TV, but I'm only getting monochrome there.  Is that intended?  From the README.txt file I gathered that the NTSC and PAL mode TV output would be color.

    If color is intended in NTSC mode, I need to determine why I'm not getting color.  It's possible that my resistor divider for the DAC is not correct.  I used the same resistors as I used for the computer VGA, which I thought would work, even if the colors weren't perfect.  I suppose that if my resistors were too small, I might be saturating the voltage all the time and turning the display white.

    The color data I'm sending is in RRRGGGBB format, but I noticed the pin-out in the README.txt for NTSC/PATL is only 6 pins.  Is there some discrepancy here?  Are we really only getting 6-bit color in NTSC / PAL?

Any info is much appreciated,
BKnight760
5  Products / Arduino Due / Any way to boost the read speed on the WiFi Shield? on: September 04, 2013, 08:20:09 pm
Hi all,
   Been doing work with the official Arduino WiFi Shield connected to my Due.  I've gotten it to work with the Due and IDE 1.5.3 after flashing the firmware on the shield, per the instructions on the WiFi playground page. 

   While my computer can send a large packet of data in a single burst, it seems that the read capabilities on the shield are severely limited.  Is the "client.read()" method the only way to read the incoming data?  That is horrible performance.  Is there no buffered read, or buffer copy or something?  There doesn't appear to be an externalized method to do this in the Library, but I'm wondering if I can modify the library to allow me to get direct access to the buffer and do it myself.

Thanks for any suggestions!
6  Products / Arduino Due / VGA library and WiFi library conflict? on: September 04, 2013, 07:47:47 pm
I've been using the VGA library for some graphics sketches I've been working with on the Due.  This has worked fine.

I decided I'd like to be able to control the VGA graphic display via WiFi.  I have a official Arduino WiFi shield that I've gotten working independently.  It took a bit of research in order to find out how to flash the firmware on the WiFi Shield to get it to work with IDE 1.5.3 and the Due, but it does work and transfers data back and forth across a socket connection.  I wrote a Java application to test it, and seems to work fine.

However, once I try to combine the VGA library and the Wifi Library into the same sketch, nothing seems to work.  No Serial output, no VGA output, no WiFi connection.  I assume there's either a DMA, SPI, or timer interrupt conflict.


This simple code does not work.  I'm not even accessing the WiFi or SPI libraries at all, but somehow just including them is causing the VGA library to quit working:

Code:
#include <WiFi.h>
#include <SPI.h>
#include <VGA.h>


void setup() {
  //Start the serial connection.
  Serial.begin(9600);

  //Start the VGA library at 320x240 resolution at 8-bit color.
  VGA.begin(320,240,VGA_COLOUR);
}//End setup


void loop() {

  //Fill the frame buffer.
  for (int y=0;y<240;y++)
  {
    for (int x=0;x<320;x++)
    {
      //Generate random color.
      byte color =random(255);

      //The serial calls make the VGA display very slow
      //but have this here to make sure it's working.
      Serial.print("(");
      Serial.print(x);
      Serial.print(",");
      Serial.print(y);
      Serial.print(") = ");
      Serial.println(color,HEX);

      //Draw the color on the screen.
      VGA.drawPixel(x,y,color);
    }  

  }


}//End loop

However, commenting out

Code:
#include <WiFi.h>

allows the VGA display to work correctly.

Any thoughts on what the conflict is here, or what could be done to work-around the problem?
7  Products / Arduino Due / Re: VGA library - now with TV output on: September 03, 2013, 03:33:43 pm
Stimmer,
   Is there a similar library for VGA input?  I want to convert a VGA signal from my computer to a composite RCA output to a TV.

   I figure the problem with this is the processor speed and not being able to both read the incoming signal and generate the outgoing signal quickly enough.  Is that the limiting factor here?

   I suppose I could write a PC application that would capture the screen and send it over serial to the Arduino and fill the frame buffer, and then simply have the Arduino generate the composite video signal.  That may be doable, as long as I can cram that much video data over serial quickly enough to get it to appear to be video instead of stop-motion.

   At 320x240 at 8-bit color, that'd be 76800 bytes of data for the frame buffer, at a baud rate of 115200 (bits per second) or 14400 Bytes/sec.  By my calculation, it'd take 5.3 seconds to transfer one frame, which is far too slow.

   I do have a wifi shield.  I wonder if I can get better throughput using that.  It looks like the wifi benchmarks are pretty good for throughput (can range from 0.7 Mbps to 3.4 Mbps reasonably).  Although, that won't overcome the memory constraint.

   From what I understand, the 480i (interlaced) TV format is equivalent to 640x480 resolution.  Does the fact that the TV format is interlaced mean that that the frame is actually half the size (half-line or every-other line)?  Or will I have to downsample my video to fit the memory of the microcontroller?
8  Products / Arduino Due / Re: VGA library - now with TV output on: May 06, 2013, 07:15:19 pm
Stimmer,
   Thanks for the advice.  Switched to

#define USE_SAM3X_DMAC 0

in the SDFat library, and everything works perfectly now.
9  Products / Arduino Due / Re: VGA library - now with TV output on: May 04, 2013, 09:54:44 am
Stimmer,

VGA Library:
stimmer-DueVGA-0.404-3-g86f6dc0

Color at 320x240

Adruino Pin
34, 35 --> Blue
36, 37, 38 --> Red
39, 40, 41 --> Green
42, 43 -->  Hsync / Vsync

I'm using the Arduino Wifi Shield (R2) with onboard SD Card reader.  I'm not actually using the Wifi functions at the moment.

SDFat Library:
SdFatBeta20130207
10  Products / Arduino Due / Re: VGA library - now with TV output on: May 02, 2013, 10:03:38 pm
Stimmer,
  I downloaded the library, but running into issues when also using the SDFat library to read my graphics off the SD Card.  Any thoughts why these libraries conflict?  Is there any potential for making them able to work together?  It was possible previously with the PWM version.

  I'd really like to use the VGA library because it's so convienient, but reading the graphics data off the SD card is absolutely needed (ie: I can't load the bitmap into the VGA library framebuffer without the SDFat library being initialized at the same time).  I was hoping to take advantage of the speed increases you mentioned before, as well as the image stabilization using the additional timer.

Thanks for any info you can provide.
11  Products / Arduino Due / Re: VGA output on: April 21, 2013, 07:52:05 pm
I reworked my code based off the REG_PWM version and am no longer having issues with the Serial connection.

My code is able to load a bitmap graphic off the SD card, read the bitmap and DIB headers and resize any image to the desired 2D-array size.  It has to down-sample from 24-bit color to 8-bit color, but still looks pretty good with only 256 color choices.

Currently, I'm loading a background image to fit the 320x240x8 framebuffer.

Then I load 2 smaller images to do some bit-blit.  I'm using images that are 24x32 pixels (also down-sized and down-sampled from larger images). 

Code:
void readBitmap(char* filePath, byte** pictureBuffer,int bufferWidth,int bufferHeight)
{

  SdFile myFile;
  boolean openedFile = myFile.open(filePath,O_RDWR);
  if (openedFile)
  {

    unsigned int FileSize=0;
    unsigned int Offset=0;


    Serial.print("Reading ");
    Serial.print(filePath);
    Serial.println(" bitmap header...");
    //Read Bitmap header
    for (int i=0;i<14;i++)
    {
      byte myByte=myFile.read();
      Serial.print("Byte ");
      Serial.print(i);
      Serial.print(": 0x");
      if (myByte<16)
      {
        //Pad with a leading zero, if needed.
        Serial.print("0");
      }
      Serial.println(myByte,HEX);

      //Bytes 2 through 5 are the file size
      if((i>=2) && (i<=5))
      {
        FileSize=FileSize+(((int)myByte)<<(8*(i-2)));
        Serial.print("FileSize: ");
        Serial.println(FileSize);
      }

      //Bytes 10 through 13 are the offset to the pixel data.
      if((i>=10) && (i<=14))
      {
        Offset=Offset+(((int)myByte)<<(8*(i-10)));
        Serial.print("Offset: ");
        Serial.println(Offset);
      }
    }

    Serial.print("Done reading ");
    Serial.print(filePath);
    Serial.println(" bitmap header.");


    Serial.print("Reading ");
    Serial.print(filePath);
    Serial.println(" DIB header...");

    unsigned int Width=0;
    unsigned int Height=0;
    unsigned int BitsPerPixel=0;
    //Read the DIB header
    for (int i=0;i<40;i++)
    {
      byte myByte=myFile.read();
      Serial.print("Byte ");
      Serial.print(i);
      Serial.print(": 0x");
      if (myByte<16)
      {
        //Pad with a leading zero, if needed.
        Serial.print("0");
      }
      Serial.println(myByte,HEX);


      //Bytes 4 through 7 are bitmap width in pixels
      if((i>=4) && (i<=7))
      {
        Width=Width+(((int)myByte)<<(8*(i-4)));
        Serial.print("Width: ");
        Serial.println(Width);
      }

      //Bytes 8 through 11 are bitmap height in pixels
      if((i>=8) && (i<=11))
      {
        Height=Height+(((int)myByte)<<(8*(i-8)));
        Serial.print("Height: ");
        Serial.println(Height);
      }

      //Bytes 14 through 15 are bitmap bits per pixel
      if((i>=14) && (i<=15))
      {
        BitsPerPixel=BitsPerPixel+(((int)myByte)<<(8*(i-14)));
        Serial.print("BitsPerPixel: ");
        Serial.println(BitsPerPixel);
      }


    }


    int BytesPerPixel=((FileSize-Offset)/Width)/Height;
    Serial.print("BytesPerPixel=");
    Serial.println(BytesPerPixel);


    Serial.print("Done reading ");
    Serial.print(filePath);
    Serial.println(" DIB header...");

    Serial.print("Loading ");
    Serial.print(filePath);
    Serial.println(" bitmap pixels...");
    myFile.seekSet(Offset+1);

    byte buf[Width*BytesPerPixel];

    for(int y=0;y<Height;y++)
    {
      //Serial.print("Loading Row: ");
      //Serial.print(y,DEC);
      //Serial.print(" / ");
      //Serial.println(Height,DEC);

      //Serial.print("Pointer to FB[y][0] = ");
      //Serial.println((int)&FrameBuffer[y][0],HEX);


      //Serial.print("Loading Pixel: ");
      //Serial.print(x,DEC);
      //Serial.print(" / ");
      //Serial.println(Width,DEC);


      //Read the entire row of pixels all at once.
      //This is a major performance upgrade.
      myFile.read(buf,sizeof(buf));

      //Convert the 3-bytes-per-pixel data into 1-byte-per-pixel format.
      for (int x=0;x<Width;x++){
        byte red=buf[x*3];
        byte green=buf[(x*3)+1];
        byte blue=buf[(x*3)+2];


        //Serial.print("Red = ");
        //Serial.println(red);

        byte redBits = (byte)map(red,0,255,0,7);
        //Serial.print("RedBits = ");
        //Serial.println(redBits);
        byte greenBits = (byte)map(green,0,255,0,7);
        byte blueBits = (byte)map(blue,0,255,0,3);

        pictureBuffer[(bufferHeight-1)-(int)(((double)y*(double)bufferHeight)/(double)Height)][(int)(((double)x*(double)bufferWidth)/(double)Width)]=(redBits<<5)+(greenBits<<2)+(blueBits);
      }

      //The Bitmap file format pads every row to a 4-byte (word)
      //boundary.  Calculate the padding, and skip it.
      int BytesInLastWord=((Width*BytesPerPixel)%4);
      int BytesOfPadding=0;
      if (BytesInLastWord>0)
      {
        BytesOfPadding=4-BytesInLastWord;
      }
      //Serial.print("Row should have ");
      //Serial.print(BytesOfPadding);
      //Serial.println(" bytes of padding.");

      for (int i=0;i<BytesOfPadding;i++)
      {
        //Skip the padding byte.
        myFile.read();
      }
    }
    myFile.close(); 

    /*
    for (int y=0;y<Height;y++)
     {
     for (int x=0;x<Width;x++)
     {
     if (FrameBuffer[y][x]<16)
     {
     //Pad the output with a leading zero.
     Serial.print("0");
     }
     Serial.print(FrameBuffer[y][x],HEX);
     Serial.print(",");
     }
     Serial.println();
     }
     */


  }
  else
  {
    Serial.print("Error opening file ");
    Serial.print(filePath);
    Serial.println(" for read.");
  }

  Serial.print("Done loading ");
  Serial.print(filePath);
  Serial.println(" bitmap pixels.");

}//End readBitmap method

I bit-blit the images using the following simple steps:

Code:
void loop(void) {

  if (millis()-starttime>100)
  {
    //Initialize our timer   
    starttime=millis();


    if (spriteDeployed==true)
    {
      //Erase the sprite by putting the background back.
      for (int y=0;y<32;y++)
      {
        for (int x=0;x<24;x++)
        {
          FrameBuffer[locationY+y][locationX+x]=background[y][x];
        }
      }
      spriteDeployed=false;
    }

    locationX=locationX+random(-5,6);
    if (locationX>320-24)
    {
      locationX=320-24;
    }
    if (locationX<0)
    {
      locationX=0;
    }

    locationY=locationY+random(-5,6);
    if (locationY>240-32)
    {
      locationY=240-32;
    }
    if (locationY<0)
    {
      locationY=0;
    }


    //Get the background for the new location
    for (int y=0;y<32;y++)
    {
      for (int x=0;x<24;x++)
      {
        background[y][x]=FrameBuffer[locationY+y][locationX+x];
      }
    }

    //Put Bit-Blit the sprite on the screen
    for (int y=0;y<32;y++)
    {
      for (int x=0;x<24;x++)
      {
        //The "And" (&=) operation allows for white background to be
        //transparent, and the black object to overwrite the background.
        FrameBuffer[locationY+y][locationX+x]&=Sprite[y][x];
       
        //The "Or" (|=) operation allows the whte background to remain
        //transparent, while overlaying the color object on the black area.
        FrameBuffer[locationY+y][locationX+x]|=SpriteMask[y][x];
      }
    }
    spriteDeployed=true;
  }

}//End loop

This all works, except there's a slight flicker to the display.  It's not bad, but bugs your eyes a little.  The pixels seem to shift slightly left and right as the screen refreshes.  It seems that the h-sync or v-sync timings must be off just slightly every once in a while.  Is that possible with the interrupts?  I'm trying to decide what to do to fix the image stability.  Any thoughts?
12  Products / Arduino Due / Re: VGA output on: January 23, 2013, 11:17:32 pm
I'm working on some code based off stimmer's modified code (320x240x8), but it seems that the Serial communication no longer works after setting up the timers.

In the setup() method, I started the Serial at 9600, and then did println() thoughout the setup() method, and found this block of code causes it to stop working.

What is it about this code that disables the serial output?  

Code:
 REG_PIOD_OWER= 0xff;
  REG_PMC_PCER0= 1<<27;  
  REG_PIOB_PDR = 1<<25;
  REG_PIOB_ABSR= 1<<25;
  REG_TC0_WPMR = 0x54494D00;
  REG_TC0_CMR0 = 0b00000000000010011100010000000000;
  //  REG_TC0_CMR0 = 0b00000000000001101100010000000000; // this inverts hsync
  REG_TC0_RC0  = 1334;
  REG_TC0_RA0  = 1174;  
  REG_TC0_CCR0 = 0b101;    
  REG_TC0_IER0 = 0b00010000;
  REG_TC0_IDR0 = 0b11101111;
  NVIC_EnableIRQ(TC0_IRQn);


Is there anything we can do to have this still work and have serial communication available?


--edit--

I did some further debug and found that it works all the way up to the point of calling:

Code:
NVIC_EnableIRQ(TC0_IRQn);
13  Products / Arduino Due / Re: Serial.print() of a 64-bit DOUBLE on: January 19, 2013, 04:23:04 pm
I made those modifications to print.cpp and print.h, and it worked just great on my DUE.  I am now able to display the true size of my 16 GB SD Card:

Code:
Volume size (bytes): 15923150848

I didn't change the methods to size_t though, it worked fine without that change.  (I did try it, and it threw a bunch of errors, so I left them as void).

As you noted, the change does add about 8KB, but heck, I've got a DUE with 512K program memory, so I can spare the extra 8K.  Woot.
14  Products / Arduino Due / Serial.print() of a 64-bit DOUBLE on: January 19, 2013, 12:34:54 am
I've read in the Reference section that the DOUBLE data type on the Due is a 64-bit variable.  Unfortunately, the Serial.print won't handle a 64-bit variable.  I haven't been able to print out a uint64_t either.

Any ideas of how to print this?

I've looked into bit shifting the top 32-bits into an unsigned int, and then printing the high 32-bits followed by the low 32-bits, but apparently the bit shift operator defaults to a 32-bit operation as well.

The reason I'm trying to do this is because I stuck a 16 GB SD card into my wifi shield and can read it using the SD library, but it won't show the correct size of the SD card because it's so large.  The unsigned int will only show up to ~4 GB.  (0xFFFFFFFF = 4294967295 decimal).

Time to program the BigInt class?
15  Products / Arduino Due / Re: Arduino Due Wifi example not working on: January 18, 2013, 11:56:38 pm
How exactly do we get the code from the repository and build the library until it's released somewhere officially?
Pages: [1] 2 3 ... 7