Shield Arduino MKR WiFi 1010 per supporto memorie Flash SPI

Spread the love

Ho un paio di Arduino MKR WiFi 1010, ed è potente, ma noto una noiosa mancanza: non c’è una memoria Flash per archiviare i dati. Ho già scritto alcuni articoli sul controllo della memoria flash SPI esterna “Come utilizzare le memorie flash SPI esterne”, ma ora vorrei semplificare il processo e ho creato un semplice shield per aggiungere la memoria flash SPI esterna nel modo più veloce.

Arduino MKR WiFi 1010 SPI Flash memory storage shield
Arduino MKR WiFi 1010 SPI Flash memory storage shield

PCB


Qui trovi il semplice PCB Shield PCBWay
PCB from PCBWay

Il PCB è semplice e ho aggiunto alcuni ponticelli da saldare per selezionare il pin CS.

Arduino MKR WiFi 1010 SPI Flash PCB shield
Arduino MKR WiFi 1010 SPI Flash PCB shield

La configurazione è la stessa degli esempi già pubblicati.

Arduino MKR WiFi 1010 pinouts low resolution
Arduino MKR WiFi 1010 pinouts low resolution

Qui l'Arduino Amazon Arduino MKR WiFi 1010

Prestare attenzione al pin CS selezionabile sul PCB.

ArduinoSPI Flash
4/CS Pulled UP if not standard CS
10DI (IO1)
8DI (IO0)
9CLK
3.3v/WP
3.3v/Hold
GNDGND
3.3vVCC

Dall’alto, puoi vedere come appare lo shield.

Arduino MKR WiFi 1010 SPI Flash memory shield
Arduino MKR WiFi 1010 SPI Flash memory shield

Per il mio scopo, di solito utilizzo un chip w25q64 da 8 Mb ed è sufficiente per tutti i miei scopi.

Qui la mia selezione di memorie Flash w25q16 SMD 2Mb - w25q16 Discrete 2Mb - w25q32 SMD 4Mb - w25q32 Discrete 4Mb - w25q64 SMD 8Mb - w25q64 Discrete 8Mb - w25q128 SMD 16Mb - w25q128 Discrete 16Mb W25Q32 W25Q64 w25q128 module 4Mb 8Mb 16Mb

Qui i bottoni SMD 3*6*2.5 SMD buttons 3X6X2.5

Condensatori SMD 805 0805 SMD Capacitor kit

Il risultato è molto utile e lo spazio utilizzato è limitato.

Arduino MKR WiFi 1010 SPI Flash memory shield
Arduino MKR WiFi 1010 SPI Flash memory shield

Esempio di Sketch

Qui c’è un semplice esempio.

/*
 *  Use SPIFlash with FAT filesystem
 *  Write data inside a file
 *  Read data and info from the file
 *  Get the list of files in the directory
 *
 *  library Adafruit_SPIFlash and SdFat - AdafruitFork
 *
 *  by Mischianti Renzo <https://mischianti.org>
 *
 *  https://mischianti.org/
 *
 *	SPIFlash connected via SPI standard check wiring on the article
 *
 */

#include "SdFat.h"
#include "Adafruit_SPIFlash.h"

Adafruit_FlashTransport_SPI flashTransport(SS, SPI); // Set CS and SPI interface
Adafruit_SPIFlash flash(&flashTransport);

// file system object from SdFat
FatFileSystem fatfs;

//The setup function is called once at startup of the sketch
void setup()
{
	  // Initialize serial port and wait for it to open before continuing.
	  Serial.begin(115200);
	  while (!Serial) {
	    delay(100);
	  }
	  Serial.println("Adafruit SPI Flash FatFs Full Usage Example");

	  // Initialize flash library and check its chip ID.
	  if (!flash.begin()) {
	    Serial.println("Error, failed to initialize flash chip!");
	    while(1) yield();
	  }

	  Serial.print("JEDEC ID: "); Serial.println(flash.getJEDECID(), HEX);
	  Serial.print("Flash size: "); Serial.println(flash.size());
	  Serial.flush();

	  // First call begin to mount the filesystem.  Check that it returns true
	  // to make sure the filesystem was mounted.
	  if (!fatfs.begin(&flash)) {
	    Serial.println("Error, failed to mount newly formatted filesystem!");
	    Serial.println("Was the flash chip formatted with the SdFat_format example?");
	    while(1) yield();
	  }
	  Serial.println("Mounted filesystem!");
	  Serial.println();

	  // create directory mischianti if not exist
	  if (!fatfs.exists("/mischianti")) {
	    Serial.println("mischianti directory not found, creating...");

	    // Use mkdir to create directory (note you should _not_ have a trailing slash).
	    fatfs.mkdir("/mischianti");

	    if ( !fatfs.exists("/mischianti") ) {
	      Serial.println("Error, failed to create directory!");
	      while(1) yield();
	    }else {
	      Serial.println("Created directory!");
	    }
	  }
	  Serial.println();

	  // Create a file
	  File writeFile = fatfs.open("/test.txt", FILE_WRITE);
	  if (writeFile) {
		  Serial.println("Opened file /test.txt for writing/appending...");

		  // Once open for writing you can print to the file as if you're printing
		  // to the serial terminal, the same functions are available.
		  writeFile.println("www.mischianti.org");
		  writeFile.print("Write a number: "); writeFile.println(123, DEC);
		  writeFile.print("Write HEX number: 0x"); writeFile.println(123, HEX);

		  // Close the file when finished writing.
		  writeFile.close();
		  Serial.println("Wrote to file /test.txt!");
	  } else {
		  Serial.println("Error, failed to open test.txt for writing!");
		  while(1) yield();
	  }

	  Serial.println();

	  // Now open the same file but for reading.
	  File readFile = fatfs.open("/test.txt", FILE_READ);
	  if (readFile) {
		  // Read a line of data:
		  String line = readFile.readStringUntil('\n');
		  Serial.print("First line of test.txt: "); Serial.println(line);

		  // You can get the current position, remaining data, and total size of the file:
		  Serial.print("Total size of test.txt (bytes): "); Serial.println(readFile.size(), DEC);
		  Serial.print("Current position in test.txt: "); Serial.println(readFile.position(), DEC);
		  Serial.print("Available data to read in test.txt: "); Serial.println(readFile.available(), DEC);

		  char filename[64];
		  readFile.getName(filename, sizeof(filename));
		  Serial.print("File name: "); Serial.println(filename);

		  Serial.print("Is file a directory? "); Serial.println(readFile.isDirectory() ? "Yes" : "No");
	  } else {
		  Serial.println("Error, failed to open test.txt for reading!");
		  while(1) yield();
	  }
	  Serial.println();

	  // You can open a directory to list all the children (files and directories).
	  File testDir = fatfs.open("/");
	  if (testDir) {
		  if (!testDir.isDirectory()) {
			Serial.println("Error, expected test to be a directory!");
			while(1) yield();
		  }
		  Serial.println("Listing children of directory /:");
		  File child = testDir.openNextFile();
		  while (child) {
			Serial.print(child.size()); Serial.print("bytes \t");

			char filename[64];
			child.getName(filename, sizeof(filename));

			// Print the file name and mention if it's a directory.
			Serial.print("- "); Serial.print(filename);
			if (child.isDirectory()) {
			  Serial.print(" (directory)");
			}
			Serial.println();
			// Keep calling openNextFile to get a new file.
			child = testDir.openNextFile();
		  }
		  Serial.println();
		  Serial.println("All file in the directory writed");
	  } else {
			Serial.println("Error, failed to open test directory!");
			while(1) yield();
	  }

}

// The loop function is called in an endless loop
void loop()
{

}

Ed ecco l’uscita seriale.

Connetti alla porta seriale COM10 a 115200
Adafruit SPI Flash FatFs Full Usage Example
JEDEC ID: EF4017
Flash size: 8388608
Mounted filesystem!

mischianti directory not found, creating...
Created directory!

Opened file /test.txt for writing/appending...
Wrote to file /test.txt!

First line of test.txt: www.mischianti.org

Total size of test.txt (bytes): 2845
Current position in test.txt: 20
Available data to read in test.txt: 2825
File name: test.txt
Is file a directory? No

Listing children of directory /:
2845bytes 	- test.txt
0bytes 	- mischianti (directory)

All file in the directory writed

Grazie

  1. Arduino SAMD NINA: piedinatura, specifiche e configurazione Arduino IDE
  2. Arduino SAMD NINA: WiFiNINA, aggiornamento firmware e led RGB
  3. Arduino SAMD (NANO 33 e MKR): file system FAT su memoria flash SPI esterna
    1. Shield Arduino NANO 33 IoT per supporto memorie Flash SPI
    2. Shield Arduino MKR WiFi 1010 per supporto memorie Flash SPI
  4. i2c Arduino SAMD MKR: interfaccia aggiuntiva SERCOM, rete e scanner di indirizzi
  5. Arduino MKR SAMD: file system FAT su memoria flash SPI esterna
  6. Collegamento dell’EByte E70 ai dispositivi Arduino SAMD (Nano 33, MKR…) e un semplice sketch di esempio

Spread the love

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *