Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / TFT Help on: June 22, 2011, 04:20:59 pm
    I needed helped on how to write a code and connect a LCD TFT display to a arduino so that when the LCD display turns on and loads image, it turns off after five seconds. The reason for this is to save battery because the LCD remains on. Please help thanks!

This is my code:
Code:
#include <ST7735.h>
#include <SD.h>
#include <SPI.h>

#define sclk 13
#define mosi 11

#define rst 8

#define cs 10
#define dc 9

// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

// we will share the hardware SPI interface
ST7735 tft = ST7735(cs, dc, rst);

// connect the SD card with MOSI going to pin 11, MISO going to pin 12 and SCK going to pin 13 (standard)
// Then pin 4 goes to CS (or whatever you have set up)
#define SD_CS 4 // Set the chip select line to whatever you use (4 doesnt conflict with the library)

// the file itself
File bmpFile;

// information we extract about the bitmap file
int bmpWidth, bmpHeight;
uint8_t bmpDepth, bmpImageoffset;

void setup(void) {
Serial.begin(9600);

pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH);

// initialize a ST7735R TFT
tft.initR();

// Just do a simple test
tft.writecommand(ST7735_DISPON);

Serial.print("Initializing SD card...");

if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
Serial.println("SD OK!");

bmpFile = SD.open("IMAGE.bmp");

if (! bmpFile) {
Serial.println("didnt find image");
while (1);
}

if (! bmpReadHeader(bmpFile)) {
Serial.println("bad bmp");
return;
}

Serial.print("image size ");
Serial.print(bmpWidth, DEC);
Serial.print(", ");
Serial.println(bmpHeight, DEC);


bmpdraw(bmpFile, 0, 0);
}

void loop() {
}


void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(BLACK);
for (uint16_t y=0; y < tft.height; y+=5) {
tft.drawHorizontalLine(0, y, tft.width, color1);
}
for (uint16_t x=0; x < tft.width; x+=5) {
tft.drawVerticalLine(x, 0, tft.height, color2);
}
}

/*********************************************/


#define BUFFPIXEL 20

void bmpdraw(File f, int x, int y) {
bmpFile.seek(bmpImageoffset);

uint32_t time = millis();
uint16_t p;
uint8_t g, b;
int i, j;

uint8_t sdbuffer[3 * BUFFPIXEL]; // 3 * pixels to buffer
uint8_t buffidx = 3*BUFFPIXEL;

//Serial.print("rotation = "); Serial.println(tft.getRotation(), DEC);

//set up the 'display window'
tft.setAddrWindow(x, y, x+bmpWidth-1, y+bmpHeight-1);

uint8_t rotback = tft.getRotation();
//tft.setRotation();

for (i=0; i< bmpHeight; i++) {


for (j=0; j<bmpWidth; j++) {
// read more pixels
if (buffidx >= 3*BUFFPIXEL) {
bmpFile.read(sdbuffer, 3*BUFFPIXEL);
buffidx = 0;
}

// convert pixel from 888 to 565
b = sdbuffer[buffidx++]; // blue
g = sdbuffer[buffidx++]; // green
p = sdbuffer[buffidx++]; // red

p >>= 3;
p <<= 6;

g >>= 2;
p |= g;
p <<= 5;

b >>= 3;
p |= b;
//Serial.print(p, HEX);
// write out the 16 bits of color
//tft.drawPixel(i, j, p);
tft.pushColor(p);
}
}
Serial.print(millis() - time, DEC);
Serial.println(" ms");
}

boolean bmpReadHeader(File f) {
// read header
uint32_t tmp;

if (read16(f) != 0x4D42) {
// magic bytes missing
return false;
}

// read file size
tmp = read32(f);
Serial.print("size 0x"); Serial.println(tmp, HEX);

// read and ignore creator bytes
read32(f);

bmpImageoffset = read32(f);
Serial.print("offset "); Serial.println(bmpImageoffset, DEC);

// read DIB header
tmp = read32(f);
Serial.print("header size "); Serial.println(tmp, DEC);
bmpWidth = read32(f);
bmpHeight = read32(f);


if (read16(f) != 1)
return false;

bmpDepth = read16(f);
Serial.print("bitdepth "); Serial.println(bmpDepth, DEC);

if (read32(f) != 0) {
// compression not supported!
return false;
}

Serial.print("compression "); Serial.println(tmp, DEC);

return true;
}

/*********************************************/


// LITTLE ENDIAN!
uint16_t read16(File f) {
uint16_t d;
uint8_t b;
b = f.read();
d = f.read();
d <<= 8;
d |= b;
return d;
}


// LITTLE ENDIAN!
uint32_t read32(File f) {
uint32_t d;
uint16_t b;

b = read16(f);
d = read16(f);
d <<= 16;
d |= b;
return d;
}
2  Using Arduino / Displays / LCD TFT Display on: June 21, 2011, 02:00:58 pm
I needed helped on how to connect a LCD TFT display to a arduino so that when the LCD display turns on and loads image, it turns off after five seconds. The reason for this is to save battery because the LCD remains on. Please help thanks!

This is my code:
Code:
#include <ST7735.h>
#include <SD.h>
#include <SPI.h>

#define sclk 13
#define mosi 11

#define rst 8

#define cs 10
#define dc 9

// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0 
#define WHITE           0xFFFF

// we will share the hardware SPI interface
ST7735 tft = ST7735(cs, dc, rst);

//  connect the SD card with MOSI going to pin 11, MISO going to pin 12 and SCK going to pin 13 (standard)
//  Then pin 4 goes to CS (or whatever you have set up)
#define SD_CS 4    // Set the chip select line to whatever you use (4 doesnt conflict with the library)

// the file itself
File bmpFile;

// information we extract about the bitmap file
int bmpWidth, bmpHeight;
uint8_t bmpDepth, bmpImageoffset;

void setup(void) {
  Serial.begin(9600);
   
  pinMode(cs, OUTPUT);
  digitalWrite(cs, HIGH);
     
  // initialize a ST7735R TFT
  tft.initR();     

  // Just do a simple test
  tft.writecommand(ST7735_DISPON);
 
  Serial.print("Initializing SD card...");

  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
    return;
  }
  Serial.println("SD OK!");
 
  bmpFile = SD.open("IMAGE.bmp");

  if (! bmpFile) {
    Serial.println("didnt find image");
    while (1);
  }
 
  if (! bmpReadHeader(bmpFile)) {
     Serial.println("bad bmp");
     return;
  }
 
  Serial.print("image size ");
  Serial.print(bmpWidth, DEC);
  Serial.print(", ");
  Serial.println(bmpHeight, DEC);
 

  bmpdraw(bmpFile, 0, 0);
}

void loop() {
}


void testfastlines(uint16_t color1, uint16_t color2) {
   tft.fillScreen(BLACK);
   for (uint16_t y=0; y < tft.height; y+=5) {
     tft.drawHorizontalLine(0, y, tft.width, color1);
   }
   for (uint16_t x=0; x < tft.width; x+=5) {
     tft.drawVerticalLine(x, 0, tft.height, color2);
   }
}

/*********************************************/


#define BUFFPIXEL 20

void bmpdraw(File f, int x, int y) {
  bmpFile.seek(bmpImageoffset);
 
  uint32_t time = millis();
  uint16_t p;
  uint8_t g, b;
  int i, j;
 
  uint8_t sdbuffer[3 * BUFFPIXEL];  // 3 * pixels to buffer
  uint8_t buffidx = 3*BUFFPIXEL;
 
  //Serial.print("rotation = "); Serial.println(tft.getRotation(), DEC);
 
  //set up the 'display window'
  tft.setAddrWindow(x, y, x+bmpWidth-1, y+bmpHeight-1);
 
  uint8_t rotback = tft.getRotation();
  //tft.setRotation();
 
  for (i=0; i< bmpHeight; i++) {
   
 
    for (j=0; j<bmpWidth; j++) {
      // read more pixels
      if (buffidx >= 3*BUFFPIXEL) {
        bmpFile.read(sdbuffer, 3*BUFFPIXEL);
        buffidx = 0;
      }
     
      // convert pixel from 888 to 565
      b = sdbuffer[buffidx++];     // blue
      g = sdbuffer[buffidx++];     // green
      p = sdbuffer[buffidx++];     // red
     
      p >>= 3;
      p <<= 6;
     
      g >>= 2;
      p |= g;
      p <<= 5;
     
      b >>= 3;
      p |= b;
     //Serial.print(p, HEX);
      // write out the 16 bits of color
      //tft.drawPixel(i, j, p);
      tft.pushColor(p);
    }
  }
  Serial.print(millis() - time, DEC);
  Serial.println(" ms");
}

boolean bmpReadHeader(File f) {
   // read header
  uint32_t tmp;
 
  if (read16(f) != 0x4D42) {
    // magic bytes missing
    return false;
  }
 
  // read file size
  tmp = read32(f); 
  Serial.print("size 0x"); Serial.println(tmp, HEX);
 
  // read and ignore creator bytes
  read32(f);
 
  bmpImageoffset = read32(f); 
  Serial.print("offset "); Serial.println(bmpImageoffset, DEC);
 
  // read DIB header
  tmp = read32(f);
  Serial.print("header size "); Serial.println(tmp, DEC);
  bmpWidth = read32(f);
  bmpHeight = read32(f);

 
  if (read16(f) != 1)
    return false;
   
  bmpDepth = read16(f);
  Serial.print("bitdepth "); Serial.println(bmpDepth, DEC);

  if (read32(f) != 0) {
    // compression not supported!
    return false;
  }
 
  Serial.print("compression "); Serial.println(tmp, DEC);

  return true;
}

/*********************************************/


// LITTLE ENDIAN!
uint16_t read16(File f) {
  uint16_t d;
  uint8_t b;
  b = f.read();
  d = f.read();
  d <<= 8;
  d |= b;
  return d;
}


// LITTLE ENDIAN!
uint32_t read32(File f) {
  uint32_t d;
  uint16_t b;
 
  b = read16(f);
  d = read16(f);
  d <<= 16;
  d |= b;
  return d;
}

3  Using Arduino / Motors, Mechanics, and Power / Re: Solar Panel Charger For Arduino on: March 08, 2011, 12:45:44 am
Thanks Crossroads, I appreciate the help.
4  Using Arduino / Motors, Mechanics, and Power / Re: Solar Panel Charger For Arduino on: March 07, 2011, 11:44:05 pm
The 14V battery is a rechargeable Li-Ion.
5  Using Arduino / Motors, Mechanics, and Power / Re: Solar Panel Charger For Arduino on: March 06, 2011, 12:03:51 am
So, if I was using a step-down regulator so the Arduino ran cooler and connected the positive terminal of the battery to vin and negative to gnd. Where does VOUT and SHDN get connected to the Arduino?
6  Using Arduino / Motors, Mechanics, and Power / Re: Solar Panel Charger For Arduino on: March 05, 2011, 11:24:28 pm
Now, can this recharge the 14v battery or would I need to add something else?


Also, the voltage regulator is labeled SHDN, VIN, GND and VOUT. What gets connected to the  14v battery and what gets connected to the Arduino board (positive/negative)?

Thanks,
7  Using Arduino / Motors, Mechanics, and Power / Solar Panel Charger For Arduino on: March 05, 2011, 12:50:57 pm
Is it possible to connect a solar panel charger that has a output of 5.0V, 0.5A to a Arduino board that has a 14V battery with a step-down voltage regulator. And if so, how?
8  Using Arduino / Motors, Mechanics, and Power / 14v Power Source on: February 28, 2011, 10:59:31 pm
I wanted to know if its possible to power an Arduino with a 14v battery and if so how?
9  Using Arduino / Programming Questions / Re: Programing Arduino To Sleep on: February 28, 2011, 06:23:26 pm
I do'nt know how to rewrite or phrase the previous code I gave in order make the Arduino wake up and go to sleep.

The purpose of this is to save battery power because when it finishes the first loop and the second loop, the Arduino continues to stay on. So, I want it to turn on when the force sensor is pressed and turns off after the first loop. Then turns on again when the switch sensor is pressed and turns off after the second loop.
10  Using Arduino / Programming Questions / Programing Arduino To Sleep on: February 28, 2011, 03:41:26 pm
Hi, I'm having a little trouble on how to write a code in order to make the Arduino wake up when the FSR force sensor (valF>=thresHold && valFenabled) has been pressed and goes to sleep after valSenabled = 1;. Then turns the Arduino back on when the switch sensor(valS == HIGH && valSenabled) is pressed and then goes to sleep after valFenabled = 1;.
Pages: [1]