RE: Bahnhofstafel mit Arduino

#1 von Rothpe , 19.07.2018 12:36

Hallo zusammen,

in meinem neuen Projekt habe ich eine Bahnhofstafel angefangen.

http://www.bilder-upload.eu/show.php?fil...-1531996595.jpg

Da ich nun nicht der beste Programmierer bin komme ich mit dem Projekt so wie ich es mir vorstelle nicht weiter.
Zur Zeit sind die Daten einfach nur eingegeben und werden auch nicht regelmäßig aktualisiert.
Eine Fahrplan.txt habe ich schon fertig.
Meine weiteren Schritte wären das Ganze in Arrays zu verteilen und dann Uhrzeit gesteuert auszugeben.
Allerdings kommt hier der große Haken.
Ich weiß den weiteren Ansatz mangels Erfahrung nicht.

Vielleicht gibt es hier im Forum jemanden den das Projekt auch interessiert und mir dabei helfen mag das zu Ende zu bringen.

Passendes Gehäuse könnte ich per 3D Druck bei einem Bekannten in Auftrag geben.

Über positive Rückmeldungen würde ich mich sehr freuen.

Viele Grüße

Peter


Rothpe  
Rothpe
Regionalbahn (RB)
Beiträge: 27
Registriert am: 11.03.2018
Ort: Bad Marienberg
Spurweite H0
Stromart AC, Digital


RE: Bahnhofstafel mit Arduino

#2 von TecnoWorld , 19.07.2018 14:20

Nun, welche Uhrzeit soll denn die Basis sein?
Mit welcher Software steuerst Du die Anlage?

Bei Rocrail würde ich jetzt einfach über den Socket gehen und sie RocRail interne Modellzeit nutzen, um die Fahrpläne zu aktualisieren/Anzuzeigen.
Bei einer anderen Software muss man halt schauen, wie man an die Uhr kommt.

Oder hast Du gar keine Modellzeit und benutzt reale Zeiten?

LG,
Ingolf


__________________________
LG aus Andalusien.
RailSolution - das Lichtprojekt von Modellbahnern für die Modellbahn


TecnoWorld  
TecnoWorld
InterRegioExpress (IRE)
Beiträge: 270
Registriert am: 11.03.2015


RE: Bahnhofstafel mit Arduino

#3 von Thorsten Haller , 19.07.2018 14:24

Hallo Peter,

beschreib doch bitte erstmal, was du dir vorstellst und realisieren möchtest. D.h. welche Hardware und Software nutzt du, was soll wann, wie unter welchen Bedingungen angezeigt werden.
Erst wenn das "Lastenheft" klar ist, kann man dir auch Tipps für die Umsetzung geben.


Viele Grüße
Thorsten


 
Thorsten Haller
InterRegio (IR)
Beiträge: 128
Registriert am: 08.06.2005
Spurweite H0
Steuerung WinDigipet, Intellibox
Stromart Digital


RE: Bahnhofstafel mit Arduino

#4 von Rothpe , 19.07.2018 14:43

Hallo zusammen,

danke erstmal für Eure Antworten.
Für dieses Projekt habe ich einen Arduino mit einem TFT SPI Display 1,8 Zoll und einer RTC 3231 Uhr verbunden.
In dem Display integriert ist ein SD Slot auf dem ich den Fahrplan als Textfile speichern möchte.
Die Uhr funktioniert live und aktualisiert sich auch.
Auf der SD Card ist das Logo der DB abgespeichert und wird in der Überschrift angezeigt. Funktioniert auch.
Der Fahrplan hat folgendes Datenformat: Uhrzeit (Abfahrtzeit), Zugnummer, Ziel, und Gleisnummer

Beispiel:

6:58 ALX796 Muenchen 2
7:02 RE3281 Buchloe 3
7:08 ALX786 Lindau 1
7:12 RB3841 Wangen 1
7:12 ALX796 Oberstdorf 1
7:14 RB5766 Oberstdorf 1
7:46 RB5760 Kempten 3
7:48 RE3282 Lindau 1
7:51 RE3382 Oberstdorf 1
8:16 RE3383 Nuernberg 3
8:21 RB5744 Oberstdorf 1
8:27 RE5739 Lindau 1

In dem Textfile ist der gesamte Fahrplan eines Bahnhofes über den Tag eingetragen.

Nun soll dieser Inhalt gemäß der aktuellen Uhrzeit ausgegeben warden.

Ob das natürlich alles do realisierbar ist und es micht sogar noch bessere Vorschläge gibt ist noch offen.

Steuern tue ich meine Anlage mit Rocrail.

Viele Grüße

Peter


Rothpe  
Rothpe
Regionalbahn (RB)
Beiträge: 27
Registriert am: 11.03.2018
Ort: Bad Marienberg
Spurweite H0
Stromart AC, Digital


RE: Bahnhofstafel mit Arduino

#5 von TecnoWorld , 19.07.2018 15:08

Dann brauchst Du doch keine eigene Uhr.
Wenn Du mit RocRail steuerst, muss doch die Uhr von Rocrail mit der Anzeige synchron laufen. Und ein Modellbahntag hat ja meist nur 20-40Minuten reale Zeit, je nach deinen Wünschen und Vorgaben.
Also häng den Arduino ans Netzwerk, klemm dich per Socket auf Rocrail drauf und lies die Clock-Pakete aus. Dann kannst Du ja sogar den Fahrplan über Rocrail anpasen, wenn ein Zug mal zeitiger eingetroffen ist, oder Verspätung hat.

LG,
Ingolf


__________________________
LG aus Andalusien.
RailSolution - das Lichtprojekt von Modellbahnern für die Modellbahn


TecnoWorld  
TecnoWorld
InterRegioExpress (IRE)
Beiträge: 270
Registriert am: 11.03.2015


RE: Bahnhofstafel mit Arduino

#6 von Rothpe , 19.07.2018 15:20

Hallo Ingolf,

danke für Deine Anntwort.
Ja das könnte mir auch gefallen.
Nur ..... wie mache ich das ???

In solchen Sachen fehlen mir echt die Kenntnisse.

Und wie kommt mein Fahrplan aus Rocrail an das Display?
Das möchte ich ja als Bahnhofstafel auf die Anlage stellen.

Ideen habe ich aber ...

Viele Grüße

Peter


Rothpe  
Rothpe
Regionalbahn (RB)
Beiträge: 27
Registriert am: 11.03.2018
Ort: Bad Marienberg
Spurweite H0
Stromart AC, Digital


RE: Bahnhofstafel mit Arduino

#7 von TecnoWorld , 19.07.2018 21:36

Was für ein Arduino Board ist es denn?


__________________________
LG aus Andalusien.
RailSolution - das Lichtprojekt von Modellbahnern für die Modellbahn


TecnoWorld  
TecnoWorld
InterRegioExpress (IRE)
Beiträge: 270
Registriert am: 11.03.2015


RE: Bahnhofstafel mit Arduino

#8 von Rothpe , 19.07.2018 21:47

Es ist ein Arduino Uno


Rothpe  
Rothpe
Regionalbahn (RB)
Beiträge: 27
Registriert am: 11.03.2018
Ort: Bad Marienberg
Spurweite H0
Stromart AC, Digital


RE: Bahnhofstafel mit Arduino

#9 von Rothpe , 21.07.2018 16:13

Schade


Rothpe  
Rothpe
Regionalbahn (RB)
Beiträge: 27
Registriert am: 11.03.2018
Ort: Bad Marienberg
Spurweite H0
Stromart AC, Digital


RE: Bahnhofstafel mit Arduino

#10 von TecnoWorld , 21.07.2018 16:30

Ja. Arduinouno hat kein Netzwerk...

Nimm für sowas einen Bananapi zero, oder einen raspberry.
die sind auch nicht teurer, aber schneller programmiert.

LG,
Ingolf


__________________________
LG aus Andalusien.
RailSolution - das Lichtprojekt von Modellbahnern für die Modellbahn


TecnoWorld  
TecnoWorld
InterRegioExpress (IRE)
Beiträge: 270
Registriert am: 11.03.2015


RE: Bahnhofstafel mit Arduino

#11 von moppe , 21.07.2018 18:46

Könnte sie ihren Code hier einstellen?

Dann kann wir sehen was sie gemacht haben......


Klaus


"Meine" Modellbahn:http://www.modelbaneeuropa.dk
Dänisches Bahnforum: http://www.baneforum.dk
PIKO C4 "Horror Gallery": http://moppe.dk/PIKOC4.html


 
moppe
Trans Europ Express (TEE)
Beiträge: 8.729
Registriert am: 07.08.2011
Homepage: Link
Ort: Norddeusche halbinsel
Gleise Roco, PECO, Märklin/Trix, PIKO,
Spurweite H0, H0e, N, Z
Steuerung Z21, Lenz, MpC Gahler+Ringsmeier, Games on Track/Faller
Stromart AC, DC, Digital, Analog


RE: Bahnhofstafel mit Arduino

#12 von Rothpe , 22.07.2018 12:37

Hallo Klaus,

danke für Deine Antwort und für Dein liebes Angebot.

Anbei der Code:

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <Wire.h>
#include "Sodaq_DS3231.h"
#include <SPI.h>
#include <SD.h>


#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9

#define SD_CS 4

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



Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

File myFile;

char timeChar[100];
char dateChar[50];

String dateString;
int minuteNow=0;
int minutePrevious=0;

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

tft.initR(INITR_BLACKTAB);

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

//Überschrift
tft.setRotation(3);
tft.fillScreen(ST7735_BLUE); // Clear display
tft.fillRect(0,0,160,20,ST7735_BLACK);

bmpDraw("LOGO.BMP",0, 5);
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(30, 0);
tft.print("Abfahrt");



//Fahrplan

//Block1
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 19);
tft.print("19:15");
tft.setCursor(35, 19);
tft.setTextColor(BLUE, WHITE);
tft.print("ALX841");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 19);
tft.print("Oberstdorf");
tft.setCursor(150, 19);
tft.print("1");

tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 29);
tft.print("19:17");
tft.setCursor(35, 29);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3894");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 29);
tft.print("Ulm");
tft.setCursor(150, 29);
tft.print("1");

tft.fillRect(0,39,160,2,ST7735_BLACK);


//Block2
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 41);
tft.print("19:58");
tft.setCursor(35, 41);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3397");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 41);
tft.print("Augsburg");
tft.setCursor(150, 41);
tft.print("3");

tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 51);
tft.print("20:05");
tft.setCursor(35, 51);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3294");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 51);
tft.print("Lindau");
tft.setCursor(150, 51);
tft.print("1");

tft.fillRect(0,61,160,2,ST7735_BLACK);


//Block3
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 63);
tft.print("20:15");
tft.setCursor(35, 63);
tft.setTextColor(BLUE, WHITE);
tft.print("RE3394");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 63);
tft.print("Oberstdorf");
tft.setCursor(150, 63);
tft.print("1");

tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 73);
tft.print("20:55");
tft.setCursor(35, 73);
tft.setTextColor(BLUE, WHITE);
tft.print("ALX841");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 73);
tft.print("Muenchen");
tft.setCursor(150, 73);
tft.print("1");

tft.fillRect(0,83,160,2,ST7735_BLACK);


//Block4
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 85);
tft.print("21:06");
tft.setCursor(35, 85);
tft.setTextColor(BLUE, WHITE);
tft.print("ALX841");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 85);
tft.print("Lindau");
tft.setCursor(150, 85);
tft.print("1");

tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 95);
tft.print("21:10");
tft.setCursor(35, 95);
tft.setTextColor(BLUE, WHITE);
tft.print("RB5767");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 95);
tft.print("Oberstdorf");
tft.setCursor(150, 95);
tft.print("3");

tft.fillRect(0,105,160,2,ST7735_BLACK);

//Block5
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 107);
tft.print("21:56");
tft.setCursor(35, 107);
tft.setTextColor(BLUE, WHITE);
tft.print("RB5767");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 107);
tft.print("Augsburg");
tft.setCursor(150, 107);
tft.print("3");

tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 117);
tft.print("21:56");
tft.setCursor(35, 117);
tft.setTextColor(BLUE, WHITE);
tft.print("RB5767");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 117);
tft.print("Augsburg");
tft.setCursor(150, 117);
tft.print("3");







//FahrplanEnde


}

void loop() {
//ConfigStart


DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();

// if (old_ts == 0 || old_ts != ts) {
// old_ts = ts;

minuteNow = now.minute();

if(minuteNow!=minutePrevious)
{
minutePrevious = minuteNow;
String hours = String(now.hour());
if(now.minute()<10)
{
hours = hours+":0"+String(now.minute());
}else
{
hours = hours+":"+String(now.minute());

}
//ConfigEnde

//FahrplanStart

//Überschrift_Uhrzeit
hours.toCharArray(timeChar,100);
tft.setCursor(130, 7);
//tft.setCursor(80, 80);
tft.setTextColor(WHITE, BLACK);
tft.print(timeChar);



}
}

#define BUFFPIXEL 20

void bmpDraw(char *filename, uint8_t x, uint8_t y) {

File bmpFile;
int bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24)
uint32_t bmpImageoffset; // Start of image data in file
uint32_t rowSize; // Not always = bmpWidth; may have padding
uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
boolean goodBmp = false; // Set to true on valid header parse
boolean flip = true; // BMP is stored bottom-to-top
int w, h, row, col;
uint8_t r, g, b;
uint32_t pos = 0, startTime = millis();

if((x >= tft.width()) || (y >= tft.height())) return;

Serial.println();
Serial.print("Loading image '");
Serial.print(filename);
Serial.println(''');

// Open requested file on SD card
if ((bmpFile = SD.open(filename)) == NULL) {
Serial.print("File not found");
return;
}

// Parse BMP header
if(read16(bmpFile) == 0x4D42) { // BMP signature
Serial.print("File size: "); Serial.println(read32(bmpFile));
(void)read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data
Serial.print("Image Offset: "); Serial.println(bmpImageoffset, DEC);
// Read DIB header
Serial.print("Header size: "); Serial.println(read32(bmpFile));
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1) { // # planes -- must be '1'
bmpDepth = read16(bmpFile); // bits per pixel
Serial.print("Bit Depth: "); Serial.println(bmpDepth);
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed

goodBmp = true; // Supported BMP format -- proceed!
Serial.print("Image size: ");
Serial.print(bmpWidth);
Serial.print('x');
Serial.println(bmpHeight);

// BMP rows are padded (if needed) to 4-byte boundary
rowSize = (bmpWidth * 3 + 3) & ~3;

// If bmpHeight is negative, image is in top-down order.
// This is not canon but has been observed in the wild.
if(bmpHeight < 0) {
bmpHeight = -bmpHeight;
flip = false;
}

// Crop area to be loaded
w = bmpWidth;
h = bmpHeight;
if((x+w-1) >= tft.width()) w = tft.width() - x;
if((y+h-1) >= tft.height()) h = tft.height() - y;

// Set TFT address window to clipped image bounds
tft.setAddrWindow(x, y, x+w-1, y+h-1);

for (row=0; row<h; row++) { // For each scanline...

// Seek to start of scan line. It might seem labor-
// intensive to be doing this on every line, but this
// method covers a lot of gritty details like cropping
// and scanline padding. Also, the seek only takes
// place if the file position actually needs to change
// (avoids a lot of cluster math in SD library).
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
else // Bitmap is stored top-to-bottom
pos = bmpImageoffset + row * rowSize;
if(bmpFile.position() != pos) { // Need seek?
bmpFile.seek(pos);
buffidx = sizeof(sdbuffer); // Force buffer reload
}

for (col=0; col<w; col++) { // For each pixel...
// Time to read more pixel data?
if (buffidx >= sizeof(sdbuffer)) { // Indeed
bmpFile.read(sdbuffer, sizeof(sdbuffer));
buffidx = 0; // Set index to beginning
}

// Convert pixel from BMP to TFT format, push to display
b = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
tft.pushColor(tft.Color565(r,g,b));
} // end pixel
} // end scanline
Serial.print("Loaded in ");
Serial.print(millis() - startTime);
Serial.println(" ms");
} // end goodBmp
}
}

bmpFile.close();
if(!goodBmp) Serial.println("BMP format not recognized.");
}

// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.

uint16_t read16(File f) {
uint16_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); // MSB
return result;
}

uint32_t read32(File f) {
uint32_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read();
((uint8_t *)&result)[2] = f.read();
((uint8_t *)&result)[3] = f.read(); // MSB
return result;
}


Und der Fahrplan:


Zeit Zugnummer Ziel Gleis
0:12 RE5761 Lindau 1
0:14 RB3396 Oberstdorf 3
4:48 ALX841 Oberstdorf 1
5:10 RB5760 Ulm 2
5:28 RB5760 Memmingen 3
5:32 RE5760 Lindau 1
6:15 RB5763 Augsburg 3
6:17 RB5760 Lindau 1
6:20 RB5762 Oberstdorf 1
6:23 RE5763 Ulm 3
6:27 ALX841 Muenchen 2
6:45 ALX841 Lindau 1
6:56 ALX841 Oberstdorf 1
6:58 ALX796 Muenchen 2
7:02 RE3281 Buchloe 3
7:08 ALX786 Lindau 1
7:12 RB3841 Wangen 1
7:12 ALX796 Oberstdorf 1
7:14 RB5766 Oberstdorf 1
7:46 RB5760 Kempten 3
7:48 RE3282 Lindau 1
7:51 RE3382 Oberstdorf 1
8:16 RE3383 Nuernberg 3
8:21 RB5744 Oberstdorf 1
8:27 RE5739 Lindau 1
8:30 RE3881 Oberstdorf 2
8:42 RB3843 Wangen 1
8:43 RB5762 Oberstaufen 1
8:50 RB5766 Oberstdorf 1
8:57 RE4247 Oberstdorf 3
8:59 ALX841 Muenchen 2
9:11 ALX841 Lindau 1
9:14 ALX841 Oberstdorf 1
9:16 RE3882 Muenchen 3
9:47 RE3284 Lindau 1
9:51 RE3384 Oberstdorf 1
10:16 RE3285 Augsburg 3
10:22 RB5766 Oberstdorf 3
10:27 IC2084 Augsburg 1
10:36 IC2012 Hannover 2
10:51 RE3883 Oberstdorf 1
11:00 ALX841 Muenchen 2
11:06 ALX841 Lindau 1
11:15 ALX841 Oberstdorf 1
11:17 RE3884 Ulm 3
11:47 RE3286 Lindau 1
11:51 RE3386 Oberstdorf 1
12:12 RB5766 Oberstdorf 2
12:16 RE3287 Augsburg 3
12:44 RE3985 Wangen 1
12:51 RB5766 Oberstdorf 1
12:59 ALX841 Muenchen 2
13:06 ALX841 Lindau 1
13:16 RE3892 Ulm 3
13:19 ALX841 Oberstdorf 1
13:24 RB5760 Oberstaufen 1
13:47 RE3288 Lindau 1
13:51 RE3388 Oberstdorf 1
13:56 RB5767 Kempten 3
14:17 RE3289 Augsburg 3
14:45 RE3987 Lindau 1
14:51 RB3887 Oberstdorf 1
15:00 ALX841 Muenchen 2
15:06 ALX841 Lindau 1
15:14 ALX841 Oberstdorf 1
15:17 RE3888 Ulm 3
15:42 IC2085 Oberstdorf 2
15:47 RE3290 Lindau 1
15:51 RE3390 Oberstdorf 1
16:16 RE3391 Augsburg 3
16:20 RB5767 Oberstdorf 2
16:24 IC2085 Oberstdorf 2
16:46 RE3889 Lindau 1
16:51 RB5767 Oberstdorf 1
16:59 ALX841 Muenchen 2
17:06 ALX841 Lindau 1
17:14 ALX841 Oberstdorf 1
17:16 RE3890 Ulm 3
17:40 RE2013 Oberstdorf 2
17:47 RE3292 Lindau 1
17:47 RE3395 Augsburg 3
17:51 RE3392 Oberstdorf 1
17:57 RE2013 Oberstdorf 2
18:16 RE3295 Nuernberg 3
18:22 RB5744 Oberstdorf 1
18:37 RE4248 Stuttgart 2
18:48 RE3891 Lindau 1
18:51 RB3398 Oberstdorf 1
18:57 ALX841 Muenchen 2
19:07 ALX841 Lindau 1
19:15 ALX841 Oberstdorf 1
19:17 RE3894 Ulm 3
19:34 RE5739 Muenchen 2
19:40 RE5765 Ulm 3
19:58 RE3397 Augsburg 3
20:05 RE3294 Lindau 1
20:15 RE3394 Oberstdorf 1
20:55 ALX841 Muenchen 2
21:06 ALX841 Lindau 1
21:10 RB5767 Oberstdorf 3
21:56 RB3299 Augsburg 2
22:11 RE5761 Lindau 1
22:14 RB5767 Oberstdorf 3
23:06 ALX841 Muenchen 2
23:11 ALX841 Lindau 1
23:14 RB5767 Oberstdorf 3
23:56 RB5760 Kempten 2

Es funktioniert allerdings noch nichts uhrzeitgesteuert da ich nicht weiter weis.
Lediglich die einmalige Anzeige funktioniert.

Viele Grüße

Peter


Rothpe  
Rothpe
Regionalbahn (RB)
Beiträge: 27
Registriert am: 11.03.2018
Ort: Bad Marienberg
Spurweite H0
Stromart AC, Digital


RE: Bahnhofstafel mit Arduino

#13 von moppe , 02.08.2018 16:38

Peter,

Als ich sehen hab wir 3 aufgaben, um ihren ziel zu erreichen.

1. Ihren Text sind "statisch" und nicht variabel.
2. Daten von SD Karte lesen und als variablen nutzen
3. Zeit mit Daten von SD Karte vergleichen um die richtige Daten zu lesen.


1. Ihren code

1
2
3
4
5
6
7
8
9
10
11
12
13
 
//Block1
tft.setTextSize(1);
tft.setTextColor(WHITE, BLUE);
tft.setCursor(0, 19);
tft.print("19:15");
tft.setCursor(35, 19);
tft.setTextColor(BLUE, WHITE);
tft.print("ALX841");
tft.setTextColor(WHITE, BLUE);
tft.setCursor(80, 19);
tft.print("Oberstdorf");
tft.setCursor(150, 19);
tft.print("1");
 



zb print("ALX841")

Wo bei meiner anzeige nutzen ich variablen

1
2
3
4
 

u8g.drawStr(zuglaufSpalte, 12, zuglauf1[count]);

u8g.drawStr(zuglaufSpalte, 19, zuglauf2[count]);
 



zb u8g.drawStr(zuglaufSpalte, 12, zuglauf1[count]);


Bei miener display ist
u8g.drawStr(80, 19, "Oberstdorf");

wie
tft.setCursor(80, 19);
tft.print("Oberstdorf");
an ihren display

Wenn sie variablen haben als Text, kannst wir arbeiten weiter mit 2 und 3.
Sie kannst immer teile von meiner display-code nutzen........


Klaus


"Meine" Modellbahn:http://www.modelbaneeuropa.dk
Dänisches Bahnforum: http://www.baneforum.dk
PIKO C4 "Horror Gallery": http://moppe.dk/PIKOC4.html


 
moppe
Trans Europ Express (TEE)
Beiträge: 8.729
Registriert am: 07.08.2011
Homepage: Link
Ort: Norddeusche halbinsel
Gleise Roco, PECO, Märklin/Trix, PIKO,
Spurweite H0, H0e, N, Z
Steuerung Z21, Lenz, MpC Gahler+Ringsmeier, Games on Track/Faller
Stromart AC, DC, Digital, Analog


RE: Bahnhofstafel mit Arduino

#14 von Rothpe , 05.08.2018 19:53

Hallo Klaus,

so habe ich meinen Sketch geändert:

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <Wire.h>
#include "Sodaq_DS3231.h"
#include <SPI.h>
#include <SD.h>


#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9

#define SD_CS 4

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



Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);



File myFile;

char timeChar[100];
char dateChar[50];

//Fahrplan definieren Start
char uhrzeit[][6]{ // [6] ist anzahl ziffern

"00:12",
"00:14",
"04:48",
"05:10",
"05:28",
"05:32",
"06:15",


};
//char zugnummer[][7]{// [7] ist anzahl charakteren

char zugnummer[][7]{"RE5761", "RB3396", "ALX841", "RB5760", "RB5760", "RB5760", };


char ziel[][11]{// [11] ist anzahl charakteren

"Lindau",
"Oberstdorf",
"Oberstdorf",
"Ulm",





};

char gleis[][2]{ //[2] ist anzahl charakteren

"1",
"3",
"1",
"2",
"3",
"1",
"3",


};

//Fahrplan definieren Ende


String dateString;
int minuteNow=0;
int minutePrevious=0;

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

tft.initR(INITR_BLACKTAB);

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

//Überschrift
tft.setRotation(3);
tft.fillScreen(ST7735_BLUE); // Clear display
tft.fillRect(0,0,160,20,ST7735_BLACK);

bmpDraw("logo.BMP",0, 0);



tft.setTextSize(2);
tft.setCursor(35, 0);
tft.print("Abfahrt");

tft.setCursor(0, 20);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(uhrzeit[0]);


tft.setCursor(35, 20);
tft.setTextColor(BLUE, WHITE);
tft.setTextSize(1);
tft.print(zugnummer[0]);

tft.setCursor(80, 20);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(ziel[0]);

tft.setCursor(150, 20);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(gleis[0]);


tft.setCursor(0, 30);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(uhrzeit[1]);

tft.setCursor(35, 30);
tft.setTextColor(BLUE, WHITE);
tft.setTextSize(1);
tft.print(zugnummer[1]);

tft.setCursor(80, 30);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(ziel[1]);

tft.setCursor(150, 30);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(gleis[1]);

tft.fillRect(0,40,160,2,ST7735_BLACK);


tft.setCursor(0, 42);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(uhrzeit[2]);

tft.setCursor(35, 42);
tft.setTextColor(BLUE, WHITE);
tft.setTextSize(1);
tft.print(zugnummer[2]);

tft.setCursor(80, 42);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(ziel[2]);

tft.setCursor(150, 42);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(gleis[2]);


tft.setCursor(0, 52);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(uhrzeit[3]);

tft.setCursor(35, 52);
tft.setTextColor(BLUE, WHITE);
tft.setTextSize(1);
tft.print(zugnummer[3]);

tft.setCursor(80, 52);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(ziel[3]);

tft.setCursor(150, 52);
tft.setTextColor(WHITE, BLUE);
tft.setTextSize(1);
tft.print(gleis[3]);


}

void loop() {



//ConfigStart


DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();

// if (old_ts == 0 || old_ts != ts) {
// old_ts = ts;

minuteNow = now.minute();

if(minuteNow!=minutePrevious)
{
minutePrevious = minuteNow;
String hours = String(now.hour());
if(now.minute()<10)
{
hours = hours+":0"+String(now.minute());
}else
{
hours = hours+":"+String(now.minute());

}
//ConfigEnde

//FahrplanStart

//Überschrift_Uhrzeit
hours.toCharArray(timeChar,100);
tft.setCursor(130, 5);
//tft.setCursor(80, 80);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(1);
tft.print(timeChar);



}
}

#define BUFFPIXEL 20

void bmpDraw(char *filename, uint8_t x, uint8_t y) {

File bmpFile;
int bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24)
uint32_t bmpImageoffset; // Start of image data in file
uint32_t rowSize; // Not always = bmpWidth; may have padding
uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
boolean goodBmp = false; // Set to true on valid header parse
boolean flip = true; // BMP is stored bottom-to-top
int w, h, row, col;
uint8_t r, g, b;
uint32_t pos = 0, startTime = millis();

if((x >= tft.width()) || (y >= tft.height())) return;

Serial.println();
Serial.print("Loading image '");
Serial.print(filename);
Serial.println(''');

// Open requested file on SD card
if ((bmpFile = SD.open(filename)) == NULL) {
Serial.print("File not found");
return;
}

// Parse BMP header
if(read16(bmpFile) == 0x4D42) { // BMP signature
Serial.print("File size: "); Serial.println(read32(bmpFile));
(void)read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data
Serial.print("Image Offset: "); Serial.println(bmpImageoffset, DEC);
// Read DIB header
Serial.print("Header size: "); Serial.println(read32(bmpFile));
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1) { // # planes -- must be '1'
bmpDepth = read16(bmpFile); // bits per pixel
Serial.print("Bit Depth: "); Serial.println(bmpDepth);
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed

goodBmp = true; // Supported BMP format -- proceed!
Serial.print("Image size: ");
Serial.print(bmpWidth);
Serial.print('x');
Serial.println(bmpHeight);

// BMP rows are padded (if needed) to 4-byte boundary
rowSize = (bmpWidth * 3 + 3) & ~3;

// If bmpHeight is negative, image is in top-down order.
// This is not canon but has been observed in the wild.
if(bmpHeight < 0) {
bmpHeight = -bmpHeight;
flip = false;
}

// Crop area to be loaded
w = bmpWidth;
h = bmpHeight;
if((x+w-1) >= tft.width()) w = tft.width() - x;
if((y+h-1) >= tft.height()) h = tft.height() - y;

// Set TFT address window to clipped image bounds
tft.setAddrWindow(x, y, x+w-1, y+h-1);

for (row=0; row<h; row++) { // For each scanline...

// Seek to start of scan line. It might seem labor-
// intensive to be doing this on every line, but this
// method covers a lot of gritty details like cropping
// and scanline padding. Also, the seek only takes
// place if the file position actually needs to change
// (avoids a lot of cluster math in SD library).
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
else // Bitmap is stored top-to-bottom
pos = bmpImageoffset + row * rowSize;
if(bmpFile.position() != pos) { // Need seek?
bmpFile.seek(pos);
buffidx = sizeof(sdbuffer); // Force buffer reload
}

for (col=0; col<w; col++) { // For each pixel...
// Time to read more pixel data?
if (buffidx >= sizeof(sdbuffer)) { // Indeed
bmpFile.read(sdbuffer, sizeof(sdbuffer));
buffidx = 0; // Set index to beginning
}

// Convert pixel from BMP to TFT format, push to display
b = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
tft.pushColor(tft.Color565(r,g,b));
} // end pixel
} // end scanline
Serial.print("Loaded in ");
Serial.print(millis() - startTime);
Serial.println(" ms");
} // end goodBmp
}
}

bmpFile.close();
if(!goodBmp) Serial.println("BMP format not recognized.");
}

// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.

uint16_t read16(File f) {
uint16_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); // MSB
return result;
}

uint32_t read32(File f) {
uint32_t result;
((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read();
((uint8_t *)&result)[2] = f.read();
((uint8_t *)&result)[3] = f.read(); // MSB
return result;
}


Allerdings wenn ich die Zugnummern erweitern möchte kann der Arduino das Bitmap nicht mehr von der SD Card lesen.
Was mache ich hier falsch??

Auch muss ich die Ausgabe noch in For Anweisung setzen.
Weis aber noch ncht wie.

Viele Grüße

Peter


Rothpe  
Rothpe
Regionalbahn (RB)
Beiträge: 27
Registriert am: 11.03.2018
Ort: Bad Marienberg
Spurweite H0
Stromart AC, Digital


RE: Bahnhofstafel mit Arduino

#15 von chaoskasi ( gelöscht ) , 09.12.2018 16:06

Hallo Leute
habe auch mal das Sketch zum Uno mit TFT Display gesendet bekomme aber die Meldung " class Adafruit_7735 " has no member named " Color565

Ich denke ich hab da was vergessen zu installieren !

gruß
Thomas


chaoskasi

   


  • Ähnliche Themen
    Antworten
    Zugriffe
    Letzter Beitrag
Xobor Einfach ein eigenes Forum erstellen
Datenschutz