Closed hicksan closed 3 years ago
I got this to work in the end.
Problem 1: The esp8266 has to be introduced as a different board type in the 'board manager' on the Arduino IDE. What it doesn't tell you is that this brings in a whole different set of standard libraries - like its own versions of SD.h and SdFat.h. Arduino is smart and when it encounters multiple libraries with the same name it will try to choose the most appropriate one. So if it know you are using an "esp8266" processor it will give preference to one in an "esp8266..." directory. But not if the directory is named "ESP8266SDFAT". in that instance it reverts to the Arduino standard Sd / SdFat library - and all kinds of compatability compile errors get thrown at you.
Two possible solutions:
Problem 2: My SD card still hogs the SPI bus and conflicts with the ST7920 display. I noticed that esp8266 cards are helpfully labelled with two sets of SPI pins. Sets 11-13 and 5-7. So I thought putting the Sd card reader on 11-13 and the ST7920 on 5-7 would solve this up front. It didn't; they still conflicted - whichever is active locks the other out.
I solved this by moving the ST7920 display onto other non-SPI pins. In this case I set CLK as D4 and MOSI as D3. I left CS as D10. After editing the constructor accordingly - it all worked fine.
I hope this helps somebody.
Thanks for reporting. :+1:
Unfortunately I really need to use those extra pins because the ESP8266 has so few. I have invested in a more expensive SD card reader so the ST7920 and the SD and other devices can share the SPI bus. Unfortunately this hasn't worked. The bus locking is no longer the issue but I have discovered that LoadFromSD demo program doesn't work: every time u8g2.begin() is called it stops the SD from working and every time SD.begin(D10) is called it stops the ST7920. By using lots of extra .begin statements I got it partly to work, but then I found: (1) the drawFile() subroutine is within a u8g2 page write process which then gets interrupted (2) any drawStr or drawPixel command causes the output to revert to random Chinese characters. It looks to me like an array somewhere is overflowing, and I cannot get this example to work. I am using the Neu Rah Arduino menu system, which relies on this library and uses these draw commands.
It you share pins between sd card and display, then you MUST use the HW_SPI constructor from U8g2. In you initial example you have used the SW_SPI constructor. Using the HW_SPI constructor is a precondition to make it work. However, even then it may not work, because display and sdcard may require different speed. It might be required to set the bus speed (u8g2.setBusClock()) manually every time you want to access your display.
IT WORKED PERFECTLY. Both this test sketch and my actual working sketch. Just by changing the constructor line from SW to HW and removing software pin references. Thank you so much. You are an amazing and wonderful person, Oliver. Thankyouthankyouthankyou.
Don't use ST7920 with other devices on the same SPI bus. The ST7920s CS pin is broken by design. See datasheet page 26 paragraph 2.
It's working fine for me with an ST7920, SD card reader and MCP2515 all sharing the same SPI bus.
Your document link crashed two browsers though, lost all my open pages and triggered lots of virus warnings from my firewall.
I am trying to run the loadFromSD demo sketch with an ESP8266 connected to as ST7920 LCD and an Sd card.
I have the display on pins D5 (CLK), D7 (MOSI) and D10 (CS) with the following constructor: U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, D5, D7, D10, U8X8_PIN_NONE);
I ran your Graphics Test sketch with just the ST7920 on the ESP8266 and it ran perfectly with this constructor.
I have the SD card connected to pins D11 (MOSI) , D12 (MISO), D13 (CLK) and D9 (CS). I call it with SD.begin(D9); as per your demo sketch. I am assuming it will go to these pins as the SPI hardware defaults, as per an UNO.
The ST7920 and SD card are on separate SPI busses because, as I already discovered when I tried this with the Mega, the SD card reader is wired wrongly and cannot share an SPI bus with any other device. This setup
worked fine with the Mega, but I am now trying it on an ESP8266 for other reasons.
The problem is it won't compile. I get loads of error messages relating to "multiple SD.h libraries" and stuff about SdFat that I am not even using, relating to a library in the area: ...\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\SDFS\src/SDFS.h
Any idea what I am doing or haven't done that might be causing this? The sketch in question is basically your demo sketch since I am just testing the hardware compatibility.
I attach the file below: