Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy with BLE and OLED muliple SPI devices - display not working

  1. #1

    Teensy with BLE and OLED muliple SPI devices - display not working

    I have two projects which I would like to merge together, 1) Adafruit BLE nRD8001 2) 0.96" OLED display. Both boards wired to the Teensy work fine, with code sketches work fine but when I merge the sketch (see below) the display shows random text. Both boards are SPI and have chip select pins, so I would have thought it would be possible to share the SPI bus for multiple devices.

    The connections
    BLE nRD8001 Teensy
    SCK Pin 13
    MISO Pin 12
    MOSI Pin 11
    REQ Pin 10
    RDY Pin 2
    ACT n/c
    RST Pin 9


    OLED Teensy
    SCK Pin 13
    MOSI Pin 11
    D/C Pin 0
    Res Pin 1
    C/S Pin 6

    I am just wondering if any knows what could be the problem or how to fix this issues with multiple SPI devices ?

    Code:
    #include <SPI.h>
    #include "Adafruit_BLE_UART.h"
    #include "IOSControllerTeensyForBluefruit.h"
    #include <Wire.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    #include <SoftwareSerial.h>
    
    float temperature;
    float light;
    float sound;
    float co2;
    int pressure;
    int humidity;
    int STATE_MC;
    
    String inputString = "";         // a string to hold incoming data
    
    /*
     *
     * Prototypes of IOSControllerTeensyForBluefruit’s callbacks
     *
     *
     */
    void doWork();
    void doSync(char *variable);
    void processIncomingMessages(char *variable, char *value);
    void processOutgoingMessages();
    void deviceConnected();
    void deviceDisconnected();
    
    #define OLED_DC     0     // Arduino micro PB6  - Teensy Pin 0
    #define OLED_RESET  1     // Arduinio micro PB7 - Teensy Pin 1
    #define OLED_CS     6     // - Teensy Pin 
    
    Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
    
    IOSControllerTeensyForBluefruit iosController(&doWork,&doSync,&processIncomingMessages,&processOutgoingMessages,&deviceConnected,&deviceDisconnected); 
     
    void setup()
    {
      STATE_MC = 0;
      Serial.begin(9600);
      Serial.print("start up");
      delay(100);
      // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
      display.begin(SSD1306_SWITCHCAPVCC);
      display.clearDisplay(); 
    }
    
    void loop() 
    {
      
      iosController.loop();
    
     }
    
    
    
    void doWork() 
    {
      float random_value;
    
    STATE_MC++; 
     if(STATE_MC == 10)
    {
        STATE_MC = 0;
        display.clearDisplay(); 
    
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println("Setup");
    
        display.setTextSize(0);
        display.setCursor(0,10);
        display.println(temperature);
        display.println(STATE_MC);
        display.display();
      }
    
      random_value = random(0,100);
      random_value = random_value / 100;
      temperature = 22 + random_value;
    
      random_value = random(0,5);
      co2 = 644 + random_value;
    
      random_value = random(0,1);
      light = 537 + random_value;
      random_value = random(0,100);
      random_value = random_value / 100;
      light = light + random_value;
      
      
      random_value = random(0,20);
      sound = 10 + random_value;
    
      pressure = 1006;
      humidity = 56;
      
      delay(1000);
    
      
    }
    
    void doSync(char *variable) 
    {
      
      
      
    }
    
    void processIncomingMessages(char *variable, char *value) 
    {
      
      
      
    }
    
    void processOutgoingMessages() {
      
      //Serial.println("Outgoing");
      
      iosController.writeMessage("Temp",temperature);
      iosController.writeMessage("co2",co2);
      iosController.writeMessage("Light",light);
      iosController.writeMessage("Sound",sound);
      iosController.writeMessage("Pressure",pressure);
      iosController.writeMessage("Humidity",humidity);
      
    }
    
    void deviceConnected() {
      
      
    
    }
    
    void deviceDisconnected() 
    {
    
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,473
    My first guess is Adafruit_SSD1306 probably doesn't use SPI transactions.

    As a quick hack, you might try calling SPI.beginTransaction() before using any display function, and SPI.endTransaction() afterwards.

  3. #3
    Paul, you are a superstar fixed the issue. Still do not trust the display driver so something to fixed properly for the future. Many thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •