Introduction: Log Data on SD Card Using the LightBlue Bean
This tutorial teaches you how to write data to an SD card using the LightBlue Bean.
The LightBlue Bean is an Arduino compatible microcontroller with integrated Bluetooth Low Energy that you can program wirelessly from your smartphone or desktop.
We will get the ambient temperature using Bean.getTemperature(); and then save it in a text file on the SD card.
Step 1: Get the Parts
To make this you will need:
- A LightBlue Bean
- A microSD card with microSD to SD adapter
- An SD card breakout board (optional)
- A breadboard
- Jumper wires
- Male headers
- Female headers
- A 2xAA battery holder with batteries
- A soldering iron
Step 2: Make a Breadboard Bean
Step 3: Solder the SD Card
To wire the SD card to the breadboard we can either buy a SD card breakout board or solder male headers directly on the pins on the adapter. These are the pins we will need:
Take the male headers and put the short end against the pins on the SD card adapter. To avoid melting the plastic, put a drop of solder on the soldering iron and quickly put it on the SD card adapter pin and male header.
Step 4: Assemble the Breadboard
Put the SD card and Bean next to each other on the breadboard. Put jumper wires from pin A0 - pin 5 under the Bean to cover the gap in the middle of the breadboard.
To connect the SD card to the Bean we need to wire the following pins to each other:
- Pin 2 – SS
- Pin 3 – MOSI
- Pin 4 – MISO
- Pin 5 – SCK
- VCC – VCC
Also connect the two GNDs on the SD card to GND on the breadboard and then connect the batteries to BAT and GND on the Bean.
This is what the final wiring should look like:
Illustration made using Fritzing
Step 5: Modify the SD Library
To read the audio files from the SD card we will use the SD library that is preinstalled in the Arduino IDE. We will need to modify it a bit though to use it with the LightBlue Bean.
To find the library, navigate to the Arduino app in Finder, right click the icon and choose "Show package contents".
From there, open Contents > Resources > Java > libraries > SD > utility > Sd2PinMap.h
On line 278-281 change SS_Pin to 2, MOSI_PIN to three, MISO_PIN to 4 and SCK_PIN to 5. Save and close!
Step 6: Program Bean
Upload this code to your Bean.
Step 7: Put File on SD Card
To write data on the SD card, we need a .txt file that we can print it to.
Create an empty .txt file, name it "datalog" and load it to the SD card. Put the SD card in the adapter on the breadboard and collect that temperature data like there's no tomorrow!