Hi, i'm new here and want to ask a or more question
I have a project that use an arduino uno, 2 boards of 32x16 LED RGB matrix, a DHT11 module, an Ultrasonic range module and a tinyRTC module.
What i want to achieve is displaying the time (from rtc) and temp+humidity (from dht11) in LED board statically( if there is a person/thing in front of the board) or dynamically (scrolling text,etc).
I'm using DHT11Lib from playground and AltRGBMatrixPanel from adafruit
I have tried each module and it works perfectly. I'm also combining all three module except the LED board and its works good as what i want.
But the problem is, when im trying to print the buffer to the LED board its not working as before.
im trying to comment all the matrix and its work pretty good.
im leaving matrix.begin() uncommented and the DHT output become 0, the error is TIME_OUT. after i tried to find the problem, i'm trying recklessly to comment the Timer 1 setup in matrix.begin() and the DHT works with sometime there is TIME_OUT or CHECKSUM_ERROR. i dont know whether the problem is in the timer or what.
The other problem is, when im trying to use matrix.fill() or matrix.print() the getDHTValue() and getRTCTime() look like its stop working because the string is not filled.
So, can you help me to find the problem? Sorry if i can't provide better explaination because this is my 2nd project with microcontroller and 1st project with arduino uno (im using 89C51 before for automatic trash bin)
Thanks before
AltRGBMatrixPanel.cpp can seen here (max character problem ) : AltRGBMatrixPanel.cpp
Here is my code:
//#include <TimedAction.h>
#include <dht11.h>
#include <AltRGBmatrixPanel.h> // Hardware-specific library
dht11 DHT11;
#define trigPin 12
#define echoPin 11
#define DHT11PIN 13
#include "Wire.h"
#define DS1307_ADDRESS 0x68
#define XPANELS 2
#define YPANELS 1
#define PLANES 3
//TimedAction timedAction = TimedAction(1000,getDHTValue);
byte zero = 0x00; //workaround for issue #527
AltRGBmatrixPanel matrix(XPANELS, YPANELS, PLANES);
char str[23] = "Universitas\nMultimedia";
int textX = matrix.width(),
textMin = sizeof(str) * -12;
long hue = 0;
int8_t ball[3][4] = {
{ 3, 0, 1, 1 }, // Initial X,Y pos & velocity for 3 bouncy balls
{ 17, 15, 1, -1 },
{ 27, 4, -1, 1 }};
uint32_t ballcolor[3] = {
0x00FF00, // Green=1
0x0000FF, // Blue=1
0xFF0000 // Red=1
};
//RTC - SCL port 5
//RTC - SDA port 4
String dhtstring;
String rtcstring;
String buffstring;
String strhour;
String strminute;
String strsecond;
void setup(){
//InitDHT(); // Initialize the pin used to read the sensor
Serial.begin(9600);
Wire.begin(); //setup for RTC
matrix.begin();
matrix.setTextSize(1);
delay(300); //Let system settle
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
//Serial.println(DHT11LIB_VERSION);
delay(700); //Wait rest of 1000ms recommended delay before
//accessing sensor
}
void loop()
{
getDHTValue();
getRTCTime();
buffstring = dhtstring + rtcstring;
Serial.println(buffstring);
/*int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2;
/*if (distance < 10){
print statically
}
else {
//print dynamically
}*/
//for(int j =0 ; j<1000; j++)
//{
//str = dhtstring;
//byte i;
//delay(10);
// Clear background
//matrix.fill(0);
// Bounce three balls around
/*for(i=0; i<3; i++)
{
// Draw 'ball'
matrix.fillCircle(ball[i][0], ball[i][1], 6, ballcolor[i]);
matrix.drawPixel(ball[i][0] - 2, ball[i][1] + 4,0xAAAAAA);
matrix.drawPixel(ball[i][0] - 3, ball[i][1] + 2,0xAAAAAA);
matrix.drawPixel(ball[i][0] - 2, ball[i][1] ,0xAAAAAA);
matrix.drawPixel(ball[i][0] - 4, ball[i][1] - 1,0xAAAAAA);
matrix.drawPixel(ball[i][0] + 1, ball[i][1] - 1,0xAAAAAA);
matrix.drawPixel(ball[i][0] - 1, ball[i][1] - 2,0xAAAAAA);
matrix.drawPixel(ball[i][0] - 6, ball[i][1] - 2,0xAAAAAA);
matrix.drawPixel(ball[i][0] - 2, ball[i][1] - 3,0xAAAAAA);
matrix.drawPixel(ball[i][0] - 4, ball[i][1] - 5,0xAAAAAA);
matrix.drawPixel(ball[i][0] , ball[i][1] - 5,0xAAAAAA);
// Update X, Y position
ball[i][0] += ball[i][2];
ball[i][1] += ball[i][3];
// Bounce off edges
if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
ball[i][2] *= -1;
if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
ball[i][3] *= -1;
}*/
// Draw big scrolly text on top
//matrix.setTextColor(random(0x1000000));
matrix.setTextColor(0x010000);
matrix.setCursor(0, 0);
matrix.print(str);
// Move text left (w/wrap), increase hue
//if((--textX) < textMin) textX = matrix.width();
//hue += 7;
// Update display
//matrix.swapBuffers(false);
//}
//delay(1000);
}
void setDateTime(){
byte second = 25; //0-59
byte minute = 26; //0-59
byte hour = 9; //0-23
byte weekDay = 3; //1-7
byte monthDay = 15; //1-31
byte month = 5; //1-12
byte year = 13; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void getRTCTime(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
if(hour<10)
strhour="0" + String(hour);
else
strhour = String(hour);
if(minute<10)
strminute="0" + String(minute);
else
strminute = String(minute);
if(second<10)
strsecond="0" + String(second);
else
strsecond = String(second);
rtcstring= strhour + ":" + strminute + ":" + strsecond+ "\n";
}
void getDHTValue()
{
int chk = DHT11.read(DHT11PIN);
dhtstring = "H="+ (String)DHT11.humidity + "%;T=" + (String)DHT11.temperature + "C \n";
}