can BME280 share CS(digital10 pin) with Datalogger shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

can BME280 share CS(digital10 pin) with Datalogger shield

Post by mromero »

My project uses Adafruit's arduino Metro board and datalogger shield. It will have 2 CO2 sensors connected to arduino using a TCA9548A( I2C multiplexer) which use the arduino SCL and SDA pins. There is also 1 BME280 (T,RH and bar press)which i connected as in your example for SPI wiring usesing digital pins 10 thru 13.

My question is the code for the data logging shield also uses digital pin 10 for the SD cs line. Will this cause a problem? I have also seen in other projects that they use the connections below.

BME280 Arduino UNO
Vin 3.3V
SDA A4
SCL A5
GND GND


If I connect the BME280 as above will i still be able to use SCL and SDA pin in Metro for TCA9548A ?

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by neradoc »

Hi, each SPI device needs a separate CS pin. Any pin can be used as Chip Select as long as it is wired to the BNO's CS pin. If there is no SD card in the slot, you would be able use pin 10 for the BME280, but you can just pick a free pin.
You can also connect the BME to the I2C bus and use it with I2C, as long as its address is unique on the bus, or connect it to the multiplexer.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by dastels »

SPI devices can not share a select line. That how the processor chooses which device to communicate with.
For more information have a look at https://learn.adafruit.com/mcus-how-do-they-work/spi and https://learn.adafruit.com/mcus-how-do-they-work/i2c.

My choice would be to wire the BME280 for I2C use. It's easier and you don't need a select line. Also, you don't need SPI's higher speed for this. And, yes, you can have many devices on a single I2C bus as long as everything (in this case the mux, the CO2 sensors, and the BME280) has different addresses.

Dave

User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by mromero »

Thank you both.

I attemped to solder CS on the datalogger to pin 3 but that still failed. I think i will use your idea of running all sensors through I3C as the BME280 and MX with 2 CO2 sensors would be accessed through different addresses.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by dastels »

If you change the default CS pin, you need to change to code to reflect the change. You didn't mention if you did.

Dave

User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by mromero »

Yes i did account in the code for the pin change to 3.

Since no matter what i tried i could not get the sd card to respond correctly. I backtracked and tried the example sketch "CardInfo" with the chip select pin set 10 . It still failed

Tried it on a second metro + dataloguer shield but using the sd card and battery as first attempt and it also failed. Code use below but hard to believe two speratate sets of metro and datalogger shields would be bad. I also purchased the SD card from adafruit... will try to locate another one in the mean time.

Stupid question the card installs with the writing to the top correct?

Code: Select all

 // include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.println();
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    while (1);
  }

  Serial.print("Clusters:          ");
  Serial.println(volume.clusterCount());
  Serial.print("Blocks x Cluster:  ");
  Serial.println(volume.blocksPerCluster());

  Serial.print("Total Blocks:      ");
  Serial.println(volume.blocksPerCluster() * volume.clusterCount());
  Serial.println();

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("Volume type is:    FAT");
  Serial.println(volume.fatType(), DEC);

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;                           // SD card blocks are always 512 bytes (2 blocks are 1KB)
  Serial.print("Volume size (Kb):  ");
  Serial.println(volumesize);
  Serial.print("Volume size (Mb):  ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Gb):  ");
  Serial.println((float)volumesize / 1024.0);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by dastels »

You can see how it inserts here: https://www.adafruit.com/product/1141

Let's go back to the startr. You say you have " Adafruit's arduino Metro board". What board exactly?

Also, which version of the logging shield do you have? See https://learn.adafruit.com/adafruit-dat ... ve-1948732.

Dave

User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by mromero »

Dastel thanks.

that is the direction i installed the SD Card.

I have tried both the Metro 328 AT mega compatible and sparkfuns RedBoard arduino Uno boards.
Both of the datalogger shields are the R3 compatible (newer model)

I am trying to see if the boards are good( only brought 2 of the 4 purchased home for testing) on neither one of the will the " cardinfo" example sketch, set to pin10 show a working SD Card. I use a preformatted 8GB SD card purchased from adafruit but I keep getting the error:

" 11:11:06.079 Initilizing SD card... initialization failed. Things to check:"

I tried a second SD card i had around and did not even check if formatted but got:

"11:06:42.560 Initializing SD card... Wiring is correct and a card is present
11:06:43.560 Card type: SD1
11:06:43.860 Could not find FAT16/FAT32 partition."

I am using a windows 10 machine and tried using quick format from the files menu but after that it gave the error message again.

I tested if i could write and read a file from the sd cards after the quick format described above and i could but keep getting the initialization failed error when i use them on the datalogging shield.

If someone can see what im missing i have been researching and fighting with this for 2 whole days now.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: can BME280 share CS(digital10 pin) with Datalogger shield

Post by dastels »

You're hardware should be fine. You followed the guides to the letter?

It sounds like a connection problem. But it could be a library issue. Make sure all your libraries are up to date.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”