ESP32 - CYD/Cheap Yellow Display: serieller Port P5

OP Persönliche Seite #7818162
Lesenswert?

Hallo, ich habe hier ein CYD mit 2 USB Ports ("CYD2USB"). Dieses hat einen Anschluss P5 wo die RX0/TX0 Pins herausgeführt sind. Leider bekomme ich keine Daten über den RX Pin.

Zum Testen verwende ich ein GPS-Modul, welches 3,3V serielle Daten mit 9600bps ausgibt.

Ich habe den Beispielsketch "TFT_Terminal" von der TFT_eSPI lib geflasht (Code ist am Ende des Posts). Der Sketch funktioniert einwandfrei mit den Pins 22 und 27 Über den CN1 Anschluss.

Jetzt könnte jemand meinen, dass es gar nicht funktionieren kann, da die RX0/TX0 Pins auch auf den CH340 gehen. Jedoch: ich habe Testweise die ESP32 Marauder Firmware geflasht (https://github.com/Fr4nkFletcher/ESP32-Marauder-Cheap-Yellow-Display).

Bei absolut identischem Aufbau erkennt Marauder das GPS und gibt auch die NMEA Daten aus - es muss also ein Softwareproblem sein!

Hat irgendjemand schonmal den P5 für serielle Daten benutzt? Was hab ich übersehen?

1
/*************************************************************
2
  This sketch implements a simple serial receive terminal
3
  program for monitoring serial debug messages from another
4
  board.
5
  
6
  Connect GND to target board GND
7
  Connect RX line to TX line of target board
8
  Make sure the target and terminal have the same baud rate
9
  and serial settings!
10

11
  The sketch works with the ILI9341 TFT 240x320 display and
12
  the called up libraries.
13
  
14
  The sketch uses the hardware scrolling feature of the
15
  display. Modification of this sketch may lead to problems
16
  unless the ILI9341 data sheet has been understood!
17

18
  Updated by Bodmer 21/12/16 for TFT_eSPI library:
19
  https://github.com/Bodmer/TFT_eSPI
20
  
21
  BSD license applies, all text above must be included in any
22
  redistribution
23
 *************************************************************/
24

25
#include <TFT_eSPI.h> // Hardware-specific library
26
#include <SPI.h>
27

28
TFT_eSPI tft = TFT_eSPI();       // Invoke custom library
29

30
// The scrolling area must be a integral multiple of TEXT_HEIGHT
31
#define TEXT_HEIGHT 16 // Height of text to be printed and scrolled
32
#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
33
#define TOP_FIXED_AREA 16 // Number of lines in top fixed area (lines counted from top of screen)
34
#define YMAX 320 // Bottom of screen area
35

36

37
//#define RXD 3
38
//#define TXD 1
39
#define RXD 22
40
#define TXD 27
41

42

43
// The initial y coordinate of the top of the scrolling area
44
uint16_t yStart = TOP_FIXED_AREA;
45
// yArea must be a integral multiple of TEXT_HEIGHT
46
uint16_t yArea = YMAX-TOP_FIXED_AREA-BOT_FIXED_AREA;
47
// The initial y coordinate of the top of the bottom text line
48
uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
49

50
// Keep track of the drawing x coordinate
51
uint16_t xPos = 0;
52

53
// For the byte we read from the serial port
54
byte data = 0;
55

56
// A few test variables used during debugging
57
bool change_colour = 1;
58
bool selected = 1;
59

60
// We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds
61
// for a full width line, meanwhile the serial buffer may be filling... and overflowing
62
// We can speed up scrolling of short text lines by just blanking the character we drew
63
int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
64

65
void setup() {
66
  // Setup the TFT display
67
  tft.init();
68
  tft.setRotation(0); // Must be setRotation(0) for this sketch to work correctly
69
  tft.fillScreen(TFT_BLACK);
70
  
71
  // Setup baud rate and draw top banner
72
//  Serial.begin(9600);
73

74
  Serial2.begin(9600, SERIAL_8N1, RXD, TXD);
75
  
76
  tft.setTextColor(TFT_WHITE, TFT_BLUE);
77
  tft.fillRect(0,0,240,16, TFT_BLUE);
78
  tft.drawCentreString(" Serial Terminal - 9600 baud ",120,0,2);
79

80
  // Change colour for scrolling zone text
81
  tft.setTextColor(TFT_GREEN, TFT_BLACK);
82

83
  // Setup scroll area
84
  setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
85

86
  // Zero the array
87
  for (byte i = 0; i<18; i++) blank[i]=0;
88
}
89

90

91
void loop(void) {
92
  //  These lines change the text colour when the serial buffer is emptied
93
  //  These are test lines to see if we may be losing characters
94
  //  Also uncomment the change_colour line below to try them
95
  //
96
  //  if (change_colour){
97
  //  change_colour = 0;
98
  //  if (selected == 1) {tft.setTextColor(TFT_CYAN, TFT_BLACK); selected = 0;}
99
  //  else {tft.setTextColor(TFT_MAGENTA, TFT_BLACK); selected = 1;}
100
  //}
101

102
  while (Serial2.available()) {
103
    data = Serial2.read();
104
    // If it is a CR or we are near end of line then scroll one line
105
    if (data == '\r' || xPos>231) {
106
      xPos = 0;
107
      yDraw = scroll_line(); // It can take 13ms to scroll and blank 16 pixel lines
108
    }
109
    if (data > 31 && data < 128) {
110
      xPos += tft.drawChar(data,xPos,yDraw,2);
111
      blank[(18+(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT)%19]=xPos; // Keep a record of line lengths
112
    }
113
    //change_colour = 1; // Line to indicate buffer is being emptied
114
  }
115
}
116

117
// ##############################################################################################
118
// Call this function to scroll the display one text line
119
// ##############################################################################################
120
int scroll_line() {
121
  int yTemp = yStart; // Store the old yStart, this is where we draw the next line
122
  // Use the record of line lengths to optimise the rectangle size we need to erase the top line
123
  tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT],TEXT_HEIGHT, TFT_BLACK);
124

125
  // Change the top of the scroll area
126
  yStart+=TEXT_HEIGHT;
127
  // The value must wrap around as the screen memory is a circular buffer
128
  if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA + (yStart - YMAX + BOT_FIXED_AREA);
129
  // Now we can scroll the display
130
  scrollAddress(yStart);
131
  return  yTemp;
132
}
133

134
// ##############################################################################################
135
// Setup a portion of the screen for vertical scrolling
136
// ##############################################################################################
137
// We are using a hardware feature of the display, so we can only scroll in portrait orientation
138
void setupScrollArea(uint16_t tfa, uint16_t bfa) {
139
  tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition
140
  tft.writedata(tfa >> 8);           // Top Fixed Area line count
141
  tft.writedata(tfa);
142
  tft.writedata((YMAX-tfa-bfa)>>8);  // Vertical Scrolling Area line count
143
  tft.writedata(YMAX-tfa-bfa);
144
  tft.writedata(bfa >> 8);           // Bottom Fixed Area line count
145
  tft.writedata(bfa);
146
}
147

148
// ##############################################################################################
149
// Setup the vertical scrolling start address pointer
150
// ##############################################################################################
151
void scrollAddress(uint16_t vsp) {
152
  tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer
153
  tft.writedata(vsp>>8);
154
  tft.writedata(vsp);
155
}
Angehängte Dateien:
OP Persönliche Seite #7818433
Lesenswert?

Marc V. schrieb:

Marko ⚠. schrieb:

Hat irgendjemand schonmal den P5 für serielle Daten benutzt? Was hab ich übersehen?

Du hast die richtigen Pins übersehen. RxD2 ist Arduino Pin 25 (GPIO16), nicht 22.

Im Anhang ist eine Übersicht zu dem Board. Meine Version ist allerdings eine etwas neuere, das Foto stimmt also nicht zu 100%. P1 ist bei mir P5 und CN1 hat die IOs 22 und 27.

Den UART2 kann man beliebigen Pins zuweisen. In diesem Fall lege ich den UART2 auf die Pins 22 und 27, welche an CN1 angeschlossen sind. Das funktioniert ja auch, das Resultat sieht man im 2. Foto.

Wenn ich den UART2 aber stattdessen an Pins 1 und 3 lege, wie es die Marauder-Firmware macht: https://github.com/Fr4nkFletcher/ESP32-Marauder-Cheap-Yellow-Display/blob/master/esp32_marauder/configs.h

1
      #define GPS_TX 1
2
      #define GPS_RX 3

Und schließe ich dann das GPS an P5 an, dann empfange ich mit meinem Sketch keine Daten. Dass es aber gehen muss weiss ich, denn mit Marauder geht es (s. 1. Foto).

Also:

o UART2 auf Pins 22 und 27 funktioniert mit meinem Sketch. o UART2 auf Pins 1 und 3 funktioniert mit Marauder. o UART2 auf Pins 1 und 3 funktioniert NICHT mit meinem Sketch.

Angehängte Dateien:
OP Persönliche Seite #7818967
Lesenswert?

Flip B. schrieb:

Der CH340 hat den RX fest im griff, dagegen kommt dein GPS-Modul nicht an.

Keine ahnung, ob man den TX des CH340 per Treibercommando deaktivieren kann, ansonsten Ch340 entlöten oder eine andere Schnittstelle nutzen.

Hatte ich zunächst auch gedacht, aber wieso funktioniert es dann mit der Marauder Firmware? (1. Post, cybserial1.jpg, GPS-Modul an P5 angeschlossen).

#7819020
Lesenswert?

Den USB Stecker abziehen damit der CH340 nicht mit Strom versorgt wird? Oder hat es mit Stecker auch mit 1/3 funktioniert?

Oder werden jetzt beide Serial auf 1/3 konfiguriert? Serial ohne Änderung verwenden statt Serial2, oder wenn Serial2, dann Serial auf andere Pins legen.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren