Dtostrf() problems

Hi,

Can anyone advise me on this problem? I am trying to print a float value onto a UTFT screen. After reading several articles which all say to use dtostrf() and use the avr-libc library, I have tried this but cannot get any joy.

#include <AVR_RTC.h>

#include <time.h>
#include <UTFT.h>

UTFT myGLCD(SSD1289, 38, 39, 40, 41);
extern uint8_t BigFont[];
int Htime;              //integer for storing high time
int Ltime;                //integer for storing low time
int long Ttime;            // integer for storing total time of a cycle
float frequency;        //storing frequency
String DisplayFreq;
void setup()
{
    pinMode(A0,INPUT);
    Serial.begin(9600);
    myGLCD.InitLCD();
    myGLCD.clrScr();
    
}
void loop()
{
     myGLCD.clrScr();
    
    myGLCD.print("Frequency of signal",CENTER, 20);

    Htime=pulseIn(A0,HIGH);      //read high time
    Ltime=pulseIn(A0,LOW);        //read low time
    
    Ttime = Htime+Ltime;

    frequency=1000000/Ttime;    //getting frequency with Ttime is in Micro seconds
    dtostrf(frequency,7, 3, DisplayFreq);
    myGLCD.print(DisplayFreq, CENTER, 40);
    myGLCD.print(" Hz",RIGHT,40);
    delay(500);
}

I get this error

fatal error: util/atomic.h: No such file or directory
#include <util/atomic.h>

I am using an Arduino Due and a SSD1289 UTFT

Any help would be appreciated

Steve

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Please post a complete sketch that illustrates the problem

the output buffer needs to be a c-string, char, not a String (see dstrtof())

I think the fourth argument is supposed to be a character array, not a String. Try:
char DisplayFreq[17];

Thanks Guys,

Unfortunately I am still getting this error:

fatal error: util/atomic.h: No such file or directory
#include <util/atomic.h>

I think it is to do with the avr-libc, do you now of a library that works? I seem to be having lots of problems with this one.

Is that the full error message copied using the "Copy error messages" button in the IDE ?

Hi HeliBob

Sorry it wasn't, but have pasted it below

Arduino: 1.8.13 (Windows 10), Board: "Arduino Due (Programming Port)"

C:\Users\Anyuser\Documents\Arduino\libraries\AVR_Standard_C_Time_Library\src\timer2.c:6:25: fatal error: util/atomic.h: No such file or directory

#include <util/atomic.h>

                     ^

compilation terminated.

exit status 1

Error compiling for board Arduino Due (Programming Port).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

So the problem is in line 6 of a file in the AVR_Standard_C_Time_Library library you installed. Perhaps that library wasn't tested on the DUE? Maybe you can find a different library for your RTC hardware.

Hi John,

I think you are right, I routed around on google and found this

Thanks for your comment though

Regrards

Steve

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.