Commit 1bab7777 authored by Nelso Jost's avatar Nelso Jost

NEW: testing basic SD card example (cardinfo)

parent 6d0abebb
......@@ -6,5 +6,6 @@
*.json
*.log
.build
get-pip.py*
pid_*
__pycache__
......@@ -9,8 +9,10 @@ PIODIR = .pio
all: firmware
install-platformaio:
pip install platformio
install-platformio:
wget https://bootstrap.pypa.io/get-pip.py && \
sudo python get-pip.py && rm get-pip.py
sudo pip install platformio
firmware:
@ echo "$$PIO_BUILD" | sh
......
......@@ -7,6 +7,7 @@
#include "repl.h"
#include "wifi.h"
#include "blinker.h"
#include "sdcard.h"
#define BUILTIN_LED 2
Blinker blinker(BUILTIN_LED);
......@@ -21,6 +22,7 @@ void REPL_BLINK(String command);
void REPL_DWRITE(String command);
void REPL_AREAD(String command);
void REPL_ALOG(String command);
void REPL_SDCARDINFO(String command);
REPL_COMMAND commands[] =\
{
......@@ -40,6 +42,9 @@ REPL_COMMAND commands[] =\
{"alog", REPL_ALOG,
"alog <pin> <interval>",
"Start datalog on analogic pin with given interval."},
{"sdcardinfo", REPL_SDCARDINFO,
"sdcardinfo",
"Show a summary of the SD card info."},
{NULL, NULL}
};
REPL repl(commands);
......@@ -161,3 +166,8 @@ void REPL_ALOG(String command)
}
}
}
void REPL_SDCARDINFO(String command)
{
print_sdcard_info();
}
/*-----------------------------------------------------------------------------
* Author: Nelso G. Jost (nelsojost@gmail.com)
* License: GPLv2
* Purpose: Provide SD card management.
*---------------------------------------------------------------------------*/
#include <SPI.h>
#include <SD.h>
#include "sdcard.h"
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
/* Credits:
* https://github.com/esp8266/Arduino/tree/master/libraries/SD/examples/CardInfo
*/
void print_sdcard_info(void)
{
Serial.print("\nInitializing SD card...");
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?");
return;
}
else
{
Serial.println("Wiring is correct and a card is present.");
}
Serial.print("\nCard 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");
}
if (!volume.init(card))
{
Serial.println("Could not find FAT16/FAT32 partition.\n"
"Make sure you've formatted the card");
return;
}
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
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);
}
/*-----------------------------------------------------------------------------
* Author: Nelso G. Jost (nelsojost@gmail.com)
* License: GPLv2
* Purpose: Provide SD card management.
*---------------------------------------------------------------------------*/
#ifndef SDCARD_H
#define SDCARD_H
void print_sdcard_info(void);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment