Serial HEX to ASCII to DMD

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]

Serial HEX to ASCII to DMD

Postby Stevel » Sat Aug 24, 2013 4:27 pm

Hi,
I am extremely new to the Arduino and any type of programming so my first project is going to be a challenge. But after seeing the Arduino and the Freetronics DMD panel I wanted to give it a try.
I want to monitor the serial port for a data string and display some of the string to the DMD in ASCII.
The details of the data are below.

STX D nnnn B C ETX
STX = 2 hex, start of text
ETX = 3 hex, end of text
D = Device number, this must match a number in the setup
nnnn = numbers or characters to be displayed
B = 0: GREEN
B = 1: RED
C = 0: Open
C = 1: Closed

So the following data should display 42.

0x02 0x80 0x20 0x20 0x34 0x32 0x30 0x30 0x03

So what I need it to do is monitor the serial port for data, when it sees 0x02 read the string.
If the device number matches the one setup in the program then display the next 4 characters in the string as ASCII to the display.

I have created a sketch that will read the character sent via the serial port and display them but I don’t know how to setup the conditions and convert the HEX to ASCII to be displayed.

Can anyone point me in the right direction on how to do this.
I have been looking at several web sites for information but have not found very much.
Stevel
 
Posts: 3
Joined: Sat Aug 24, 2013 8:02 am

Re: Serial HEX to ASCII to DMD

Postby stryker » Sun Aug 25, 2013 12:36 am

Hi stevel

Strictly speaking, your serial traffic won't be hex, rather it will be a string of bits that can be represented to human readable form as a number in some base (your choice of 2-binary, 10-decimal, or 16-hex...whatever is your preference), or as the representation of a displayed ascii character. This means to filter by a value, your code is just going to need to refer to the data in a particular way so comparing it to hex 0x42 or char '*' are equivalent.

Can you post here your code as it is up to now? I don't see your attachment.

Cheers !
Geoff
stryker
 
Posts: 108
Joined: Sat Jan 14, 2012 2:44 pm

Re: Serial HEX to ASCII to DMD

Postby Stevel » Sun Aug 25, 2013 12:48 pm

Hi Geoff,

Thank you for your reply.

As I said in my post this is new to me, I only bought the Arduino and DMD panel just over a week ago and have spent 6 or so hours with it.
My code is extremely basic and was mainly done so I could experiment with creating different fonts for the panel. I wanted the largest font I could make that would display 4 characters. Which I found by using Arial narrow 16.

My objective is to receive the string via the serial port until it sees 0x03, and then extract the 4 characters from the string that are required to be displayed on the panel.
So 0x02 0x80 0x30 0x30 0x34 0x32 0x30 0x30 0x03 would be received and 0042 would be displayed on the DMD panel.

I have been looking through the arduino reference under serial and it looks like I could use the readBytesUntil() function because the string I will be receiving will always end in 0x03.
But it does not explain how to implement it in any detail.

I guess what I really need is a book that explains how to implement the functions in some detail.

Or maybe someone to guide me on which functions I should be using to start my sketch.

Cheers
Steve
Attachments
Serial_txt_DMD.zip
(1.05 KiB) Downloaded 203 times
Stevel
 
Posts: 3
Joined: Sat Aug 24, 2013 8:02 am

Re: Serial HEX to ASCII to DMD

Postby phuchuyhdtv » Sat Aug 31, 2013 5:01 am

help me!!!!!!!!!!
i want Serial HEX to ASCII exto DMD and ascii extended characters?????????
phuchuyhdtv
 
Posts: 7
Joined: Sat Aug 31, 2013 4:58 am

Re: Serial HEX to ASCII to DMD

Postby stryker » Sat Aug 31, 2013 2:46 pm

Hi stevel

Is the output to the serial monitor what you were expecting? You've got it printing out the characters received - is that working for you?

The section where you output to the DMD has a problem that the x & y values the dmd.drawString gets to use will soon be negative. I haven't checked to see if that function will deal with that nicely, but x & y need to be positive values which represent the offset from the top left corner of the DMD in rows and columns at which the string will be displayed.

Since you only have the 4 characters to display on the DMD the final logic in your loop() function doesn't do that. But then I presume that's because you've not got to that final step and for this test you want to show all 6.

I think you shoud replace
Code: Select all
   for (byte x=0;x<DISPLAYS_ACROSS;x++) {
     for (byte y=0;y<DISPLAYS_DOWN;y++) {
       dmd.drawString( 0-(x),  1-(y),(serIn), 6, GRAPHICS_NORMAL );
       }
   }
with something like this to get it to display something
Code: Select all
dmd.drawString( 0,0, serIn, 6, GRAPHICS_NORMAL );
(ie there's no need for the two for() statements there)

Cheers !
Geoff
stryker
 
Posts: 108
Joined: Sat Jan 14, 2012 2:44 pm

Re: Serial HEX to ASCII to DMD

Postby phuchuyhdtv » Sun Sep 01, 2013 4:01 am

i want Serial HEX to ASCII exto DMD and ascii extended characters?????????
phuchuyhdtv
 
Posts: 7
Joined: Sat Aug 31, 2013 4:58 am

Re: Serial HEX to ASCII to DMD

Postby stryker » Sun Sep 01, 2013 8:43 am

phuchuyhdtv wrote:i want Serial HEX to ASCII exto DMD and ascii extended characters?????????
Nobody can help you get to where you want to go unless you explain where you are now.

What output are you seeing now, and did my last post change anything for you?
stryker
 
Posts: 108
Joined: Sat Jan 14, 2012 2:44 pm

Re: Serial HEX to ASCII to DMD

Postby phuchuyhdtv » Sun Sep 01, 2013 9:23 am

/*--------------------------------------------------------------------------------------
Includes
--------------------------------------------------------------------------------------*/
#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 "huy.h"
#include "huy1.h"
//#include "Arial_black_16.h"
//#include "ArialN16.h"
//#include "ArialN15.h"
//#include "Arial12.h"

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

char serIn[8];

void ScanDMD()
{
dmd.scanDisplayBySPI();
}

void setup(void)
{

//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 1600 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) 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(9600);
}

void loop(void){
byte b;
if(Serial.available()) {

int chars_in = 0;
while (Serial.available()>0 && chars_in <9){
serIn[chars_in] = Serial.read();
Serial.write( byte(serIn[chars_in]));

chars_in++;
}
Serial.println();
}

// if (byte(serIn[0]==96))
{

dmd.selectFont(huy);

dmd.drawString( 0, 0,(serIn), 8, GRAPHICS_NORMAL );//(serIn)

}

// else {}
}
phuchuyhdtv
 
Posts: 7
Joined: Sat Aug 31, 2013 4:58 am

Re: Serial HEX to ASCII to DMD

Postby phuchuyhdtv » Sun Sep 01, 2013 9:24 am

i want Serial HEX to ASCII exto DMD and ascii extended characters?????????
phuchuyhdtv
 
Posts: 7
Joined: Sat Aug 31, 2013 4:58 am


Return to Dot Matrix Display

Who is online

Users browsing this forum: No registered users and 0 guests