Adafruit Adalogger FeatherWing Created by lady ada Last updated on 2018-01-18 06:15:20 PM UTC
Guide Contents Guide Contents Overview Pinouts Power Pins RTC & I2C Pins SD & SPI Pins Assembly Using the Real Time Clock 2 3 6 6 6 7 9 11 What is a Real Time Clock? 11 Battery Backup 11 CR1220 12mm Diameter - 3V Lithium Coin Cell Battery RTC with Arduino Wiring Talking to the RTC First RTC test Setting the time Reading the time RTC with CircuitPython Wiring Adafruit CircuitPython Library Install Usage Setting the time Using the SD Card 4GB Blank SD/MicroSD Memory Card USB MicroSD Card Reader/Writer
Overview A Feather board without ambition is a Feather board without FeatherWings! This is the Adalogger FeatherWing: it adds both a battery-backed Real Time Clock and micro SD card storage to any Feather main board. Using our Feather Stacking Headers or Feather Female Headers you can connect a FeatherWing on top of your Feather board and let the board take flight! © Adafruit Industries https://learn.adafruit.
This FeatherWing will make it real easy to add datalogging to any of our existing Feathers. You get both an I2C real time clock (PCF8523) with 32KHz crystal and battery backup, and a microSD socket that connects to the SPI port pins (+ extra pin for CS). Tested and works great with any of our Feathers, based on ATmega32u4, ATSAMD21, Teensy, or ESP8266. We recommend the Arduino's default SD library to talk to the microSD card socket.
Great for any kind of datalogging or even data reading! Some light soldering is required to attach the headers onto the 'Wing but it's a 10 minute task. © Adafruit Industries https://learn.adafruit.
Pinouts Evern though every pin from the Feather is 'doubled up' with an inner header, not all of the pins are actually used! Power Pins On the bottom row, the 3.3V (second from left) and GND (fourth from left) pin are used to power the SD card and RTC (to take a load off the coin cell battery when main power is available) RTC & I2C Pins © Adafruit Industries https://learn.adafruit.
In the top right, SDA (rightmost) and SCL (to the left of SDA) are used to talk to the RTC chip. SCL - I2C clock pin, connect to your microcontrollers I2C clock line. This pin has a 10K pullup resistor to 3.3V SDA - I2C data pin, connect to your microcontrollers I2C data line. This pin has a 10K pullup resistor to 3.3V These pins are in the same location on every Feather There's also a breakout for INT which is the output pin from the RTC.
Starting from the left you've got SPI Clock (SCK) - output from feather to wing SPI Master Out Slave In (MOSI) - output from feather to wing SPI Master In Slave Out (MISO) - input from wing to feather These pins are in the same location on every Feather. They are used for communicating with the SD card. When the SD card is not inserted, these pins are completely free. MISO is tri-stated whenever the SD CS pin is pulled high The SDCS pin is the chip select line.
Assembly When putting together your Featherwings, think about how you want it to connect, you can use stacking headers: Or plain female socket headers: © Adafruit Industries https://learn.adafruit.
The most common method of attachment for the featherwing is putting stacking or female headers on the Feather mainboard and then putting the Wing on top: But don't forget, you can also put the stacking headers on the wing and stack the Feather on top of it! © Adafruit Industries https://learn.adafruit.
Using the Real Time Clock What is a Real Time Clock? When logging data, it's often really really useful to have timestamps! That way you can take data one minute apart (by checking the clock) or noting at what time of day the data was logged. The Arduino IDE does have a built-in timekeeper called millis() and theres also timers built into the chip that can keep track of longer time periods like minutes or days.
CR1220 12mm Diameter - 3V Lithium Coin Cell Battery PRODUCT ID: 380 https://adafru.it/em8 $0.95 IN STOCK You MUST have a coin cell installed for the RTC to work, if there is no coin cell, it will act strangely and possibly hang the Arduino when you try to use it, so ALWAYS make SURE there's a battery installed, even if it's a dead battery. © Adafruit Industries https://learn.adafruit.
RTC with Arduino Wiring Wiring it up is easy, connect GND to GND on your board VCC to the logic level power of your board (on classic Arduinos & Metros use 5V, on 3.3V devices use 3.3V) SDA to the SDA i2c data pin SCL to the SCL i2c clock pin There are internal 10K pull-ups on the PCF8523 on SDA and SCL to the VCC voltage pcfmetro Fritzing https://adafru.it/A1F Talking to the RTC The RTC is an i2c device, which means it uses 2 wires to to communicate.
Type in RTClib - and find the one that is by Adafruit and click Install There are a few different 'forks' of RTClib, make sure you are using the ADAFRUIT one! We also have a great tutorial on Arduino library installation at: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use Once done, restart the IDE First RTC test The first thing we'll demonstrate is a test sketch that will read the time from the RTC once a second.
Now open up the Serial Console and make sure the baud rate is set correctly at 57600 baud you should see the following: Whenever the RTC chip loses all power (including the backup battery) it will reset to an earlier date and report the time as 0:0:0 or similar. Whenever you set the time, this will kickstart the clock ticking. So, basically, the upshot here is that you should never ever remove the battery once you've set the time.
if (! rtc.initialized()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); This line is very cute, what it does is take the Date and Time according the computer you're using (right when you compile the code) and uses that to program the RTC. If your computer time is not set right you should fix that first. Then you must press the Upload button to compile and then immediately upload.
void loop () { DateTime now = rtc.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(" ("); Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial.print(") "); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.
RTC with CircuitPython Wiring Wiring it up is easy, connect GND to GND on your board VCC to the logic level power of your board - every CircuitPython board uses 3.3V SDA to the SDA i2c data pin SCL to the SCL i2c clock pin There are internal 10K pull-ups on the PCF8523 on SDA and SCL to the VCC voltage Adafruit CircuitPython Library Install To use the RTC sensor with your Adafruit CircuitPython board you'll need to install the Adafruit_CircuitPython_PCF8523 module on your board.
Usage To demonstrate the usage of the PCF8523 module you can connect to your board's serial REPL to see the output while saving our example sketch to main.py Next connect to the board's serial REPL so you are at the CircuitPython >>> prompt. Then save this script to main.py (back up or remove whatever was there before) import import import import busio adafruit_pcf8523 time board myI2C = busio.I2C(board.SCL, board.SDA) rtc = adafruit_pcf8523.
find these lines: if False: # change to True if you want to write the time! # year, mon, date, hour, min, sec, wday, yday, isdst t = time.struct_time((2017, 10, 29, 15, 14, 15, 0, -1, -1)) # you must set year, mon, date, hour, min, sec and weekday # yearday is not supported, isdst can be set but we don't do anything with it at this time Change the False to True in the first line, and update the time.struct_time to have the current time starting from year to weekday .
Using the SD Card The other half of the adalogger FeatherWing is the SD card. The SD card is how we store long term data. While the Feather may have a permanent EEPROM storage, its only a couple hundred bytes - tiny compared to a 2 gig SD card. SD cards are so cheap and easy to get, its an obvious choice for long term storage so we use them for the 'Wing! The FeatherWing kit doesn't come with an SD card but we carry one in the shop that is guaranteed to work.
The official SD formatter is available from https://www.sdcard.org/downloads/formatter_4/ Download it and run it on your computer, there's also a manual linked from that page for use Download the official SD Formatter software for Windows https://adafru.
On Teensy 3.x it's on GPIO 10 On STM32F2/WICED, its on PB5 On ESP32, it's on GPIO 33 On nRF52, it's on GPIO 11 OK, now insert the micro SD card into the FeatherWing and upload the sketch © Adafruit Industries https://learn.adafruit.
Open up the Serial Monitor and type in a character into the text box (& hit send) when prompted. You'll probably get something like the following: Its mostly gibberish, but its useful to see the Volume type is FAT16 part as well as the size of the card (about 2 GB which is what it should be) etc. © Adafruit Industries https://learn.adafruit.
If you have a bad card, which seems to happen more with ripoff version of good brands, you might see: The card mostly responded, but the data is all bad. Note that the Product ID is "N/A" and there is no Manufacturer ID or OEM ID. This card returned some SD errors.
Once you know the SD card works, check out the SD card library examples, SD library documentation and Notes! Example logging sketch If you want to try saving data to the SD card in the simplest sketch, try this example. You can adjust the delay() to set how often analog data is read from pin A0 and saved to the SD card. The red LED will blink if there's an error, and the green LED will blink when data is written to the SD card.
42 strcpy(filename, "ANALOG00.TXT"); 43 for (uint8_t i = 0; i < 100; i++) { filename[6] = '0' + i/10; 44 45 filename[7] = '0' + i%10; 46 // create if does not exist, do not open existing, write, sync after write 47 if (! SD.exists(filename)) { break; 48 } 49 } 50 51 52 logfile = SD.open(filename, FILE_WRITE); 53 if( ! logfile ) { Serial.print("Couldnt create "); 54 55 Serial.println(filename); 56 error(3); 57 } 58 Serial.print("Writing to "); 59 Serial.
CircuitPython Adafruit CircuitPython Module Install To use a microSD card with your Adafruit CircuitPython board you'll need to install the Adafruit_CircuitPython_SD module on your board. First make sure you are running the latest version of Adafruit CircuitPython for your board. Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle.
Next connect to the board's serial REPL so you are at the CircuitPython >>> prompt. Initialize & Mount SD Card Filesystem Before you can use the microSD card you need to initialize its SPI connection and mount its filesystem.
Once the microSD card is mounted inside CircuitPython's filesystem you're ready to read and write data from it. Reading and writing data is simple using Python's file operations like open, close, read, and write. The beauty of CircuitPython and MicroPython is that they try to be as similar to desktop Python as possible, including access to files. For example to create a file and write a line of text to it you can run: with open("/sd/test.txt", "w") as f: f.write("Hello world!\r\n") Notice the with statemen
with open("/sd/test.txt", "a") as f: f.write("This is another line!\r\n") Notice the a option in the open function--this tells Python to add data at the end of the file instead of erasing it and starting over at the top. Try reading the file with the code above to see the new line that was added! That's all there is to manipulating files on microSD cards with CircuitPython! Here are a few more complete examples of using a SD card from the Trinket M0 CircuitPython guides.
import import import import import import adafruit_sdcard busio digitalio board storage os # Use any pin that is not taken by SPI SD_CS = board.D0 # Connect to the card and mount the filesystem. spi = busio.SPI(board.SCK, board.MOSI, board.MISO) cs = digitalio.DigitalInOut(SD_CS) sdcard = adafruit_sdcard.SDCard(spi, cs) vfs = storage.VfsFat(sdcard) storage.
But you probably want to do a little more, lets log the temperature from the chip to a file. Here's the new script import import import import import import import import adafruit_sdcard microcontroller busio digitalio board storage os time # Use any pin that is not taken by SPI SD_CS = board.D0 led = digitalio.DigitalInOut(board.D13) led.direction = digitalio.Direction.OUTPUT # Connect to the card and mount the filesystem. spi = busio.SPI(board.SCK, board.MOSI, board.MISO) cs = digitalio.
file temperature.txt The key part of this demo is in these lines: print("Logging temperature to filesystem") # append to the file! while True: # open file for append with open("/sd/temperature.txt", "a") as f: led.value = True # turn on LED to indicate we're writing to the file t = microcontroller.cpu.temperature print("Temperature = %0.1f" % t) f.write("%0.1f\n" % t) led.value = False # turn off LED to indicate we're done # file is saved time.
Downloads Datasheets and Files EagleCAD PCB files on GitHub Fritzing object in Adafruit Fritzing library PCF8523 product page Schematic Fabrication Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2018-01-18 06:15:18 PM UTC Page 36 of 36