Main Site Documentation

Can't get temp module to print stats


#1

Hey Guys,
I’m a novice to c++ and was wondering if someone can help me figure out whats going wrong here.

// tested with GHI Gadgeteering 2013 R1 Beta
// Arduino Environment version 1.5.5 Beta

// All Gadgeteering Sketches require these includes:
 #include <Wire.h>
 #include <SPI.h>
 #include <Gadgeteering.h>


 #include <Mainboards/FEZMedusaS12.h>
 #include <Modules/TempHumidity.h>
 #include <Modules/CharacterDisplay.h>

using namespace gadgeteering;
using namespace gadgeteering::mainboards;
using namespace gadgeteering::modules;


fez_medusa_s12 board;
// add variables for each module you are using
temp_humidity *room_weather;
character_display *char_board;

unsigned int temperature;
unsigned int humidity;

void setup() {
  Serial.begin(9600);
 room_weather = new temp_humidity(3);
 room_weather->take_measurements(double& temperature, double& humidity);
 char_board = new character_display(12);
 char_board->print("Temperature: " + temperature + " Relative Humidity: " + humidity);
 
 
}
 
void loop() {

}

this is the error report:
room_temp.ino: In function ‘void setup()’:
room_temp:30: error: expected primary-expression before 'double’
room_temp:30: error: expected primary-expression before 'double’
room_temp:32: error: invalid operands of types ‘const char*’ and ‘const char [21]’ to binary ‘operator+’

thanks in advance


#2

you do not need to include “double” in call to method.

you can not concatenation integers and strings


#3

thanks, mike. but when I do it gives me this:

room_temp.ino: In function ‘void setup()’:
room_temp:30: error: no matching function for call to 'gadgeteering::modules::temp_humidity::take_measurements(unsigned int&, unsigned int&)'
C:\Users----\Documents\Arduino\libraries\Gadgeteering\src/Modules/TempHumidity.h:42: note: candidates are: void gadgeteering::modules::temp_humidity::take_measurements(double&, double&)


#4

read error carefully. it is telling you what is the problem, and how to fix it.


#5

Thanks, I got it reading the temp and humidity in the serial monitor, but it wont print to the character display

// tested with GHI Gadgeteering 2013 R1 Beta
// Arduino Environment version 1.5.5 Beta

// All Gadgeteering Sketches require these includes:
 #include <Wire.h>
 #include <SPI.h>
 #include <Gadgeteering.h>


 #include <Mainboards/FEZMedusaMini.h>
 #include <Modules/TempHumidity.h>
 #include <Modules/CharacterDisplay.h>

using namespace gadgeteering;
using namespace gadgeteering::mainboards;
using namespace gadgeteering::modules;



fez_medusa_mini board;
// add variables for each module you are using
temp_humidity *room_weather;
character_display *char_board;


double temperature = 0;
double humidity = 0;

void setup() {
 Serial.begin(9600);
 room_weather = new temp_humidity(3);
 room_weather->take_measurements(temperature, humidity);
 char_board = new character_display(1);
 char_board->print(temperature);
 
  Serial.println("temp:" );
  Serial.println(temperature);
 
 Serial.println("humidity:" );
 Serial.println(humidity);
 
}
 
void loop() {

}

#6

I don’t have the char display interface for medusa in mind, but what is the parameter type of the char_board->print() method?
may be you need to convert temperature into a string before calling print.
You can use sprint to do so.
I did exactly that with the N18 display.


#7

yeah print() only allows const and char,

New to c++, not sure how to go about converting it, do you have a small code sample you can show me.


#8

Try this:

;
sprintf(buffer, "Temp: %d", temperature);
char_board->print(buffer);

“%d” will be replaced with your temperature.
If you want to have decimal places you need to do that on your own because %f is not supported.
Google for “arduino convert float to string” and you will find several solutions.


#9

huge thx! it worked :slight_smile:


#10

If anyone’s wondering to get it to decimals I used this:

dtostrf(temperature, 2, 1, dtostrfbuffer);
char_board->print(dtostrfbuffer);

Thx again Mike + Reinhard :slight_smile:


#11

Whats the cmd for a new line, because \n isn’t working


#12

If you have the 2x16 char display (or similar) a new line wont work.
The should be method that allows to set cursor position or a print method that accepts the start position (row and column).