Temperature sensor and HIFIVE1

(Daniel kirubakaran) #1

Anybody worked with temperature sensors like DS3231 RTC Module ,DHT11 or any other with HIFIVE1?

if so, i need your help!

Because i want to do a mini project with temp sensors,i 've got a sample code from one of the tutorials sites , i tried it with HIFIVE1 with some modifications in that code ,i am getting some following errors.

…Downloads/DemoPrograms/ILI9341_RTC/ILI9341_RTC.ino:93: undefined reference to `String::String(float, unsigned char)'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board HiFive 1.

and my code is show

#include “Adafruit_GFX.h”
#include “Adafruit_ILI9341.h”
#include <Wire.h>
//#include <iostream.h>
#include “Sodaq_DS3231.h”
#include <SPI.h>

//added manually
extern “C”
void *__dso_handle = NULL;

#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

float maxTemperature=0;
float minTemperature=200;
char charMinTemperature[10];
char charMaxTemperature[10];
char timeChar[100];
char dateChar[50];
char temperatureChar[10];

float temperature = 0;
float previousTemperature = 0;

uint32_t old_ts;

String dateString;
int minuteNow=0;
int minutePrevious=0;

//added Manually from
char *dtostrf (float val, signed char width, unsigned char prec, char *sout) {
char fmt[20];
sprintf(fmt, “%%%d.%df”, width, prec);
sprintf(sout, fmt, val);
return sout;
void setup(){



// printText(“TEMPERATURE”, ILI9341_GREEN,20,130,3);
// printText(“MAX”, ILI9341_RED,37,260,2);
// printText(“MIN”, ILI9341_BLUE,173,260,2);


void loop()
float temperature = rtc.getTemperature();
DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();

if (old_ts == 0 || old_ts != ts) {

old_ts = ts;

minuteNow = now.minute();
dateString = getDayOfWeek(now.dayOfWeek())+", “;
dateString = dateString+String(now.date())+”/"+String(now.month());
dateString= dateString+"/"+ String(now.year());
minutePrevious = minuteNow;
String hours = String(now.hour());
hours = hours+":0"+String(now.minute());
hours = hours+":"+String(now.minute());


// printText(timeChar, ILI9341_WHITE,55,55,4);
// printText(dateChar, ILI9341_GREEN,8,5,2);

if(temperature != previousTemperature)
previousTemperature = temperature;
String temperatureString = String(temperature,1);
// printText(temperatureChar, ILI9341_WHITE,50,180,4);
// printText(“o”, ILI9341_WHITE,158,175,3);
// printText(“C”, ILI9341_WHITE,180,180,4);

maxTemperature = temperature;
dtostrf(maxTemperature,5, 1, charMaxTemperature);
// printText(charMaxTemperature, ILI9341_WHITE,8,290,2);
// printText(“o”, ILI9341_WHITE,70,280,2);
// printText(“C”, ILI9341_WHITE,85,290,2);
if(temperature < minTemperature)

minTemperature = temperature;
dtostrf(minTemperature,5, 1, charMinTemperature);
// printText(charMinTemperature, ILI9341_WHITE,145,290,2);
// printText(“o”, ILI9341_WHITE,207,280,2);
// printText(“C”, ILI9341_WHITE,222,290,2);

void setRTCTime()
DateTime dt(2018, 4, 2, 13, 13, 30, 1); // Year, Month, Day, Hour, Minutes, Seconds, Day of Week
rtc.setDateTime(dt); //Adjust date-time as defined ‘dt’ above

void printText(char *text, uint16_t color, int x, int y,int textSize)
tft.setCursor(x, y);

String getDayOfWeek(int i)
case 1: return “Monday”;break;
case 2: return “Tuesday”;break;
case 3: return “Wednesday”;break;
case 4: return “Thursday”;break;
case 5: return “Friday”;break;
case 6: return “Saturday”;break;
case 7: return “Sunday”;break;
default: return “Monday”;break;

but the same code gets successful compilation with arduino uno board.
I checked with the WString.h/.c in the arduino packages and compared it with arduino files also.Couldn’t get the exact problem.

(Daniel kirubakaran) #2

Typo~ Shown below

(Rakesh) #3

Library what they provided is not compatible for sifive you have to check with the Adafruite family sensors there you can get the compatible library for sifive

(Daniel kirubakaran) #4

I completed my project on this topic.Thank you anyways.


Daniel, how did you resolve the problem?

(Daniel kirubakaran) #6

In the beginning i tried this in arduino ide ,unfortunately Wire.h library is notavailable for hifive1 to execute DS3231, later i searched for software i2c for hifive1 ,this link helped me out https://github.com/hasanunlu/i2c_demo_for_HiFive1. With that as reference i just converted my entire program into C files including adafruit ili9341 , gfx and also software spi .Then compiled and uploaded from ubuntu terminal command.

Note: float printf values were not supported while writing in C file so i just added
asm (" .global _printf_float"); after all the inclusions.

Another way,
using arduino ide
now westerndigital has provided libraries for software i2c and uart ,ref:https://github.com/westerndigitalcorporation/cinco/tree/master/hardware/freedom_e/libraries
works well in windows ,choose the recent sifive version 1.0.7, and for adafruit_ili9341 library just go to https://github.com/sifive/Adafruit_ILI9341/find/freedom_e300 replace cpp and H file with this one,you could see the real speed of Hifive1.As usual download Sodaq_DS3231 library.