Show Posts
|
|
Pages: [1]
|
|
1
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 11, 2012, 04:44:30 am
|
Wie schon befürchtet komm ich net weiter... Beispiel-Project: #include <ST7735.h> #include <SD.h> #include <SPI.h>
// If we are using the hardware SPI interface, these are the pins (for future ref) #define sclk 13 //ich nutz ja 52 für LCD #define mosi 11 //ich nutz ja 51 für LCD
// You can also just connect the reset pin to +5V (we do a software reset) #define rst 8 //ich nutz 41 für LCD
// these pins are required #define cs //ich nutz ja 53 für LCD #define dc //ich nutz 40 für LCD
// 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
// to draw images from the SD card, we will share the hardware SPI interface ST7735 tft = ST7735(cs, dc, rst);
// For Arduino Uno/Duemilanove, etc // 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) Hau ich das LCD und die SD-Card parallel aufs SPI-Interface?
|
|
|
|
|
2
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 11, 2012, 03:39:20 am
|
So. Läuft jetzt über SPI  //#define sclk 52 //#define mosi 51 #define cs 53 #define dc 7 #define rst 8
#define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF
#include <ST7735.h> #include <SPI.h>
//ST7735 tft = ST7735(cs, dc, mosi, sclk, rst); ST7735 tft = ST7735(cs, dc, rst); Jetzt will ich die SD-Karte noch zum Laufen kriegen... Hoffe auf Hilfe wenn ich nicht weiterkomme 
|
|
|
|
|
4
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 10, 2012, 04:14:33 am
|
Sehe gerade meinen Stand der 100% läuft: #define sclk 4 #define mosi 5 #define cs 6 #define dc 7 #define rst 8
#define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF
#include <ST7735.h> #include <SPI.h>
ST7735 tft = ST7735(cs, dc, mosi, sclk, rst); d.h. das funktioniert also auch auf anderen Pins... die highspeed-methode läuft nicht. dafür werden nur cs, dc und rst verwendet: ST7735 tft = ST7735(cs, dc, rst); würde ja wie folgt aussehen: //#define sclk 4 //#define mosi 5 #define cs 53 #define dc 7 #define rst 8 Funktioniert dennoch nicht
|
|
|
|
|
5
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 10, 2012, 04:03:20 am
|
Genau, und Hardwareseitig wie folgt ändern:
SCL -> SCK = 52 SDA -> MOSI = 51 RS/DC -> 9 RES -> 8 CS -> SS = 53
Fragen bildet schließlich, also keine Sorge.
ok... Hab meinen Fehler gefunden denk ich... Habe die Pins in den Kommentaren nicht genutzt, die für den MEGA notwendig sind...
|
|
|
|
|
6
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 10, 2012, 03:49:25 am
|
// Pins SCLK and MOSI are fixed in hardware, and pin 10 (or 53) // must be an output //#define sclk 13 // for MEGAs use pin 52 //#define mosi 11 // for MEGAs use pin 51 #define cs 10 // for MEGAs you probably want this to be pin 53 #define dc 9 #define rst 8 // you can also connect this to the Arduino reset
// 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
#include <ST7735.h> #include <SPI.h>
// Option 1: use any pins but a little slower //ST7735 tft = ST7735(cs, dc, mosi, sclk, rst);
// Option 2: must use the hardware SPI pins // (for UNO thats sclk = 13 and sid = 11) and pin 10 must be // an output. This is much faster - also required if you want // to use the microSD card (see the image drawing example) ST7735 tft = ST7735(cs, dc, rst); Also im oberen Code die Pin 10 durch Pin 53 ersetzen? Tut mir leid für diese simplen Fragen, Stecke nicht so in dem Thema drinn und bin blutiger Anfänger...
|
|
|
|
|
7
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 10, 2012, 03:29:29 am
|
Ah, okay. Ich befürchte, ich hab dein Problem nicht 100% verstanden :-) daher ein paar Fragen, die vielleicht auch den anderen helfen:
Bestätige oder verneine mal
- SD-Karte alleine ohne LCD tut? - LCD alleine ohne SD tut auch (in der "langsamen" Variante)? (habe ein ja gelesen) - LCD alleine ohne SD tut auch auf Hardware-SPI? - SD auf SPI und gleichzeitig LCD in "langsam" tut auch? - sobald du SD und LCD zusammen auf die Hardware-SPI-Pins belegst, tut nix
Hatte bisher keinen Zugriff auf die Karte, egal was ich probiert habe. LCD in langsame Version läuft (Hab versucht damit auch die Karte zu betreiben, geht nicht). Nutze ich nur cs und dc tut es nichts mehr... Für die SD-Card nutzung hab ich halt nur den Beispiel-Code von oben. Mir gehts erst mal darum das LCD über SPI nutzen zu können.
|
|
|
|
|
8
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 10, 2012, 03:04:10 am
|
|
Verbinde das LCD über Steckverbindungen, da es kein extra Shield ist und nicht dierekt gesteckt werden kann.
Bezeichnungen auf dem LCD sind wie folgt:
VCC GND SCL -> 13 SDA -> 11 RS/DC -> 9 RES -> 8 CS -> 10
SD-CARD:
MISO -> ??? SCLK - >??? MOSI -> ??? CS -> 4
|
|
|
|
|
9
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 10, 2012, 02:40:24 am
|
|
Das mit dem Code-Tag lief etwas schief bei meinem letzten Post.
Ja, habe das im Kommentar getestet, funktioniert dennoch nicht.
Kann es irgendwie an der SPI.h liegen, ohne dass ich es im Compiler mitkriege?
|
|
|
|
|
10
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 09, 2012, 06:09:54 pm
|
#include <ST7735.h> #include <SD.h> #include <SPI.h>
// If we are using the hardware SPI interface, these are the pins (for future ref) #define sclk 13 #define mosi 11
// You can also just connect the reset pin to +5V (we do a software reset) #define rst 8
// these pins are required #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
// to draw images from the SD card, we will share the hardware SPI interface ST7735 tft = ST7735(cs, dc, rst);
// For Arduino Uno/Duemilanove, etc // 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(); // change this to initB() for ST7735B TFT's
// 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("parrot.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); } }
/*********************************************/ // This procedure reads a bitmap and draws it to the screen // its sped up by reading many pixels worth of data at a time // instead of just one pixel at a time. increading the buffer takes // more RAM but makes the drawing a little faster. 20 pixels' worth // is probably a good place
#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[2 * BUFFPIXEL]; // 3 * pixels to buffer uint8_t buffidx = 2*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++) { // bitmaps are stored with the BOTTOM line first so we have to move 'up' for (j=0; j<bmpWidth; j++) { // read more pixels //if (buffidx >= 2*BUFFPIXEL) { //bmpFile.read(sdbuffer, 3*BUFFPIXEL); //buffidx = 0; sdbuffer[0] = bmpFile.read(); sdbuffer[1] = bmpFile.read(); sdbuffer[2] = bmpFile.read(); //Serial.print(sdbuffer[0], HEX); //Serial.print(sdbuffer[1], HEX); //Serial.print(sdbuffer[2], HEX); //} //p = (sdbuffer[1] << 8) | sdbuffer[0]; //buffidx++; //buffidx++; // convert pixel from 565 to 888 //b = sdbuffer[0] & 0x1f; //g = (sdbuffer[0] >> 5) | (sdbuffer[1] << 5); //r = sdbuffer[1] >> 3; // convert pixel from 888 to 565 b = sdbuffer[0]; // blue g = sdbuffer[1]; // green p = sdbuffer[2]; // 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; }
/*********************************************/
// These read data from the SD card file and convert them to big endian // (the data is stored in little endian format!)
// 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; }
Bekomme im Serial Monitor immer Initializing SD card...failed!
|
|
|
|
|
11
|
International / Deutsch / Re: Kriege den SPI Bus nicht zum laufen
|
on: December 09, 2012, 06:09:35 pm
|
Nutze ich den "langsamen" Code, funktionier alles: // You can use any (4 or) 5 pins #define sclk 4 #define mosi 5 #define cs 6 #define dc 7 #define rst 8 // you can also connect this to the Arduino reset
// 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
#include <ST7735.h> #include <SPI.h>
// Option 1: use any pins but a little slower ST7735 tft = ST7735(cs, dc, mosi, sclk, rst);
// Option 2: must use the hardware SPI pins // (for UNO thats sclk = 13 and sid = 11) and pin 10 must be // an output. This is much faster - also required if you want // to use the microSD card (see the image drawing example) //ST7735 tft = ST7735(cs, dc, rst);
void fillpixelbypixel(uint16_t color) { for (uint8_t x=0; x < tft.width; x++) { for (uint8_t y=0; y < tft.height; y++) { tft.drawPixel(x, y, color); } } delay(100); }
void setup(void) { Serial.begin(9600); Serial.print("hello!"); tft.initR(); // initialize a ST7735R chip
Serial.println("init"); tft.writecommand(ST7735_DISPON); uint16_t time = millis(); tft.fillScreen(BLACK); time = millis() - time; Serial.println(time, DEC); delay(500); // tft.fillScreen(BLACK); testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", WHITE); delay(1000); //a single pixel tft.drawPixel(tft.width/2, tft.height/2, GREEN); delay(500); // line draw test testlines(YELLOW); delay(500); // optimized lines testfastlines(RED, BLUE); delay(500);
testdrawrects(GREEN); delay(500);
testfillrects(YELLOW, MAGENTA); delay(500);
tft.fillScreen(BLACK); testfillcircles(10, BLUE); testdrawcircles(10, WHITE); Serial.println("done"); delay(1000); }
void loop() { tft.writecommand(ST7735_INVON); delay(500); tft.writecommand(ST7735_INVOFF); delay(500); }
void testlines(uint16_t color) { tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(0, 0, x, tft.height-1, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(0, 0, tft.width-1, y, color); } tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(tft.width-1, 0, x, tft.height-1, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(tft.width-1, 0, 0, y, color); } tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(0, tft.height-1, x, 0, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(0, tft.height-1, tft.width-1, y, color); }
tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(tft.width-1, tft.height-1, x, 0, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(tft.width-1, tft.height-1, 0, y, color); } }
void testdrawtext(char *text, uint16_t color) { tft.drawString(0, 0, text, color); }
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); } }
void testdrawrects(uint16_t color) { tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawRect(tft.width/2 -x/2, tft.height/2 -x/2 , x, x, color); } }
void testfillrects(uint16_t color1, uint16_t color2) { tft.fillScreen(BLACK); for (uint16_t x=tft.width-1; x > 6; x-=6) { tft.fillRect(tft.width/2 -x/2, tft.height/2 -x/2 , x, x, color1); tft.drawRect(tft.width/2 -x/2, tft.height/2 -x/2 , x, x, color2); } }
void testfillcircles(uint8_t radius, uint16_t color) { for (uint8_t x=radius; x < tft.width; x+=radius*2) { for (uint8_t y=radius; y < tft.height; y+=radius*2) { tft.fillCircle(x, y, radius, color); } } }
void testdrawcircles(uint8_t radius, uint16_t color) { for (uint8_t x=0; x < tft.width+radius; x+=radius*2) { for (uint8_t y=0; y < tft.height+radius; y+=radius*2) { tft.drawCircle(x, y, radius, color); } } } Habe noch so gut wie keine Erfahrung. Mein Ziel ist eine Grafikanzeige und will halt die SD-Karte nutzen wie in folgendem Code und drehe mich halt im Kreis... Vllt. kann mir ja jemand helfen?!
|
|
|
|
|
12
|
International / Deutsch / Kriege den SPI Bus nicht zum laufen
|
on: December 09, 2012, 06:08:27 pm
|
Hallo Leute, Nutze ein Arduino Mega 2560 und ein 1,8" LCD von SainSmart. Folgender Code wird genutzt, läuft aber nicht: // Pins SCLK and MOSI are fixed in hardware, and pin 10 (or 53) // must be an output //#define sclk 13 // for MEGAs use pin 52 //#define mosi 11 // for MEGAs use pin 51 #define cs 10 // for MEGAs you probably want this to be pin 53 #define dc 9 #define rst 8 // you can also connect this to the Arduino reset
// 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
#include <ST7735.h> #include <SPI.h>
// Option 1: use any pins but a little slower //ST7735 tft = ST7735(cs, dc, mosi, sclk, rst);
// Option 2: must use the hardware SPI pins // (for UNO thats sclk = 13 and sid = 11) and pin 10 must be // an output. This is much faster - also required if you want // to use the microSD card (see the image drawing example) ST7735 tft = ST7735(cs, dc, rst);
void fillpixelbypixel(uint16_t color) { for (uint8_t x=0; x < tft.width; x++) { for (uint8_t y=0; y < tft.height; y++) { tft.drawPixel(x, y, color); } } delay(100); }
void setup(void) { Serial.begin(9600); Serial.print("hello!"); tft.initR(); // initialize a ST7735R chip
Serial.println("init"); tft.writecommand(ST7735_DISPON); uint16_t time = millis(); tft.fillScreen(BLACK); time = millis() - time; Serial.println(time, DEC); delay(500); // tft.fillScreen(BLACK); testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", WHITE); delay(10000); //a single pixel tft.drawPixel(tft.width/2, tft.height/2, GREEN); delay(500); // line draw test testlines(YELLOW); delay(500); // optimized lines testfastlines(RED, BLUE); delay(500);
testdrawrects(GREEN); delay(500);
testfillrects(YELLOW, MAGENTA); delay(500);
tft.fillScreen(BLACK); testfillcircles(10, BLUE); testdrawcircles(10, WHITE); Serial.println("done"); delay(1000); }
void loop() { tft.writecommand(ST7735_INVON); delay(500); tft.writecommand(ST7735_INVOFF); delay(500); }
void testlines(uint16_t color) { tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(0, 0, x, tft.height-1, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(0, 0, tft.width-1, y, color); } tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(tft.width-1, 0, x, tft.height-1, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(tft.width-1, 0, 0, y, color); } tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(0, tft.height-1, x, 0, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(0, tft.height-1, tft.width-1, y, color); }
tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawLine(tft.width-1, tft.height-1, x, 0, color); } for (uint16_t y=0; y < tft.height; y+=6) { tft.drawLine(tft.width-1, tft.height-1, 0, y, color); } }
void testdrawtext(char *text, uint16_t color) { tft.drawString(0, 0, text, color); }
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); } }
void testdrawrects(uint16_t color) { tft.fillScreen(BLACK); for (uint16_t x=0; x < tft.width; x+=6) { tft.drawRect(tft.width/2 -x/2, tft.height/2 -x/2 , x, x, color); } }
void testfillrects(uint16_t color1, uint16_t color2) { tft.fillScreen(BLACK); for (uint16_t x=tft.width-1; x > 6; x-=6) { tft.fillRect(tft.width/2 -x/2, tft.height/2 -x/2 , x, x, color1); tft.drawRect(tft.width/2 -x/2, tft.height/2 -x/2 , x, x, color2); } }
void testfillcircles(uint8_t radius, uint16_t color) { for (uint8_t x=radius; x < tft.width; x+=radius*2) { for (uint8_t y=radius; y < tft.height; y+=radius*2) { tft.fillCircle(x, y, radius, color); } } }
void testdrawcircles(uint8_t radius, uint16_t color) { for (uint8_t x=0; x < tft.width+radius; x+=radius*2) { for (uint8_t y=0; y < tft.height+radius; y+=radius*2) { tft.drawCircle(x, y, radius, color); } } } Ist ein Example vom Hersteller... Alles nach angaben aufgelegt.
|
|
|
|
|