Terminal Serial input from a human typing at a keyboard.
Duane C. Johnson
Posts: 955
Hi guys;
I'm just getting started with PropellerGCC C.
I've been testing code snippets on a clone of the PropStick, thanks to Andrew William's M44D40+ .
So much easier than my home brew PropSticks. Thanks Andrew.
My problem is how do I communicate with the Prop through the serial terminal.
I have the printf() output to the terminal working OK.
However, the scanf() input from the terminal doesn't work for me and I don't know why?
Here is the code snippit I'm testing:
scanf
So what am I doing wrong?
Duane J
I'm just getting started with PropellerGCC C.
I've been testing code snippets on a clone of the PropStick, thanks to Andrew William's M44D40+ .
So much easier than my home brew PropSticks. Thanks Andrew.
My problem is how do I communicate with the Prop through the serial terminal.
I have the printf() output to the terminal working OK.
However, the scanf() input from the terminal doesn't work for me and I don't know why?
Here is the code snippit I'm testing:
#include "stdio.h" #include "float.h" #include "math.h" #include "simpletools.h" float main() { char str [80]; float DEG, D2R, SIN, COS, TAN; DEG = 12.345678; // Preload a float angle in degrees for test. pause(250); // Needed to allow the terminal to get started. printf("Enter an angle in degrees?\n\a"); for (int n = 1; n <= 4; n++) // try it 4 times { //scanf("%f",DEG); // I enteres 30 or 30.0 or anything else // yet DEG contains 12.345678 when done. scanf("%f",&DEG); // I enteres 30 or 30.0 or anything else // yet DEG contains 0.0 when done. // so something happened to DEG but what? //scanf("%f*",DEG); // I enteres 30 or 30.0 or anything else // yet DEG contains 12.345678 when done. //scanf("%f*",&DEG); // I enteres 30 or 30.0 or anything else // yet DEG contains 0.0 when done. // so something happened to DEG but what? // Do some float calculations D2R = 180.0 / PI; SIN = sin(DEG / D2R); COS = cos(DEG / D2R); TAN = tan(DEG / D2R); printf("%d DEG = %f SIN = %1f COS = %f TAN = %f\n\a",n , DEG, SIN, COS, TAN); } printf("Done.\n\a"); }The documentation I'm using is here:
scanf
So what am I doing wrong?
Duane J
Comments
I used this command line to build it: Here is the output I got:
This is one of the primary reasons for using simpletext.h or simpletools.h - no immediate failures.
The biggest reason of course is so that you'll have room for other code without more surprizes.
Also, please don't use "float main()", use "int main(void)" instead.
Please go through Andy's tutorials.
By the way, why do these posted examples always seem to use "stdio.h" instead of <stdio.h>? Is this something that the Parallax tutorials suggest? If so, why?
I added angle brackets "<>" to stdio.h
Added the define PI but I know the PI didn't need defining.
I am using "SimpleIDE 0.9.45"
This is the terminal output. This is in the "Build Status" box
It apparently compiled correctly. In "Project Options" I have
"PROPSTICK" although "GENERIC" and "EEPROM" do the same thing.
C++
CMM Main RAM Compact
-Os Size
in "Compiler" the "32bit Double" box is checked and
-std=c99
is already in the "Other Compiler Options".
in "Linker" the "MATH lib" is checked.
I added
-lm
in the "Other Linker Options"
Where do I put the rest of the suggested options?
propeller-elf-gcc -Os -mcmm -std=c99 -o test.elf test.c -lm
Maybe they are already there in the "SimpleIDE Properties".
GCC Compiler "C:/Program Files (x86)/SimpleIDE/bin/../propeller-gcc/bin/propeller-elf-gcc.exe"
Library Folder "C:/Users/Shirley/Documents/SimpleIDE/Learn/Simple Libraries"
Workspace Folder "C:/Users/Shirley/Documents/SimpleIDE/"
Where do I find "Andy's tutorials" ?
Duane J
Looks like we have some work to do there
I use simple library calls and it works fine.
Learn Parallax PropellerC: http://learn.parallax.com/propeller-c
For some reason it started to work.
And I can't see for the life of me reason why.
Heck, I can't get it to fail now, except for obvious errors which wont compile anyway.
What I am doing is attempting to do calculate the bisector angle between 2 spherical angles.
This is the orientation of a heliostat, a flat mirror, between the sun and a target.
I have done this in BASIC on a PC but now want to do it on the Prop using C.
A really good reference is here:
Calculate distance, bearing and more between Latitude/Longitude points.
Equations and all.
I like doing solar trackers.
In this case I want an SD card that has precalculated solar position data for 30 years or so, at least 10. These bisector calculations are much easier to do than the full equation of time calculations. Just look of the sun and move the mirror. And float precision is plenty accurate. Unlike with the full calculation.
Anyway, thanks for the assistance. What ever it was %^)
Duane J