- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
I am currently working on interfacing of flex sensor with the PSOC 4200 but I can't get the analog values(float) to print on the terminal.
Here's the code:
#include <project.h>
#include <stdio.h>
int main()
{
float R_DIV = 47500.0; //47K Ohm approx
float VCC=5.0;
float STRAIGHT_RESISTANCE = 37300.0;
float BEND_RESISTANCE = 90000.0;
uint8 flexADC;
float32 flexV, flexR;
char str[10];
float angle=0.0;
UART_Start();
ADC_Start();
CyGlobalIntEnable;
for(;;)
{
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
flexADC = ADC_GetResult16(0);
flexV = ADC_CountsTo_Volts(0,flexADC);
flexR = R_DIV * (VCC / flexV - 1.0);
UART_PutString("Resistance in Ohms");
sprintf(str,"%.2f ",flexR);
UART_PutString("%s\n",str);
angle= (flexR-STRAIGHT_RESISTANCE)*(90.0-0.0)/(BEND_RESISTANCE-STRAIGHT_RESISTANCE)+0.0;
UART_PutString("Bend angle in degrees");
sprintf(str,"%.2f ",angle);
UART_PutString("%s\n",str);
CyDelay(2000);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum.
Printing floats needs some settings:
- Set "use newlib nano" to true (Project butld settings -> linker)
- Set "use newlib nano float formatting" to true (Project butld settings -> linker)
- Set "Heap Size" to 0x0200 (System view)
That should do the job
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I still can't get the float values on the terminal. What is the API to be used to print float?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your program seems ok so far. Can you please post your complete project or a shortened version that shows the error so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is your program and it is working. I don't have the component you where using for the Flex so I just stuck some default items in the program for resistance and bend angle. The issue was in Project settings it was not working after Resistance in ohms print out. Now it is working you will need to take out the default values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As you didn't send your program I pasted your information in to a PSoc Ble device CY8C4247LQI-BL483 I picked this as your post was in IOT. If that is not the correct device you can change it to your device.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
Thank you Bob for helping me yesterday. I was able to configure my flex sensor.
Can you assist me how I can use the map function in my program
like this:
float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE, 0, 90.0);
instead of
/* angle= (flexR-STRAIGHT_RESISTANCE)*(90.0-0.0)/(BEND_RESISTANCE-STRAIGHT_RESISTANCE)+0.0; */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is how you use MAP