In a previous atricle I mentioned, that I want to store sensor data on a SD card. I couldn't do that, because I used the Catalex SD card module on the SPI bus. But this module blocks the bus for other devices, so I couldn't use any other SPI device.
After some (many) research and trouble shooting it's finally working. For everyone, who has the same problem (that the catalex module blocks the bus), here's the solution.
My idea: I want to use two Arduinos, one as transmitter, oner as receiver. The data is the temperature of a room, which is measured with DS18B20 sensors. Those data is then sent via the NRF24L01+ wireless module to the receiver. Afterwards the temperture will be displayed on an I2C display, and it will be stored on the catalex sd card mofule.
The reason why I'm pushing that much effort into that project is, because the the catalex module (v1.0) blocks the SPI bus. This is due to the SN74LVC125A logiv level shifter module. It has the necesarry pins to NOT block the bus, but those are all soldered to ground somehow. Now the only way to use that device with other SPI devices is to put it on the software SPI bus. That way you create a second SPI bus on the Arduino (which costs many pins in total).
The setup needs, besides the modules, some other parts.
|1||Arduino||Uno or Nano|
* ignore the button!
|1||Arduino||Uno or Nano|
|1||SD Card Reader||Catalex v1.0|
The program's on GitHub.
Before you can upload the code on your Arduino, you're going to need some libraries. All necesarry libs are on GitHub in the folder called 'Libraries'.
The Catalex SD card module is connected to the SoftSPI-bus. That an immitation of the hardware SPI-bus and can be set to every pin you want. Therefor you have to edit the SdFat-library: The SdFatConfig file. Change the line 81 to ...
#define SD_SPI_CONFIGURATION 3 (Standard 1)
I've done this already in the file, so you just have to add the library to your Arduino libraries.
The transmitter takes the data from the temperature sensor and sends it via the RF24 to the receiver. For more information please refer to the above shown links.
The data will be received and printed to the display. To store them on the SD card, you have to call the text file the follwoing way:
file.open("Temp.txt", O_WRITE | O_CREAT | O_AT_END);
The first attribute gives the file name, the second one the type of access:
- O_WRITE: Writing, not reading.
- O_CREAT: If the file doesn't exist, it will be created.
- O_AT_END: The program writes at the end of the file, otherwise the date will be overwritten.
At the beginning you have to define, where the SPI-bus is placed. You can see this in line 55:
const uint8_t SOFT_MISO_PIN = 4; const uint8_t SOFT_MOSI_PIN = 5; const uint8_t SOFT_SCK_PIN = 6; const uint8_t SD_CHIP_SELECT_PIN = 7;
Basically that's all. As you can see, it's not that hard to do that task, but it wasn't quite easy to find everything out. I hope that helps some of you!
Maybe another last words: You can use the SD module with any other device, not only SD+RF24, but also SD+RFID.
Questions and comments: deloarts.wordpress.com