Error in MAX7219 library while read temperature sensor

Hello everyone, I’m using Max7219 library for programming and I have some problems:

I have temperature / humidity sensor, I want to see temperature in my 7 segment display (8 digit, max7219)

The code is:

// Demo of MAX7219 library
// Author: Nick Gammon
// Date: 17 March 2015

#include <SPI.h>
#include <bitBangedSPI.h>
#include <MAX7219.h>
#include <Wire.h>
#include <Si7021.h>

const byte chips = 1;
MAX7219 display (chips, 10, 11, 13);  // Chips / LOAD / DIN / CLK

SI7021 si7021; //Temp/humidity sensor

void setup ()
  {
   si7021.begin();
   si7021.setTemperatureRes(12);
   display.setIntensity (6);
  }  // end of setup

void loop ()
  {
   display.sendString (si7021.readTemp());
   delay (1000);
}

The issue is when loading the sketch to Arduino Uno, gets:

Demo.ino: In function ‘void loop()’:
Demo:24: error: no matching function for call to ‘MAX7219::sendString(float)’

display.sendString (si7021.readTemp());
^
Demo.ino:24:45: note: candidate is:
Demo.ino:7:0:
ArduinolibrariesMAX7219-master/MAX7219.h:42:10: note: void MAX7219::sendString(const char*)

void sendString (const char * s);
^
ArduinolibrariesMAX7219-master/MAX7219.h:42:10: note: no known conversion for argument 1 from ‘float’ to ‘const char*’

exit status 1
no matching function for call to ‘MAX7219::sendString(float)’

And I don’t have idea how solve this, please tell me what to do for solve this issue in the Max7219.cpp and Max7219.h files.

The sensor library works perfectly in LCD 16x2 and others LCD’s but in the Max7219 -7 segment dispay- don’t work :frowning:

The library works fine for standard numbers and letters but not for reading sensors.

I want to build a weather station using the Max7219 -7 segment display- (I have a lot of this displays)

Thank you for help me,
Benjamin.

I uploaded the .h and .cpp files, check it.

MAX7219.h (1.19 KB)

MAX7219.cpp (5.43 KB)

void sendString (const char * s);

display.sendString (si7021.readTemp());

u are sending a float value to sendString()

@BenjaminJ: Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

Please use code tags.

Read this before posting a programming question


As backwoodsjack said, the sendString function is for printing strings. You can convert floats to a string like this:

 float f = 42.56;
  char buf [20];
  dtostrf (f, 10, 4, buf);  // number, width, decimal places, buffer

Now you could print “buf”.

Thank you very much Nick! Finally I could make it work!

Now, how get temperature and humidity displayed on the screen at the same time?

Here is a video that I recorded, look:

As seen in the video, on the left side is humidity and the right side is temperature, sendString function only allows a reading separately. How do to the display shows the temperature and humidity at the same time?

Here is the full code:

// Demo of MAX7219 library
// Author: Nick Gammon
// Date: 17 March 2015

#include <SPI.h>
#include <bitBangedSPI.h>
#include <MAX7219.h>
#include <Wire.h>
#include <Si7021.h>

const byte chips = 1;
MAX7219 display (chips, 10, 11, 13);  // Chips / LOAD / DIN / CLK

SI7021 si7021; //Temp/humidity sensor

void setup ()
  {
   si7021.begin();
   si7021.setHumidityRes(12);

       display.begin();
       display.setIntensity (2);

  }  // end of setup

void loop ()
{
   float h = si7021.readHumidity();
   float t = si7021.readTemp();
       
       char temp [20];
       char hum [20];
       
          dtostrf (h, 0, 2, hum); // number, width, decimal places, buffer 
          dtostrf (t, 9, 2, temp); // number, width, decimal places, buffer 
        
    display.sendString (hum);
    display.sendString (temp);
    
delay (300);
}

Really, I appreciate your help.
Thank you

          dtostrf (h, 0, 2, hum); // number, width, decimal places, buffer

In a field width at least 0 characters wide, put the whole number, the decimal point, and two digits of the fractional portion of the value. Hmmm.

          dtostrf (t, 9, 2, temp); // number, width, decimal places, buffer

In a field width at least 9 characters wide, put the whole number, the decimal point, and two digits of the fractional portion of the value. How is that, along with anything else, going to fit on a 8 character display?

If display.sendString() is blanking the display, populate the string properly, and combine the two strings into one. strcpy() and strcat() look useful.

As seen in the video, on the left side is humidity and the right side is temperature, sendString function only allows a reading separately.

Make up a string first, eg. using sprintf. Then display that string.

Thanks Nick, I have tried this but I don’t know how do it, you can write me the string? I’m confused with this, thank you!

PaulS:

          dtostrf (h, 0, 2, hum); // number, width, decimal places, buffer

In a field width at least 0 characters wide, put the whole number, the decimal point, and two digits of the fractional portion of the value. Hmmm.

          dtostrf (t, 9, 2, temp); // number, width, decimal places, buffer

In a field width at least 9 characters wide, put the whole number, the decimal point, and two digits of the fractional portion of the value. How is that, along with anything else, going to fit on a 8 character display?

If display.sendString() is blanking the display, populate the string properly, and combine the two strings into one. strcpy() and strcat() look useful.

Thank you Paul, I have tried this but I don't know how do it, you can write me the string? I want to see temp and humidity at the same time in the display, how combine both? Thanks.

BenjaminJ:
Thanks Nick, I have tried this but I don't know how do it, you can write me the string? I'm confused with this, thank you!

Learn to Google as there are plenty of sprintf examples such as Sprintf C : Understanding How the sprintf () Function Works in C - Udemy Blog

but I don't know how do it

Oh, come on now. 12 year old boys know how to do "it".

If the "it" that you don't know how to do is to use strcat() or strcpy() to populate a string, why haven't you googled those functions? They are dirt-simple to use.

PaulS:
Oh, come on now. 12 year old boys know how to do "it".

Careful bandying the word "it" around: Knights who say Ni.