LCD and SD card fail to co-exist | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
LCD and SD card fail to co-exist
December 3, 2017
3:20 pm
Avatar
vendersgade
Member
Members
Forum Posts: 7
Member Since:
October 31, 2017
sp_UserOfflineSmall Offline

I am using an I2C 2*16 char LED and a Deek-Robot Nano Data Logging Shield (product ID 8105). They both work fine when I interface to them independently from an Arduino Nano, however, when I add them both to the same Nano (as I need to do). They interfere. The SD sheild uses CS PIN 10. Please see attachment for demo code. 

The error produces is rather random. Sometimes the LCD display starts flickering with strange chars, sometimes it just goes blank.

Any help is greatly appriciated.

/søren

SD_card_error.pngImage Enlarger

sp_PlupAttachments Attachments
December 4, 2017
1:04 pm
Avatar
vendersgade
Member
Members
Forum Posts: 7
Member Since:
October 31, 2017
sp_UserOfflineSmall Offline

Further to the above matter.

I tried to locate the problem and whilst I can sucessfully write files to the SD card, I have problems with the SD VIs eating memory and if I run the funktions in a  while loop (logging random data) I usually only get 4-8 iterations before my application crashes. 

Has anyone managed to get the SD vi's to work ?.

I tested my code both with :

Deek-Robot Shield Model 8105 ( CS PIN10) and Deek-Robot Shield Model 8122 and (CS PIN 4)

They both display the same type of erratic behaviour. 

 

Any help would be greatly appriciated.

/søren

December 4, 2017
6:43 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

You likely have a memory leak.  Take a look at the Important Considerations in the user manual.  You have to take care on these platforms as you can easily use up all memory if not coded properly.

In you first VI the problem is that you are creating/initializing the LCD on each iteration.  This is creating a new object for every iteration which will quickly eat up your memory.  You need to pull initialization functions outside the while loop.

In your second VI you are never closing the file.  It is outside the loop which will never terminate, and the close file will never execute.  You should be closing the file to purge the data to disk.  Otherwise it will keep the data in memory and eventually run out.  Take a look at the included "SD Card - Simple Datalogger.vi" example.  This one should run without the issues you are seeing.

December 14, 2017
9:21 pm
Avatar
vendersgade
Member
Members
Forum Posts: 7
Member Since:
October 31, 2017
sp_UserOfflineSmall Offline

Steffan,

Thanks for answering, sorry for making a novice mistake. I moved the init part of the LCD outside the loop, unfortunately it did not help. I still only get aprox. 4 iterations (loops) then the application crashes. Using Visuino I created the same code and get a memory warning when compiling the applicaiton. So, perhaps the root problem is memory capacity rather than memory leak ? Visuino is a cool tool, no doubt about that. But its dwarfed by LabVIEW and no real match to G. 

/søren

 

Deek3.pngImage Enlarger

sp_PlupAttachments Attachments
December 14, 2017
9:24 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

It still appears your file write is outside the loop, as I mentioned is a problem.  That is probably where your memory leak is.

December 14, 2017
9:27 pm
Avatar
vendersgade
Member
Members
Forum Posts: 7
Member Since:
October 31, 2017
sp_UserOfflineSmall Offline

Just one more remark. In the VI "TSX-SD-Card-Log-Data-Deek2.vi", all VIs relating to the LCD have been removed, yet I still get the freezing problem after a few iterations. I tried all my best tricks, however I cant get the SD VIs to run for more than a few iterations.

/søren

December 14, 2017
10:06 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

That VI has the same problem I just mentioned.  Your SD File Close will never run, therefore the data will sit in RAM until you run out.  You need to flush the data to the SD card using the File Close INSIDE the loop.

May 7, 2018
10:53 am
Avatar
mattFitz
Member
Members
Forum Posts: 11
Member Since:
February 19, 2018
sp_UserOfflineSmall Offline

All,

 

I am seeing unexpected results when I use an SD reader with an LCD display.  The attached simplified examples show the issue well.  When I read and display a single line everything is OK.  Wehn I read and display multiple lines from the SD it seems not to work correctly.  Help is appreciated and have spent too many hours on this simple fish tank configuration read. My code is in LabVIEW 2015.

 

Matt

May 7, 2018
7:07 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

It looks like in the case you identified as not working, you are creating an array of string to display on the LCD, but in the loop you are wiring those strings to the same lines on the display with a 300ms update rate.  So not sure what you expect to see but if you don't clear the line first you will see characters from the last string, and 300ms is somewhat fast.  Can you explain what you are seeing?

May 7, 2018
8:32 pm
Avatar
mattFitz
Member
Members
Forum Posts: 11
Member Since:
February 19, 2018
sp_UserOfflineSmall Offline

Tried to upload small image files but exceeds your limits. I was able to crop one down to fit.

 

True case: Works as expected

False Case: Doesn't update the display at all.

False Case / Eject SD: Displays File Not Found (limited to 10 characters) and other strings display correctly.

 FalseWithSDremoved2.jpgImage Enlarger

sp_PlupAttachments Attachments
May 8, 2018
12:39 am
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

I would try getting rid of all your unused code, case selectors and case statements.  Even though you are disabling them with boolean inputs, they are taking up code space and creating a lot of extra memory copies.  And you have an array control with ~100 bytes sitting on the front panel.  Every time your array wires hit case structure boundaries, selectors, etc. you create a memory copy of that complete array.  It could be that you are running out of memory.  Try creating a copy of the VI with all the unnecessary code removed, or use disable structures instead to remove the code. 

May 8, 2018
12:07 pm
Avatar
mattFitz
Member
Members
Forum Posts: 11
Member Since:
February 19, 2018
sp_UserOfflineSmall Offline

That seemed to work.  Trying to find a way to have method of configurable parameter so not stuck with constants.  The SD read functions seem to be using a lot of memory.  Suggestions?  This is only a portion of the program. Can the check unused RAM function be used to check available memory?

May 8, 2018
5:23 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

The SD card library does take up a lot of memory, but that's a function of the core Arduino libraries.  One option is to go to a bigger Arduino platform with more memory.  You can also take a look at the Saving Read-Only Data to Program Memory.vi example.  This shows how you can store large arrays of read-only data to Program Memory instead of RAM.  That might benefit you here.  You can use the check unused RAM function but that doesn't tell you about fragmentation.  You could have 100 bytes free, for example, but not in contiguous space, so if an array is copied that requires more bytes than this, the memory allocation will fail.

May 8, 2018
6:09 pm
Avatar
mattFitz
Member
Members
Forum Posts: 11
Member Since:
February 19, 2018
sp_UserOfflineSmall Offline

I will review your suggestions and get back to you with my solution.  I understand what you are saying about fragmentation and how this can be a real issue on a device with a low amount of RAM.

May 15, 2018
6:39 pm
Avatar
mattFitz
Member
Members
Forum Posts: 11
Member Since:
February 19, 2018
sp_UserOfflineSmall Offline

Well, I upgraded to an Arduino Mega with 4x more RAM and same results.  In my opinion, reading any size SD file is unreliable and have spent way too much time trying to make this work.  I have tried parsing strings, parsing bytes, and reading fixed size fields.

I will be at NI Week next week.  Does the Arduino team plan be there?  I would like to discuss more in person.

Matt

May 17, 2018
9:34 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

mattFitz said
Well, I upgraded to an Arduino Mega with 4x more RAM and same results.  In my opinion, reading any size SD file is unreliable and have spent way too much time trying to make this work.  I have tried parsing strings, parsing bytes, and reading fixed size fields.

I will be at NI Week next week.  Does the Arduino team plan be there?  I would like to discuss more in person.

Matt

 

Can you upload your latest program that is still not working?  We have several complex examples using the SD card interface for file read/write on both an Uno and Mega without any issues.   To answer your question, we will not be at NIWeek this year.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
4
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356