I am doing a project where Arduino mega dos some calculation work and sends the data to UNO via serial(115200) and the UNO is inturn expected to scroll the received text on DMD display(1X4).
Here is the code part of mega which generates the message to be sent on serial to UNO
void DmD()
{
DateTime now = rtc.now();
int dai = now.day();
int mon = now.month();
int yr = now.year();
int hr = now.hour();
int minit = now.minute();
sprintf(scrollingtext, "<%d/%d %d:%d Total Feedback:%d Air:%d Toilet:%d Service:%d Total Avg:%d Air:%d Toilet:%d Service:%d >" , dai,mon,hr,minit,TotalFB,TotalAirFB,TotalToiletFB,TotalServiceFB,total_avg,Air_avg,toilet_avg,service_avg);
}
I am not posting the entire code since the word limit doesn't allow more charachters
The code at UNo which receives the message and expected it to scroll on DMD is
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 4
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
const byte numChars = 100;
char receivedChars[numChars];
boolean newData = false;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup()
{
//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 5000 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5s) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
//clear/init the DMD pixels held in RAM
dmd.clearScreen( true ); //true is normal (all pixels off), false is negative (all pixels on)
Serial.begin(115200);
Serial.println("<Arduino is ready>");
}
void loop()
{
recvWithStartEndMarkers();
showNewData();
DmD();
}
void recvWithStartEndMarkers()
{
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void showNewData()
{
if (newData == true)
{
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
void DmD()
{
if (newData == true)
{
dmd.selectFont(Arial_Black_16);
//displays the message
dmd.drawMarquee(receivedChars ,200,(32*DISPLAYS_ACROSS)-1 ,0);
long start=millis();
long timer=start;
boolean ret=false;
while(!ret)
{
if ((timer+30) < millis()) {
ret=dmd.stepMarquee(-1,0);
timer=millis();
}
}
}
}
So here's the two problems m facing
-
whenever the function DMD is enabled the function ShowNewData doesn't show up in the serial monitor. And if the DmD function is disabled then ShowNewData hows up in the serial monitor(Although this doesn't really matter to me, But m just wondering why this happens)
-
The DMD dispaly only scrolls text till "Service:" parameter (rest " total avg: air, toilet and service" parameters doesn't show up on DmD)
What changes do I need to make either in the mega code or UNO code? I am really stuck on this thing from past two weeks and not able to get the reason why this is happening. Any help, suggestion would be really appreciated. Thanks in advance