How to transfer code from Node MCU to Arduino Uno
And what kind of data should be stored in sd card,Give me an example, please
https://greennewsforum.blogspot.com/2018/10/sd-card-and-74hc595.html?m=1
How to transfer code from Node MCU to Arduino Uno
And what kind of data should be stored in sd card,Give me an example, please
https://greennewsforum.blogspot.com/2018/10/sd-card-and-74hc595.html?m=1
I mean sd card with shift register as shown in the link
https://greennewsforum.blogspot.com/2018/10/sd-card-and-74hc595.html?m=1

My exact question is what kind of data should be stored in the sd card. As stated in the code
![image|400x364]
(upload://zH5GW7jcAV0wji7I8QSjjEiXpHC.png)
#include "Arduino.h"
#include <SPI.h>
#include <SD.h>
#define CHIPSELECT_PIN 15
#define MINIMUM_SDCARD_SIZE 100
//Pin connected to ST_CP of 74HC595
//D3
#define LATCHOUT_PIN 0
//Pin connected to SH_CP of 74HC595
//D5
#define CLOCK_PIN 14
////Pin connected to DS of 74HC595
//D7
#define DATAOUT_PIN 13
byte dataOut = 0xFF;
int fileCounter = 0;
String ROOT_DIRECTORY = "/gtlog";
boolean baseDir = false;
void setup() {
Serial.begin(115200);
cardInitialization();
initializeDigitalPIN();
}
// The loop function is called in an endless loop
void loop() {
String filename = getNextFileName();
writeFile(filename, "Test String");
delay(2000);
readFileFromRoot();
delay(2000);
setDigitalPINOut(dataOut);
}
String getNextFileName() {
//String filename = String("log") + (fileCounter++) + String(".txt");
String filename = ROOT_DIRECTORY + "/" + (fileCounter++) + String(".txt");
Serial.print("Filename is ");
Serial.println(filename);
return filename;
}
boolean cardInitialization() {
pinMode(CHIPSELECT_PIN, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(CHIPSELECT_PIN)) {
// don't do anything more:
Serial.println("Card failed, or not present");
return false;
} else {
if (!isBaseDirAvailable()) {
createDirectory();
}
return true;
}
Serial.println("card initialized.");
}
void readFileFromRoot() {
File readFile = SD.open(ROOT_DIRECTORY);
readFile.rewindDirectory();
dataReader(readFile, 0);
readFile.flush();
readFile.close();
}
void dataReader(File root, int numTabs) {
Serial.println("*****Reading file*****");
while (true) {
File entry = root.openNextFile();
if (!entry) {
Serial.println("No more files");
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.println(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
dataReader(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
String fileName = entry.name();
Serial.print(fileName);
String line;
while (entry.available()) {
line = entry.readStringUntil('\n');
}
if (SD.exists(fileName)) {
Serial.println("Deleting the file " + fileName);
SD.remove(fileName);
Serial.print("File deleted");
}
//Serial.println(entry.size(), DEC);
//Serial.println(line);
}
entry.close();
}
}
void writeFile(String filename, String output) {
Serial.print("CustomSDCard::writeFile: ");
Serial.println(filename);
if (!checkSpace(MINIMUM_SDCARD_SIZE)) {
deleteFile();
}
//SdFile::dateTimeCallback(TimeRecorder::dateTime);
File dataFile = SD.open(filename, FILE_WRITE);
uint32_t fileSize = dataFile.size();
fileSize /= 1024;
// if the file is available, write to it:
if (dataFile) {
dataFile.println(output);
// print to the serial port too:
//Serial.println(output);
} else {
Serial.println("Error in reading/opening file " + filename);
//dataFile.clearWriteError();
//Serial.print("Write Error: ");
}
dataFile.flush();
dataFile.close();
}
boolean isBaseDirAvailable() {
return baseDir;
}
void deleteFile() {
File deleteFile = SD.open(ROOT_DIRECTORY);
deleteFile.rewindDirectory();
deleteEachFile(deleteFile, 0);
deleteFile.flush();
deleteFile.close();
}
void createDirectory() {
if (!SD.exists(ROOT_DIRECTORY)) {
SD.mkdir(ROOT_DIRECTORY);
}
baseDir = true;
}
void deleteEachFile(File root, int numTabs) {
while (true) {
File entry = root.openNextFile();
if (!entry) {
Serial.println("No more files");
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.println(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
dataReader(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
String fileName = entry.name();
if (SD.exists(fileName)) {
Serial.println("Deleting the file " + fileName);
SD.remove(fileName);
Serial.print("File deleted");
}
//Serial.println(entry.size(), DEC);
//Serial.println(line);
}
entry.close();
}
}
bool checkSpace(uint32_t fileSize) {
Sd2Card card;
SdVolume volume;
if (!card.init(SPI_HALF_SPEED, CHIPSELECT_PIN) && !volume.init(card)) {
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?");
Serial.println(
"Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return false;
} else {
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;
if (volumesize > fileSize) {
return true;
} else {
return false;
}
}
}
void initializeDigitalPIN() {
//set pins to output because they are addressed in the main loop
pinMode(LATCHOUT_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
}
void setDigitalPINOut(byte variableData) {
digitalWrite(CLOCK_PIN, LOW);
digitalWrite(LATCHOUT_PIN, LOW);
shiftOut(DATAOUT_PIN, CLOCK_PIN, variableData);
digitalWrite(LATCHOUT_PIN, HIGH);
}
/*
* Sample from arduino tutorial website
*/
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
/*Serial.print("Data Before: ");
Serial.println(myDataPin);*/
//internal function setup
int i = 0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut�
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i = 7; i >= 0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if (myDataOut & (1 << i)) {
pinState = 1;
} else {
pinState = 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
Perhaps you'd get some good help if you described what you are trying to accomplish, what you've tried so far and what is or is not working.
We not mind readers here - I keep music on SD cards, and data from my "flower" greenhouse environmental control system, for example.
You?
a7
Does the code accept data?
12
122
13
10
130
Or:
C0
E1
12
43
122
Or:
00011100
00111000
01110000
Perhaps you'd get some good help if you described what you are trying to accomplish, what you've tried so far and what is or is not working.
We not mind readers here - I keep music on SD cards, and data from my "flower" greenhouse environmental control system, for example.
You?
a7
Porting code from one architecture/chip to another is often difficult and therefore done for specific reasons. e.g., use a more powerful chip to add functionality, or use a less powerful chip to save cost and make lots of money when selling large volumes.
The Arduino Uno is a far less capable device than the Node MCU. So some functionality cannot be ported.
Why do you want to port the code?
When simulating, I am having a problem with the data. I attached the ino, proteus, mmc,
Filename is /gtlog/0.txt
CustomSDCard::writeFile: /gtlog/0.txt
Volume type is FAT0
Volume size (bytes): 0
Volume size (Kbytes): 0.TXT
1.TXT
2.TXT
3.TXT
LOG.TXT
No more files
*****Reading file*****
0.TXT
0.TXT1.TXT
1.TXT2.TXT
2.TXT3.TXT
3.TXTLOG.TXT
LOG.TXTNo more files
Filename is /gtlog/1.txt
CustomSDCard::writeFile: /gtlog/1.txt
Volume type is FAT0
Arduino shift_register_sd_card.zip (2.5 ك.ب)
proteus shift register sd card.zip (20.3 ك.ب)
mmc file.zip (8.6 ك.ب)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.