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...
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 theexamples 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).
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.