Teensy 3.1 SPI, U8Glib and SDfat

Status
Not open for further replies.

arduvfr

New member
I'm using a Teensy 3.1 along with a SPI based SD card using SDfat and a SPI based OLED display using U8Glib on the same SPI bus (with separate SS/CS lines). So far, each one works by itself, but both together do not work.

HELP me ?

code
#include*"U8glib.h"
#include*<SPI.h>
#include*<SdFat.h>
U8GLIB_ST7920_128X64_4X*u8g(13,*11,*10,U8G_PIN_NONE);
File root;
SdFat*sd;
SdFile*myFile;

void draw1(void) {
**u8g.setFont(u8g_font_unifont);
**u8g.drawStr(*0,*22,*"Hello!");
}

void draw2(void) {
**// graphic commands to redraw the complete screen should be placed here
**u8g.setFont(u8g_font_unifont);
**// u8g.setFont(u8g_font_osb21);
**u8g.drawStr(*0,*22,*"ok");
}


void setup() {
**Serial.begin(9600);
**while (!Serial) {
****;*// wait for serial port to connect.
**}

**u8g.setColorIndex(1);
**u8g.firstPage();**
**do {
****draw1();
**}*
**while( u8g.nextPage() );

**pinMode(10, OUTPUT);
**pinMode(9, OUTPUT);

**if (!sd.begin(9)) {
****Serial.println("initialization failed!");
****return;
**}
**Serial.println("initialization done.");

**delay(1000);


}

void loop(void) {
**// loop
**delay(1000);

**// open the file for write at end like the Native SD library
**if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
****sd.errorHalt("opening test.txt for write failed");
**}
**// if the file opened okay, write to it:
**Serial.print("Writing to test.txt...");
**myFile.println("testing 1, 2, 3.");

**// close the file:
**myFile.close();
**Serial.println("done.");

**delay(1000);
**u8g.firstPage();**
**do {
****draw2();
**}*
**while( u8g.nextPage() );
**delay(1000);

**// re-open the file for reading:
**if (!myFile.open("test.txt", O_READ)) {
****sd.errorHalt("opening test.txt for read failed");
**}
**Serial.println("------------");
**Serial.println("test.txt:");

**// read from the file until there's nothing else in it:
**int data;
**while ((data = myFile.read()) >= 0) {
****Serial.write(data);
**}
**// close the file:
**myFile.close();

}
 
Status
Not open for further replies.
Back
Top