Skip to content

Commit adcf89b

Browse files
committed
User Manual writing commit 21
1 parent 0633987 commit adcf89b

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed
114 KB
Loading

content/hardware/05.pro-solutions/solutions-and-kits/edge-control/tutorials/user-manual/content.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ The different commands and controllable power rails will be specified in the lis
969969
970970
```cpp
971971
Power.on(PWR_VBAT); // turns on the 12V power rails for the "Latching Outputs"
972-
Power.on(PWR_3V3); // turns on the 3.3V power rail for the micro SD Card (default ON)
972+
Power.on(PWR_3V3); // turns on the 3.3V power rail for the micro SD Card
973973
Power.on(PWR_19V); // turns on the 19V power rail for the 4-20mA sensors reference
974974
Power.on(PWR_MKR1); // turns on the MKR board connected to slot 1
975975
Power.on(PWR_MKR2); // turns on the MKR board connected to slot 2
@@ -1459,4 +1459,91 @@ void loop()
14591459

14601460
![UART communication demo](assets/UART.gif)
14611461

1462-
### Bluetooth® Low Energy
1462+
## Micro SD Card
1463+
1464+
A Micro SD Card can be integrated to the Edge Control for sensor data logging, storing projects configurations or any application concerned to data storage.
1465+
1466+
The very known [SD library](https://www.arduino.cc/reference/en/libraries/sd/) is compatible with the Edge Control, we can test the included examples just by adding some lines of code needed by the Edge Control.
1467+
1468+
The example code used below is an adaptation of the "Datalogger" example included in the `SD` library. It logs the value sampled from an analog input of the Edge Control.
1469+
1470+
The same wiring of the [analog input section](#analog-inputs) can be used, with the addition of an micro SD card attached.
1471+
1472+
```cpp
1473+
#include <Arduino_EdgeControl.h>
1474+
#include <SPI.h>
1475+
#include <SD.h>
1476+
1477+
constexpr unsigned int adcResolution{ 12 };
1478+
1479+
const int chipSelect = PIN_SD_CS;
1480+
1481+
void setup() {
1482+
// Open serial communications and wait for port to open:
1483+
Serial.begin(115200);
1484+
while (!Serial) {
1485+
; // wait for serial port to connect. Needed for native USB port only
1486+
}
1487+
1488+
EdgeControl.begin();
1489+
// Power on the 3V3 rail for SD Card
1490+
Power.on(PWR_3V3);
1491+
Power.on(PWR_VBAT);
1492+
1493+
Wire.begin();
1494+
Expander.begin();
1495+
1496+
Serial.print("Waiting for IO Expander Initialization...");
1497+
while (!Expander) {
1498+
Serial.print(".");
1499+
delay(100);
1500+
}
1501+
Serial.println(" done.");
1502+
1503+
Input.begin();
1504+
Input.enable();
1505+
1506+
analogReadResolution(adcResolution);
1507+
1508+
Serial.print("Initializing SD card...");
1509+
1510+
// see if the card is present and can be initialized:
1511+
if (!SD.begin(chipSelect)) {
1512+
Serial.println("Card failed, or not present");
1513+
// don't do anything more:
1514+
while (1)
1515+
;
1516+
}
1517+
Serial.println("card initialized.");
1518+
}
1519+
1520+
void loop() {
1521+
// make a string for assembling the data to log:
1522+
String dataString = "";
1523+
1524+
int sensor = Input.analogRead(INPUT_05V_CH01); // read the Edge Control 0-5v Channel 1
1525+
dataString += String(sensor);
1526+
1527+
// open the file. note that only one file can be open at a time,
1528+
// so you have to close this one before opening another.
1529+
File dataFile = SD.open("datalog.txt", FILE_WRITE);
1530+
1531+
// if the file is available, write to it:
1532+
if (dataFile) {
1533+
dataFile.println(dataString);
1534+
dataFile.close();
1535+
// print to the serial port too:
1536+
Serial.println(dataString);
1537+
}
1538+
// if the file isn't open, pop up an error:
1539+
else {
1540+
Serial.println("error opening datalog.txt");
1541+
}
1542+
}
1543+
1544+
```
1545+
1546+
You will be able to read all the sampled data from the micro SD card inserting it to your PC on a `.txt` file called `DATALOG`.
1547+
1548+
![Data logging wiring and output](assets/data-logging.png).
1549+

0 commit comments

Comments
 (0)