Display on max7219 from DHT11

Hello everyone
I will be happy for some help.
I'm using max7219 8X32 and DHT11
and:
MD_Parola.h
MD_MAX72xx.h
DHT

first of all I'm trying to center the text on the max7219 can someone show me how with explantions? using the Hello in my code?

second I'm trying to display temperate and humidity from the DHT11 to the max7219 but I don't know how to show the text on the max, I have tried all kind of things but nothing help...

thank you



#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

const uint16_t WAIT_TIME = 1000;


#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));
  dht.begin();
  P.begin();
}

void loop(void) {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  P.print("Hello");

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.println(F("°C "));
}

Is it a MAX7219 driven LED Marix Display unit? How many Modules are there? Show the picture, please. And waht Arduino are you using?

image
and arduino nano

P.displayText(pc[curText], PA_CENTER, SPEED_TIME, PAUSE_TIME, effect[inFX], effect[outFX]);

The above is a line to display text (a string). The PA_CENTER puts the text in the center of the display. I suggest that you play with some of the examples that come with the library to see how it works. Like this one.

To display your DHT11 data, first convert the numeric data to a text string. I use the snprintf() function along with dtostrf() to convert floats to text (Arduino disables snprintf() from converting floats).

1 Like

thank you I made a string and was able to display but I didn't understand how to center the text, I'm a little new to arduino and coding ...

Perform this tutorial to show a float number on the Matrx Display Unit and then try with the DHT11 Sensor. If problem, report it.
1. Connect your Display Uni wit NANO as per following description:

NANO                  Display Unit
D10 (SS/)             CS pin
D11 (MOSI)            DIN pin
D12 (MISO)            no connectiom
D13 (SCK)             CLK pin
5V                    Vcc
GND                   GND

2. Upload the following sketch.

// Including the required Arduino libraries
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CS_PIN 10

// Create a new instance of the MD_Parola class with hardware SPI connection
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

float number = -23.57;
char buffer[20]; // Make sure the buffer is large enough

void setup()
{
  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.setTextAlignment(PA_CENTER);
  myDisplay.displayClear();
  delay(2000);
  //------------------

  // Convert the float to ASCII with 2 decimal places of precision
  floatToASCII(number, buffer, 2);

  myDisplay.print(buffer);
}

void loop() {}

void floatToASCII(float num, char *buffer, int precision)
{
  // Handle the case where the number is negative
  if (num < 0) 
  {
    *buffer++ = '-';
    num = -num;
  }

  // Extract the integer and fractional parts
  int intPart = (int)num;
  float fracPart = num - (float)intPart;

  // Convert the integer part to ASCII
  int length = snprintf(buffer, 10, "%d", intPart);
  buffer += length;

  // Add the decimal point
  *buffer++ = '.';

  // Convert the fractional part to ASCII with the specified precision
  for (int i = 0; i < precision; i++) 
  {
    fracPart *= 10;
    int digit = (int)fracPart;
    *buffer++ = '0' + digit;
    fracPart -= digit;
  }

  // Null-terminate the string
  *buffer = '\0';
}

3. Check that the display shows: -23.75 at the center of the display.

it's work but the way of making the numbers to string and then displaying them was faster,
the only problems is centering and using the ° sign

1. This is the command for placing the string at the center.
myDisplay.setTextAlignment(PA_CENTER);

2. You don't need to worry about +/- sign as your DHT11 will always show positive value.

3. Connect your DHT11 with NANO and check that you can display Humidty and Temp as interger value.

thanks, 1 works great

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