Read/write to SD card

10-28-2020: Cubecell fails to compile with only one include (SD.H) in the program using a fresh install of Arduino *V1.8.13 and Cubecell board for arduino downloaded last night. It fails on other PC’s as well. This must be an issue with Cellcube. My conversion project to cubecell is dead in the water and this is disappointing. here is the error message that seems to be related to the SPI pin mapping…

In file included from C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2Card.h:26:0,
from C:\Program Files (x86)\Arduino\libraries\SD\src/utility/SdFat.h:29,
from C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:20,
from C:\Users\User\Documents\Arduino\SDerrors\SDerrors.ino:2:
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:27:26: error: ‘SS’ was not declared in this scope
uint8_t const SS_PIN = SS;
^
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:28:28: error: ‘MOSI’ was not declared in this scope
uint8_t const MOSI_PIN = MOSI;
^
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:29:28: error: ‘MISO’ was not declared in this scope
uint8_t const MISO_PIN = MISO;
^
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:30:27: error: ‘SCK’ was not declared in this scope
uint8_t const SCK_PIN = SCK;
^
In file included from C:\Program Files (x86)\Arduino\libraries\SD\src/utility/SdFat.h:29:0,
from C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:20,
from C:\Users\User\Documents\Arduino\SDerrors\SDerrors.ino:2:
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2Card.h:70:41: error: ‘SS’ was not declared in this scope
uint8_t const SD_CHIP_SELECT_PIN = SS;
^
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2Card.h:79:35: error: ‘MOSI’ was not declared in this scope
uint8_t const SPI_MOSI_PIN = MOSI;
^
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2Card.h:81:35: error: ‘MISO’ was not declared in this scope
uint8_t const SPI_MISO_PIN = MISO;
^
C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2Card.h:83:34: error: ‘SCK’ was not declared in this scope
uint8_t const SPI_SCK_PIN = SCK;
^
exit status 1
Error compiling for board CubeCell-Board(HTCC-AB01).

Can anyone help? Is there a Heltec support email?

Bill

It doeI am working on migrating from Adafruit feather RFM95 board to HTCC-AB01 Development board and am having issues with the arduino SD.H library failing to compile. Is there a special SD.H library for the Cellcube? No examples for DS card are listed in arduino for Cellcube.

The statement it is failing on is…#include <SD.h>
Here is the error messaging…
C:\Users\User\Documents\Arduino\libraries\SD\src/utility/Sd2Card.h:79:35: error: ‘MOSI’ was not declared in this scope
uint8_t const SPI_MOSI_PIN = MOSI;
^
C:\Users\User\Documents\Arduino\libraries\SD\src/utility/Sd2Card.h:81:35: error: ‘MISO’ was not declared in this scope
uint8_t const SPI_MISO_PIN = MISO;
^
C:\Users\User\Documents\Arduino\libraries\SD\src/utility/Sd2Card.h:83:34: error: ‘SCK’ was not declared in this scope
uint8_t const SPI_SCK_PIN = SCK;
^
Multiple libraries were found for “SD.h”
Used: C:\Users\User\Documents\Arduino\libraries\SD
Not used: C:\Program Files (x86)\Arduino-Tinsy\libraries\SD
exit status 1
Error compiling for board CubeCell-Board(HTCC-AB01).

Maybe my SD.H file is corrupt (it ignored the Tinsy library)

Any help is greatly appreciated.
Bill

I think you need to do a migrate with the SPI, the follow example shows how to set SPI

Thank you for your quick reply.

The SPI.h library works fine in the example you provided and in the default SPI.H from arduino. As soon as you add the #include <SD.h> library, it errors out with the same error message. It is like the defines for MISO,MOSI,SCK and SS pins don’t line up with the Cubecell’s assigned pins.
These can be redefined for the SPI port but I do not know what the pin numbers are for the Cubcell to try it (I’m desperate)…
Example
// Map SPI port to ‘new’ pins D14…D17
#define PIN_SPI_SS (17)
#define PIN_SPI_MOSI (16)
#define PIN_SPI_MISO (14)
#define PIN_SPI_SCK (15)

static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;

It is late here in Oregon, USA right now (10:46pm) and I am headed to bed now so I may not reply to any comments until tomorrow am.

Thanks again.

Bill

Can you give us the SD card library website URL,we get it and do a fix.

I have no way to link it since it is in the install package from the arduino official website (windows7 and up version). The installer saves the SD.H file in the C:\Program Files (X86)\Arduino\libraries\SD\SRC folder on my HDD.

Here is the contents of the SD.H file…
/*

SD - a slightly more friendly wrapper for sdfatlib

This library aims to expose a subset of SD card functionality
in the form of a higher level “wrapper” object.

License: GNU General Public License V3
(Because sdfatlib is licensed with this.)

© Copyright 2010 SparkFun Electronics

*/

#ifndef SD_H
#define SD_H

#include <Arduino.h>

#include “utility/SdFat.h”
#include “utility/SdFatUtil.h”

#define FILE_READ O_READ
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT | O_APPEND)

namespace SDLib {

class File : public Stream {
private:
char _name[13]; // our name
SdFile *_file; // underlying file pointer

public:
  File(SdFile f, const char *name);     // wraps an underlying SdFile
  File(void);      // 'empty' constructor
  virtual size_t write(uint8_t);
  virtual size_t write(const uint8_t *buf, size_t size);
  virtual int availableForWrite();
  virtual int read();
  virtual int peek();
  virtual int available();
  virtual void flush();
  int read(void *buf, uint16_t nbyte);
  boolean seek(uint32_t pos);
  uint32_t position();
  uint32_t size();
  void close();
  operator bool();
  char * name();

  boolean isDirectory(void);
  File openNextFile(uint8_t mode = O_RDONLY);
  void rewindDirectory(void);

  using Print::write;

};

class SDClass {

private:
  // These are required for initialisation and use of sdfatlib
  Sd2Card card;
  SdVolume volume;
  SdFile root;

  // my quick&dirty iterator, should be replaced
  SdFile getParentDir(const char *filepath, int *indx);
public:
  // This needs to be called to set up the connection to the SD card
  // before other methods are used.
  boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
  boolean begin(uint32_t clock, uint8_t csPin);

  //call this when a card is removed. It will allow you to insert and initialise a new card.
  void end();

  // Open the specified file/directory with the supplied mode (e.g. read or
  // write, etc). Returns a File object for interacting with the file.
  // Note that currently only one file can be open at a time.
  File open(const char *filename, uint8_t mode = FILE_READ);
  File open(const String &filename, uint8_t mode = FILE_READ) {
    return open(filename.c_str(), mode);
  }

  // Methods to determine if the requested file path exists.
  boolean exists(const char *filepath);
  boolean exists(const String &filepath) {
    return exists(filepath.c_str());
  }

  // Create the requested directory heirarchy--if intermediate directories
  // do not exist they will be created.
  boolean mkdir(const char *filepath);
  boolean mkdir(const String &filepath) {
    return mkdir(filepath.c_str());
  }

  // Delete the file.
  boolean remove(const char *filepath);
  boolean remove(const String &filepath) {
    return remove(filepath.c_str());
  }

  boolean rmdir(const char *filepath);
  boolean rmdir(const String &filepath) {
    return rmdir(filepath.c_str());
  }

private:

  // This is used to determine the mode used to open a file
  // it's here because it's the easiest place to pass the
  // information through the directory walking function. But
  // it's probably not the best place for it.
  // It shouldn't be set directly--it is set via the parameters to `open`.
  int fileOpenMode;

  friend class File;
  friend boolean callback_openPath(SdFile&, const char *, boolean, void *);

};

extern SDClass SD;

};

// We enclose File and SD classes in namespace SDLib to avoid conflicts
// with others legacy libraries that redefines File class.

// This ensure compatibility with sketches that uses only SD library
using namespace SDLib;

// This allows sketches to use SDLib::File with other libraries (in the
// sketch you must use SDFile instead of File to disambiguate)
typedef SDLib::File SDFile;
typedef SDLib::SDClass SDFileSystemClass;
#define SDFileSystem SDLib::SD

#endif

I signed up for dropbox so I can share the files you are looking for. I think the files that need editing are located in the SD\src\utility folder. The Sd2PinMap.h, and Sd2Card.h look like prime suspects to me.

Here is the link to the SD folder Arduino created and populated on new install…

https://www.dropbox.com/scl/fi/xfucvosg6w284n0vkmjum/SD.zip?dl=0&oref=e&r=ABQDKjYhAnLOKsErcv5AA3DP_EbZRjw0md0z1XR_u4Jxf7X4SndyBVQfdMOexh72x31GxDIJoyO_ELOk6hpsDK6zo1-ZWKR6Nz1eYnyCwtkF9me3SO_cqSddONi8M_13zZ6eVL3jUgfe5znlRH1GKdMDRVKESXcf1JPez9v2UW-YNT3MZnG_OEMUrJX57y_DO1aoz8ekICbWO22gSd-LQ0Kbu1uXTb2T2J7kgEgJW7x0Fg&sm=1

It is the SPI PIN did not defined in CubeCell variants, I had updated CubeCell variants just now. I can build the sd example now. Please update CubeCell code from git and try again. I hope it works.

I just finished updating and trying it on 3 different PC’s. All three failed to compile. See link below for error listing.

Did try compiling any of the SD examples that are listed in the Arduino Basics? I am using these for testing- all examples fail.

BTW. I bricked my only two Cellcube boards last night by wiring a Neopixel V+ to the 3V3 pin not realizing that it can’t supply the current needed. I have been using the adafruit feather RFM95 board and use the 3V pin and any GPIO pin for control with no issues. I google searched issue and now know that the VEXT pin is what I should have used to power the Neopixel. I still don’t know how to use the VEXT Control pin. The lack of documentation for this board is causing extremely slow development. I will order more boards today but they will not arrive until mid-end of next week.

Here is the link to the error messages after updating the Cubecell board…
https://www.dropbox.com/l/scl/AADKQLBehOQZZjpOVoBDJcXQg1d6mvFeQco

I can’t connect to the web you provided.
I compiled the SD examples that are listed in the Arduino Basic


How did you update CubeCell environment? Now only it is updated in git .
You can replace the folder “variants” in your environment with https://github.com/HelTecAutomation/ASR650x-Arduino/tree/master/variants

That did the trick. Thank you very much!!

The SD examples I tried compiled fine after replacing the files. The manual update process was no fun to do- recommend an update to CubeCell board version from the Arduino boards manager for others to have it a lot easier. I will test the read/write on a SD to be certain all works well when my boards arrive (next couple of days from now).

Hello guys, I am trying to compile the code "CardInfo " of the example on my HTCC-AB02S but I can’t do it. I have tried with other examples and I am getting the same so if You can help me I will much appreciate it. I am getting the following errors:

In file included from C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2Card.h:26:0,
from C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/SdFat.h:29,
from C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/SD.h:20,
from C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\examples\CardInfo\CardInfo.ino:24:
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2PinMap.h:27:26: error: ‘SS’ was not declared in this scope
uint8_t const SS_PIN = SS;
^
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2PinMap.h:28:28: error: ‘MOSI’ was not declared in this scope
uint8_t const MOSI_PIN = MOSI;
^
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2PinMap.h:29:28: error: ‘MISO’ was not declared in this scope
uint8_t const MISO_PIN = MISO;
^
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2PinMap.h:30:27: error: ‘SCK’ was not declared in this scope
uint8_t const SCK_PIN = SCK;
^
In file included from C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/SdFat.h:29:0,
from C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/SD.h:20,
from C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\examples\CardInfo\CardInfo.ino:24:
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2Card.h:70:41: error: ‘SS’ was not declared in this scope
uint8_t const SD_CHIP_SELECT_PIN = SS;
^
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2Card.h:79:35: error: ‘MOSI’ was not declared in this scope
uint8_t const SPI_MOSI_PIN = MOSI;
^
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2Card.h:81:35: error: ‘MISO’ was not declared in this scope
uint8_t const SPI_MISO_PIN = MISO;
^
C:\Users\Alberto\Desktop\Arduino\arduino-1.8.13\libraries\SD\src/utility/Sd2Card.h:83:34: error: ‘SCK’ was not declared in this scope
uint8_t const SPI_SCK_PIN = SCK;
^
exit status 1
Error compilando para la tarjeta CubeCell-GPS(HTCC-AB02S).

Hi, I am having the same problem.

I can’t compile any codes. all i am getting errors. Is there any Heltec support email?

Thanks for your help.

Regards.

Hi @BillP,

I am having the same issue as you had but i can’t get it working. i had tried to replace the variants folder as they suggested but still i am having error with the pins. Could you help me too?

I will much appreciate.

Regards,