Brendon Shaw
Active member
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 ?
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()
{
}