uSD I/O
Rsadeika
Posts: 3,837
I am working with SimpleIDE 0-9-28 on my Windows 7 PC, and below is a simple program example that is found in the Propeller C Tutorials(online). This is a very straight forward program that captures a keypress and then writes to the uSD card. The data that is captured is in byte form, that is handled by a '%d' or '%s' to be presentable on the screen, while on the uSD card it appears as gibberish symbols that is byte code. This is all well and good.
Since I am working on a program that will be obtaining data from a Sensirion SHT11 module, I am wondering how I can manipulate the input data so it would be in a readable form when opened by notepad, or any other such program, when stored on the uSD card. Specifically the form would be a database, so I can present it in graph style or anything else. Another problem arises is when the data is now in a non-byte form, then using an fread command runs into some problems. Any easy solutions for this?
Thanks
Ray
Since I am working on a program that will be obtaining data from a Sensirion SHT11 module, I am wondering how I can manipulate the input data so it would be in a readable form when opened by notepad, or any other such program, when stored on the uSD card. Specifically the form would be a database, so I can present it in graph style or anything else. Another problem arises is when the data is now in a non-byte form, then using an fread command runs into some problems. Any easy solutions for this?
Thanks
Ray
/* SDio.c */ #include "simpletools.h" /* Activity Board */ int DO = 22, CLK = 23, DI = 24, CS = 25; FILE* fp; int main() { // Add startup code here. pause(300); printf("uSD I/O test program.\n"); sd_mount(DO, CLK, DI, CS); fp = fopen("test.txt", "a"); int n,status,m; while(1) { // Add main loop code here. printf("> "); status = scanf("%s", &n); if(!status) break; fwrite(&n, 4, 1, fp); } fclose(fp); /* Display contents of file. */ printf("\nYou entered:\n"); fp = fopen("test.txt", "r"); while(1) { status = fread(&m,4, 1, fp); if(!status) break; printf("n = %d\n", m); } fclose(fp); }
Comments
I'm trying to decide between fixing FSRW to work in xmm-split mode or using the stardard I/O...
But, I can't find a simple example of using standard I/O to just read a file...
Is there one?
Maybe I'll try this example with your changes.
Can I just use stdio.h instead of simpletools.h?
Do I need the simpletools.h to make it work like in this example?
The actual example uses %d, and all that it allows are numbers on the keyboard; I wanted to also capture letters, hence %s. I guess I am breaking SOP with this.
Ray
I noticed the C++ style of variable declaration and wondered it C had added that style since I last used C back in the Turbo C days.
The examples on Parallax site use it and I like it.
I do not think it needs to be pure ANSI C to be a good teaching tool for C and C++ programming and for sure for programming propeller code.
I guess it could also be a bug and we are using the C++ part to the compiler as a default and that was not what was selected in the IDE.
Tom
Ray
I think you are able to include inline declarations in this code because the "Other Compiler Options" has been set to "-std=c99". I think I remember removing that option and having to move all my declarations to the top of functions or as globals... Just a guess as I'm not positive that was the issue.
dgately
dgately
Ray
Yes. Parallax requested that -std=c99 be included on any Simple Projects. If folks don't understand what is trying to be achieved with Simple View and SImple Libraries, they should spend time with the Parallax Propeller C Web Site and Educational Tutorials.
Also, it would be nice to know if things are missing from the User Guide. For example, some of the Simple View -vs- Project View behaviors are not documented. The Propeller-Load document describes using config files and _cfg_ variable patching; it was not included in the User Guide and is available as a separate document. The User Guide content is owned by Parallax. All SimpleIDE Simple View decisions are owned by Parallax.
Simple View is the Parallax version of Project View. You can choose between one view and another with the Menu Tools -> Set Simple/Project View. Simple View is designed for Educational customers. Project View operates the way 0-8-5 did except for some enhancements I thought were useful that were introduced in Simple View such as the New Project methodology (Project View New Project gives a small template for the main file where as Simple View New Project uses the educational templates); the Add Library, Add Tab, and Open Tab tools; the Create Project Library.
As far as C versions, it depends on the requirements and coding standard if any of an organization. Some people are pedantic, uptight, and argumentative; others don't care (people you won't mind working with). If you want a job writing C programs, it's good to know what are the basic extensions to C89 that C99 brings so that you can deal with the pedantic C89 types.
Ray
Ardunio to teach programming in a C or C++ syntax for microcontrollers ie propeller.
For pure ANSI C that should be a seperate class taken by students.
Second back to the original question asked I created an example and attached the
file it created on the SD card and an excel file that used it.
For some reason the file with an extention of csv would not add here so I renamed it txt
Tom
Hopefully as more interest gets stirred up for C, somebody will create some specific C code for using the Sensirion module that Parallax sells, hint, hint. I have a similar prototype with a Sensirion module that uses a GG PPUSB board and it is written in Spin. I want to create something similar that is written in C, then I can do some comparisons.
Ray
What board type are you using when removing the mount? Can you copy/paste the build status here?
Ray
Ray
Ray
Andy
Andy
Ray
1) In Simple View, click the lower-left Show Project Manager button if it isn't already in view.
2) Set Board type to ACTIVITYBOARD-SDXMMC.
3) Set Memory Model to XMMC External Flash Code Main Ram.
After that, you can Run with Terminal, or Load EEPROM & Run. If you use Load EEPROM & Run, make sure to Click Program -> Open Terminal, then Program -> Reset Port.
Andy
Ray
fTemp = sensirionSpin_Gettemperaturef();
Humid = sensirionSpin_Gethumidity();
These two functions are what is causing the problem, which are part of the spin2cpp conversion of the Spin sensirion examples that I used. I guess I could look at the sensirion.c code, but I am not sure what I would be looking for. Maybe somebody can spot the problem, I attached the sensirion stuff.
Ray
sensirion.c
seisirion.h