Hello,
I connected the VMA412 display and touch screen to the mega2560 board and i get a pale backlite display. The library i downloaded is not working apart from the serial display test which is showing random display coordinates that never stop. Is there a way to disable the spi interface ? I would be glad to give more documents and pics from the hardware and software i tried. Kind Regards , Joop.
Please tell us which library you've dowloaded.
Please provide a link to the display that you bought.
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.
The board was sold to me for arduino AND Mega2560 but now the 2560 has been removed..:=( and the seller wont give support on installation..
I downloaded the library ST7781Mega2560 from VMA412_code_and_library-update from the manufacturer site, dated from 08-12-2016.
This is the link to the board manufacturer. Where i downloaded the library mentioned before.
WPSH412:
2.8" TOUCHSCREEN VOOR ONTWIKKELBORD – Velleman – Wholesaler and developer of electronics]
"(VMA412: 2.8 INCH TOUCH SCREEN FOR UNO/MEGA DEVELOPMENT BOARD – Velleman – Wholesaler and developer of electronics)"
This is a link to the ATMega2560 seller company :
"https://whadda.com/product/arduino-mega2560-rev3-ard-a000067/"
Thanks for the link to your display.
-
Install MCUFRIEND_kbv library via the IDE Library Manager.
-
Plug the Shield into your MEGA2560
-
Run all of the library examples.
-
Report back with success (or problems)
David.
p.s. if you have previously installed a library manually it is wise to remove that directory before re-installing properly via the IDE Library Manager.
Pls. tell me what version of IDE i need to install: 1 or 2.0 ?
If I go to https://www.arduino.cc/en/software it shows v1.8.19
The IDE Library Manager has been present for several years. It approves, installs, updates third party libraries. Most importantly it fetches libraries from a known repository and installs them to the correct place on your PC.
Most sketches and libraries will work with all versions of the IDE. I would never install "a nightly build". There is no need to jump to the "very latest" version. Just keep to a "recent" version unless there is a good reason to change.
Oh, I have never seen v2.0.x. I am sure that it "works". I would wait for a few months until other readers have used it for a while.
David.
I installed version 1 again (version 1.6.13) from scratch and deleted all old libraries and downloaded both fresh mcufriend library 3.0.0 and the adafruit-gfx library 1.11.3
when i tried to upload 1 of the test programs it was uploaded correctly but when i tried to run it i got the message:
error at compiling for board Arduino Mega or MEGA2560.
In the mean time i got a scrolling timestamp on /dev/cu.usbmodem FA141 (at 9600 baud speed) and the display is milky white with backlite on.
this happens to most tests i did,
With exception of :
Diagnose test pins : OK (24 and 31)
LCD_ID: Read 02 : ILI9327, Reg. 61-63 - RD-ID 1-3 : HX8347-G , Reg 64-66 - RD-ID 1-3 : HX8347- A.
LCD read reg : OK
I saw when compiler error occurred often an error msg : ADA-fruit_I2CDevice.h no such file or directory?????
Then i checked without the display a simple program: led on / off 1 sec. on pin 10, which compiled and worked ok.
The test is made via a USB cable from my iMac with OSX El Capitan v. 10.11.6 directly to the board of MEGA 2680
If i need to change any of the versions pls. let me know what is recommended for both IDE and the library versions and other software
Why not 1.8.19?
You seem to have some confusion. First you say that it uploaded succesfully which means that you loaded the sketch in the IDE, were able to verify (compile) it and load it on your board. Next you say ""try to run it" you get the "error compiling for board". So what does "run"mean for you?
That means that you haven't installed that library; it might be required by your sketch or by the Afafruit-gfx library. You will need to install it (preferably using the library manager, IDE menu sketch -> include library -> manage libraries).
==
Notes:
- You can scroll through the IDE's output window (the black Window) to check the error messages.
- I'm not sure if IDE 1.6.13 has the button to copy error messages, if not you can select all text in the output window, copy it and post it here using code tags (use the
</>
button).
If you are running v1.6.13 of the IDE you are due for a change. I did not expect such an old version.
I suggest that you install v1.8.19.
Actually, MCUFRIEND_kbv and Adafruit_GFX should work with pretty well anything.
However Adafruit load up a whole tranche of unused classes. It is these that might give problems with "old" IDE versions. e.g. the Adafruit_I2C problems
Please do not "download" manually. The modern IDEs contain a proper "Library Manager".
When you have installed IDE v1.8.19 you can use the Library Manager to look after libraries.
I am not familiar with MAC. Just like anything else: You don't need to be "cutting edge" but I strongly recommend that your software is not more than 12 months "out of date".
I am intrigued. I would expect your Shield to work 100%.
i.e. plug Shield into MEGA2560 as Nature intended.
i.e. connect MEGA2560 to the IMac with its USB cable.
If you still have a problem, run LCD_ID_readreg.ino
Copy-Paste from the Serial Terminal to your message.
David.
p.s. copy-paste from any of the examples can be useful.
A manually typed description requires a lot more thought and care.
I always advise making notes on paper before manually typing up your message.
Obe last question if i may, ( currently running IDE 1.8.18 ) Is there a way to get the SdFat program to run correctly ? I have a shield with which i can make a connection to alternate pins so that i can use a sd disk ? Do i have to rewire or redefine the SD chip select pin 53 in SD_CS_PIN or is it a no go with mega 2560 board? It would be great if i could use sd on board images to call to.
The other functions are all running now
Your descriptions in #9 made no sense at all. If you want to refer to a library example just quote the example name.
That makes no sense either.
You can say things like: "Ran ALL examples. ALL worked"
Or "Ran all examples. example123.ino did NOT work"
Or "Ran all examples EXCEPT example456.ino"
You have a regular Mcufriend Shield. It plugs into your Uno, Leo, Zero, Due, Mega2560, ...
All examples should work the same except for SD card sketches.
The SD card on the Shield uses pins D10, D11, D12, D13 which only suits the Uno.
e.g. showBMP_kbv_Uno.ino for the Uno uses Hardware SPI pins
e.g. showBMP_not_Uno.ino for the Mega2560
Hence you have to use Software SPI with the non-Uno boards to read SD disk on non-hardware pins. Instructions are in the example sketch.
If you have a separate SD card module you can plug it into the D50-D53 on your Mega2560. Edit showBMP_kbv_Uno.ino to use D53 for SD_CS. Regular SD programs should work.
The Mega2560 has SPI pins on the 18x2 header socket as well as the 3x2 header.
The other non-Uno boards only have SPI on the 3x2 header. So you need an IDC ribbon cable to access the 3x2 when the Shield is plugged in.
David.
Hi David,
I hope that my mail is getting "more to the point"
Your hint for using "showBMP_not_Uno" worked :=)
I can read bitmaps from the sd card now without additional wiring necessary
I only get 1 error msg when uploading the sketch, which follows here:
C:\Users\Joop\AppData\Local\Temp\arduino_modified_sketch_772663\showBMP_not_Uno.ino: In function 'void loop()':
C:\Users\Joop\AppData\Local\Temp\arduino_modified_sketch_772663\showBMP_not_Uno.ino:72:14: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
if (f != NULL) {
^~~~
Sketch uses 41384 bytes (16%) of program storage space. Maximum is 253952 bytes.
Global variables use 1213 bytes (14%) of dynamic memory, leaving 6979 bytes for local variables. Maximum is 8192 bytes.
It does not influence the working of the display card and /or the SD card
I still use IDE version 1.8.18
P.S.
Following here is the contents of the sketch:
// MCUFRIEND UNO shields have microSD on pins 10, 11, 12, 13
// The official <SD.h> library only works on the hardware SPI pins
// e.g. 11, 12, 13 on a Uno
// e.g. 50, 51, 52 on a Mega2560
// e.g. 74, 75, 76 on a Due
//
// if you are not using a UNO, you must use Software SPI:
//
// NEW: install <SdFat.h> v2.x.x library with the Arduino Library Manager
// NEW: edit the src/SdFatConfig.h file to #define SPI_DRIVER_SELECT 2
//
// OBSOLETE SdFat v1.x.x uses a different system
// OBSOLETE v1.x.x SdFatConfig.h: #define ENABLE_SOFTWARE_SPI_CLASS 1
// OBSOLETE: SdFatSoftSpi<12, 11, 13> SD; //Bit-Bang on the Shield pins SDFat.h v1
// OBSOLETE: #define SD_CS 10
//
// copy all your BMP files to the root directory on the microSD with your PC
// (or another directory)
#include <SPI.h> // f.k. for Arduino-1.5.2
#define USE_SDFAT
#include <SdFat.h> // Use the SdFat library
#if SPI_DRIVER_SELECT != 2
#error edit SdFatConfig.h . READ THE SKETCH INSTRUCTIONS
#endif
SoftSpiDriver<12, 11, 13> softSpi; //Bit-Bang on the Shield pins SDFat.h v2
SdFat SD;
#define SD_CS SdSpiConfig(10, DEDICATED_SPI, SD_SCK_MHZ(0), &softSpi)
#include <Adafruit_GFX.h> // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define NAMEMATCH "" // "" matches any name
//#define NAMEMATCH "leeuw" // leeuw.bmp
#define PALETTEDEPTH 8 // support 256-colour Palette
char namebuf[32] = "/"; //BMP files in root directory
//char namebuf[32] = "/bitmaps/"; //BMP directory e.g. files in /bitmaps/*.bmp
File root;
int pathlen;
void setup()
{
uint16_t ID;
Serial.begin(9600);
Serial.print("Show BMP files on TFT with ID:0x");
ID = tft.readID();
Serial.println(ID, HEX);
if (ID == 0x0D3D3) ID = 0x9481;
tft.begin(ID);
tft.fillScreen(0x001F);
tft.setTextColor(0xFFFF, 0x0000);
bool good = SD.begin(SD_CS);
if (!good) {
Serial.print(F("cannot start SD"));
while (1);
}
root = SD.open(namebuf);
pathlen = strlen(namebuf);
}
void loop()
{
char *nm = namebuf + pathlen;
File f = root.openNextFile();
uint8_t ret;
uint32_t start;
if (f != NULL) {
#ifdef USE_SDFAT
f.getName(nm, 32 - pathlen);
#else
strcpy(nm, (char *)f.name());
#endif
f.close();
strlwr(nm);
if (strstr(nm, ".bmp") != NULL && strstr(nm, NAMEMATCH) != NULL) {
Serial.print(namebuf);
Serial.print(F(" - "));
tft.fillScreen(0);
start = millis();
ret = showBMP(namebuf, 5, 5);
switch (ret) {
case 0:
Serial.print(millis() - start);
Serial.println(F("ms"));
delay(5000);
break;
case 1:
Serial.println(F("bad position"));
break;
case 2:
Serial.println(F("bad BMP ID"));
break;
case 3:
Serial.println(F("wrong number of planes"));
break;
case 4:
Serial.println(F("unsupported BMP format"));
break;
case 5:
Serial.println(F("unsupported palette"));
break;
default:
Serial.println(F("unknown"));
break;
}
}
}
else root.rewindDirectory();
}
#define BMPIMAGEOFFSET 54
#define BUFFPIXEL 20
uint16_t read16(File& f) {
uint16_t result; // read little-endian
f.read(&result, sizeof(result));
return result;
}
uint32_t read32(File& f) {
uint32_t result;
f.read(&result, sizeof(result));
return result;
}
uint8_t showBMP(char *nm, int x, int y)
{
File bmpFile;
int bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24, 16, 8, 4, 1)
uint32_t bmpImageoffset; // Start of image data in file
uint32_t rowSize; // Not always = bmpWidth; may have padding
uint8_t sdbuffer[3 * BUFFPIXEL]; // pixel in buffer (R+G+B per pixel)
uint16_t lcdbuffer[(1 << PALETTEDEPTH) + BUFFPIXEL], *palette = NULL;
uint8_t bitmask, bitshift;
boolean flip = true; // BMP is stored bottom-to-top
int w, h, row, col, lcdbufsiz = (1 << PALETTEDEPTH) + BUFFPIXEL, buffidx;
uint32_t pos; // seek position
boolean is565 = false; //
uint16_t bmpID;
uint16_t n; // blocks read
uint8_t ret;
if ((x >= tft.width()) || (y >= tft.height()))
return 1; // off screen
bmpFile = SD.open(nm); // Parse BMP header
bmpID = read16(bmpFile); // BMP signature
(void) read32(bmpFile); // Read & ignore file size
(void) read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data
(void) read32(bmpFile); // Read & ignore DIB header size
bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile);
n = read16(bmpFile); // # planes -- must be '1'
bmpDepth = read16(bmpFile); // bits per pixel
pos = read32(bmpFile); // format
if (bmpID != 0x4D42) ret = 2; // bad ID
else if (n != 1) ret = 3; // too many planes
else if (pos != 0 && pos != 3) ret = 4; // format: 0 = uncompressed, 3 = 565
else if (bmpDepth < 16 && bmpDepth > PALETTEDEPTH) ret = 5; // palette
else {
bool first = true;
is565 = (pos == 3); // ?already in 16-bit format
// BMP rows are padded (if needed) to 4-byte boundary
rowSize = (bmpWidth * bmpDepth / 8 + 3) & ~3;
if (bmpHeight < 0) { // If negative, image is in top-down order.
bmpHeight = -bmpHeight;
flip = false;
}
w = bmpWidth;
h = bmpHeight;
if ((x + w) >= tft.width()) // Crop area to be loaded
w = tft.width() - x;
if ((y + h) >= tft.height()) //
h = tft.height() - y;
if (bmpDepth <= PALETTEDEPTH) { // these modes have separate palette
//bmpFile.seek(BMPIMAGEOFFSET); //palette is always @ 54
bmpFile.seek(bmpImageoffset - (4<<bmpDepth)); //54 for regular, diff for colorsimportant
bitmask = 0xFF;
if (bmpDepth < 8)
bitmask >>= bmpDepth;
bitshift = 8 - bmpDepth;
n = 1 << bmpDepth;
lcdbufsiz -= n;
palette = lcdbuffer + lcdbufsiz;
for (col = 0; col < n; col++) {
pos = read32(bmpFile); //map palette to 5-6-5
palette[col] = ((pos & 0x0000F8) >> 3) | ((pos & 0x00FC00) >> 5) | ((pos & 0xF80000) >> 8);
}
}
// 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).
uint8_t r, g, b, *sdptr;
int lcdidx, lcdleft;
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; ) { //pixels in row
lcdleft = w - col;
if (lcdleft > lcdbufsiz) lcdleft = lcdbufsiz;
for (lcdidx = 0; lcdidx < lcdleft; lcdidx++) { // buffer at a time
uint16_t color;
// Time to read more pixel data?
if (buffidx >= sizeof(sdbuffer)) { // Indeed
bmpFile.read(sdbuffer, sizeof(sdbuffer));
buffidx = 0; // Set index to beginning
r = 0;
}
switch (bmpDepth) { // Convert pixel from BMP to TFT format
case 32:
case 24:
b = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
if (bmpDepth == 32) buffidx++; //ignore ALPHA
color = tft.color565(r, g, b);
break;
case 16:
b = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];
if (is565)
color = (r << 8) | (b);
else
color = (r << 9) | ((b & 0xE0) << 1) | (b & 0x1F);
break;
case 1:
case 4:
case 8:
if (r == 0)
b = sdbuffer[buffidx++], r = 8;
color = palette[(b >> bitshift) & bitmask];
r -= bmpDepth;
b <<= bmpDepth;
break;
}
lcdbuffer[lcdidx] = color;
}
tft.pushColors(lcdbuffer, lcdidx, first);
first = false;
col += lcdidx;
} // end cols
} // end rows
tft.setAddrWindow(0, 0, tft.width() - 1, tft.height() - 1); //restore full screen
ret = 0; // good render
}
bmpFile.close();
return (ret);
}
(If you like i can sent the contents of the include hex files too, pls let me know.)
Can you please edit your post #14, select all code and click the</>
button to apply code tags; next save your post. It makes it easier to read and copy and prevents the forum software from mangling it.
Please do NOT paste "library examples".
Start with the example. Quote it by name.
If you make some edits. Copy-paste only the "changed statements".
Looking on GitHub. Line #72 says
switch (ret) {
but line #58 says.
if (f != NULL) {
Anyway, the message is a warning. Technically you should say
if (f != 0) {
Sorry to sound picky. I don't want to read through all of your pasted code just to find one edit. When you could have told me the edit in the first place.
David.
Sorry for that.... i am trying to do better next time, And i was not aware that i made any edit in it.
Have a nice weekend!
Please send me an example. When i use the > or < key the text line disappears :=(
Simple answer is: "run the all library examples"
Copy-Paste is a standard technique on any PC.
Copy-Paste to a Forum message is straightforward.
If you use the "</>" icon the text is safe. (6th icon from the left)
If you paste directly to the message it interprets "[" and spaces differently. i.e. it ruins code.
Read the Forum Instructions. If you are unsure of some English words just ask. You seem to be pretty good with English.
Yes, all Forums are annoying. You just have to live with this. But we are fairly good at solving reader's problems even if we seem a bit grumpy at times.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.