LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the SD card adapter with myrio

 

Hi everybody;

 

I have a microsd card adapter.microsd card adapter.png

 


I want to write data in ''.xlsx'' format to sd card using myRIO's SPI pins. Is it possible to do this?

If anyone knows how to do this or gives an example, it would be really helpful. thanks everyone for their help

0 Kudos
Message 1 of 8
(1,860 Views)

I would say "Yes, it is probably possible, but extremely difficult and challenging".  Here's what you need to do:  

  • Obtain or create a proper Excel .xlsx file.  You can easily do this on a PC with Microsoft Office (you don't even need LabVIEW to create an Excel Workbook, you just need Excel).
  • Copy the .xlsx file onto an SD card using the SD slot in your PC (or purchase a SD Reader/Writer that plugs into a USB port on your PC and costs less than $20).
  • Use your myRIO for its intended purpose, being a Real-Time Target for LabVIEW's Real-Time module.

Suppose you somehow transfer an Excel .xlsx file to the myRIO and you want to write it (from the myRIO) onto an SD card.  Again, for $25, you can get a USB SD R/W device, and have only to think about how Linux File I/O works -- will the files be easily readable on a Windows PC?  [This is not something I do, so I've got no opinion here].

 

Suppose you only want to play with SPI, and want to know if the myRIO supports SPI.  Yes, it does.  The myRIO Software Toolkit has Express VIs for two SPI channels, and excellent Videos on the Web showing how to use them.  But you can "roll your own" and do many more.  We wrote custom FPGA routines that let us run SPI signals (SCLK, CSEL, MISO, and MOSI) to 16 A/D chips that let us acquire 4-channel A/D at 100 Hz, but with a timing accuracy (relative to the A/D "Convert" pulse) on the order of 200 µs, using three DIO lines for SCLK, CSEL, and MOSI, and 16 lines for MISO.

 

Bob Schor

 

0 Kudos
Message 2 of 8
(1,818 Views)

@Bob_Schor wrote:

I would say "Yes, it is probably possible, but extremely difficult and challenging".  Here's what you need to do:  

  • Obtain or create a proper Excel .xlsx file.  You can easily do this on a PC with Microsoft Office (you don't even need LabVIEW to create an Excel Workbook, you just need Excel).
  • Copy the .xlsx file onto an SD card using the SD slot in your PC (or purchase a SD Reader/Writer that plugs into a USB port on your PC and costs less than $20).
  • Use your myRIO for its intended purpose, being a Real-Time Target for LabVIEW's Real-Time module.

Suppose you somehow transfer an Excel .xlsx file to the myRIO and you want to write it (from the myRIO) onto an SD card.  Again, for $25, you can get a USB SD R/W device, and have only to think about how Linux File I/O works -- will the files be easily readable on a Windows PC?  [This is not something I do, so I've got no opinion here].

 

Suppose you only want to play with SPI, and want to know if the myRIO supports SPI.  Yes, it does.  The myRIO Software Toolkit has Express VIs for two SPI channels, and excellent Videos on the Web showing how to use them.  But you can "roll your own" and do many more.  We wrote custom FPGA routines that let us run SPI signals (SCLK, CSEL, MISO, and MOSI) to 16 A/D chips that let us acquire 4-channel A/D at 100 Hz, but with a timing accuracy (relative to the A/D "Convert" pulse) on the order of 200 µs, using three DIO lines for SCLK, CSEL, and MOSI, and 16 lines for MISO.

 

Bob Schor

 


Thanks for answer.

I have tested with a usb flash disk before and i am saving the data but i want to do this for a normal SPI SD card reader because usb port is full and using it with usb hub creates more complexity.

I can't find an example that can check or write the contents of any file on the sd card using the SPI protocol.
This prevents me from taking the first step. The examples given are only surface examples of using SPI.

I've been looking through the Arduino examples, but I'm still having trouble with exactly how to do it.

 

David

 

0 Kudos
Message 3 of 8
(1,807 Views)

David,

 

     Are you trying to develop code that will run on a "disconnected" myRIO, that is, one that has no TCP/IP connection to a PC "Host" via TCP/IP, either through WiFi or through the USB Cable?  Was your intension to add a larger-size "Disk" to the Linux system running on the myRIO (because its on-board storage is too small for the amount of data you want to save) and you planned to use an SD card?

 

     If so, then you need to basically write a "Disk Driver" that understands low-level Disk I/O, including such things as Directory structures, formatting of drives, how to access and read/write specific "blocks" on the disk, etc., etc.  This is definitely beyond my skills ...

 

     On the other hand, if the myRIO is connected to a PC running Windows, you are in luck, because (a) Windows knows all about writing to disk files (even SD cards), and (b) there are several protocols that let a Windows "Host" transfer data back and forth with a Real-Time Target (think "myRIO") running NI Linus LabVIEW Real-Time.  Personally, I use Network Streams to send messages and data between the PC and the myRIO, but you can also use straight TCP/IP.

 

Bob Schor

 

P.S. -- just dreamt up another solution -- get a second myRIO, buy the $20 SD Reader/Writer for it, and make the second myRIO into a myRIO-SD machine.  You set up a protocol that lets the first myRIO send a command to the second to receive header + data, and then transfer the data.  The myRIO-SD opens a file on the SD Drive (using information in the just-received header), then fills it with data, closing the file when the first myRIO says "Close File".  Now all (?) you have to do is figure out how to use the USB port to "plug in" an external drive and access that Drive in LabVIEW-RT.  I'm assuming this is possible (though I haven't tried to do this), otherwise why is the USB port included?

0 Kudos
Message 4 of 8
(1,784 Views)

@Bob_Schor wrote:

David,

 

     Are you trying to develop code that will run on a "disconnected" myRIO, that is, one that has no TCP/IP connection to a PC "Host" via TCP/IP, either through WiFi or through the USB Cable?  Was your intension to add a larger-size "Disk" to the Linux system running on the myRIO (because its on-board storage is too small for the amount of data you want to save) and you planned to use an SD card?

 

     If so, then you need to basically write a "Disk Driver" that understands low-level Disk I/O, including such things as Directory structures, formatting of drives, how to access and read/write specific "blocks" on the disk, etc., etc.  This is definitely beyond my skills ...

 

 



Thanks for the answer.
I guess using the SD card adapter will be a bit of a hassle.
Basically, let me describe the app I want to build.

-I want the created application to save its logs in excel format on an sd card, and then I will have the opportunity to examine this logs on windows. Also, if myRIO is damaged, I'm more likely to protect it from damage because the sd card is small, and I can still recover the app logs saved on the sd card.
Since I can't use the SD card adapter. alternatively:
If there's a space in myRIO that I can use to store information, that's enough(If myrio is not damaged, I will transfer data from stored location to windows using usb).
-Is there a storage space I can use to save several excel files?

 

David

0 Kudos
Message 5 of 8
(1,767 Views)

OK, the key question remains unanswered!  When you run the application you want to run, will the myRIO be "all by itself", that is, not connected (by a USB cable or through WiFi) to a PC, or is a PC part of the picture?

 

If the myRIO is "all by itself", I then need to ask "What do you mean by "save logs in Excel format"?  Do you mean "Write my data as a text file organized in rows and columns, with commas or tabs separating columns and end-of-lines separating rows", or do you mean "Save my data as an Excel Workbook using the Report Generation Toolkit or third-party software"?

 

You can certainly write text files, and you can certainly save them on the myRIO's limited non-volitile memory (512 MB).  How were you planning on getting them off, other than by connecting the myRIO to a PC?  Again, if it is connected while you are running whatever application you plan to run on the myRIO, do it right, as a LabVIEW Real-Time Project, with the Nost code on the PC (where you have access to the PC's rather-more copious disk space, to say nothing of memory, processor speed, etc.

 

Bob Schor

0 Kudos
Message 6 of 8
(1,751 Views)

thans for answer  

 

-Yes, myRIO will be standalone. It will not connect to any PC. myRIO will not have a USB or wifi connection away from me for a certain period of time (example 5 hours) and will wait at that location. After the specified time expires (since I cannot record to the SD card), I will need to bring myRIO from there and transfer the data to my own PC with a USB cable.

-Logs can be in the form of any text file (but I will need to use a comma between the data as it needs to be organized so that the rows and columns can be separated)

 

DavidHammer_0-1674455810615.png

-Which location will I need to choose (at the locations in the picture above) to save the data to myRIO memory ? So which one is more suitable?

 

David

0 Kudos
Message 7 of 8
(1,742 Views)

A good question (and a reasonable decision for your situation).  This article discusses how NI "maps" Windows file paths to Linux-RT.  You'll notice that they show a path to "/home/lvuser/test.txt".  I think the path I would suggest, as it is unlikely to mess up anything, is /home/lvuser/LabVIEW Data/ (note that there's a space between "LabVIEW" and "Data", despite what Linux likes).

 

Given what you are doing, using the Delimited Spreadsheet might be quite reasonable.  If we guestimate that a "record" is 100 bytes and you generate one record/second, in 5 hours you will generate 1.8 Mbytes.

 

Bob Schor

0 Kudos
Message 8 of 8
(1,682 Views)