Since itoa stands for "Integer to Alpha" you are correct
that you are using the wrong function. You want an ftoa()
which usually doesn't exist. You might be able to use
sprintf(), but it will drag a lot of code into your
module, if it exists.
I generally advise avoiding floating point on our
controllers because they have only minimal integer
math support.
MS
Debasmit Banerjee wrote:
> Hi,
>
>
>
> I am fairly new to TinyOS. I want to read the battery voltage for my
> application. The values I am getting for VBatt vary like 7,8,9,10,11 for
> different batteries I use. I am storing the VBatt in a float. And I am
> sending the value through the serial port to display in a terminal. I am
> using itoa() to convert the float value to string which is sent to the
> serial port using Serial.send() – this might be incorrect because I am
> using itoa() for a float value. I don’t know how else to check the value
> of the voltage, but I don’t know how to convert float to string.
>
> I don’t know whether the problem might be this or something else.
>
>
>
> The code I use is this:
>
>
>
> Sensorboard.h:
>
>
>
> #define MAKE_BAT_MONITOR_OUTPUT() sbi(DDRA, 5)
>
> #define MAKE_BAT_ADC_INPUT() cbi(DDRF, 7)
>
> #define SET_BAT_MONITOR() sbi(PORTA, 5)
>
> #define CLEAR_BAT_MONITOR() cbi(PORTA, 5)
>
>
>
>
>
> Test.nc:
>
>
>
> TestM.BattControl->Voltage;
>
> TestM.ADCBATT ->Voltage;
>
>
>
>
>
>
>
> TestM.nc:
>
>
>
> uses
>
> {
>
> interface ADC as ADCBATT;
>
> interface StdControl as BattControl;
>
> }
>
>
>
> Implementation
>
> {
>
> float vBatt;
>
>
>
> command result_t StdControl.init()
>
> {
>
>
>
> call BattControl.init();
>
> return SUCCESS;
>
> }
>
>
>
> command result_t StdControl.start()
>
> {
>
> call BattControl.start();
>
> return SUCCESS;
>
> }
>
>
>
> command result_t StdControl.stop()
>
> {
>
> call BattControl.stop();
>
> return SUCCESS;
>
> }
>
>
>
> async event result_t ADCBATT.dataReady(uint16_t datas)
>
> {
>
> vBatt = 1.223*1024/datas;
>
>
>
> return SUCCESS;
>
> }
>
>
>
> event result_t MyTimer.fired()
>
> {
>
> SET_BAT_MONITOR();
>
> call ADCBATT.getData();
>
> CLEAR_BAT_MONITOR();
>
>
>
> itoa(vBatt, temp, 10);
>
> call Serial.Send(temp, strlen(temp));
>
>
>
> }
>
>
>
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help