Tuesday, September 28, 2010

Scrolling text on a sparkfun 7 segment serial display with Arduino

Here is a youtube video showing scrolling text on a sparkfun 7 segment serial display.

http://www.youtube.com/watch?v=WFEq9U17cKk

Here is the arduino code.

/*Scrolling text on a sparkfun 7 segment serial display.

My code is based in part on the code in the tutorial at

http://www.arunet.co.uk/tkboyd/ec/ec1led4x7ser.htm

If you are new to this display, I suggest checking out the tutorial first.
Once you have played around with displaying text, then try my code.

The tutorial didn't specify a license for the code. Given the spirit of the Arduino
I will assume it's public domain.

My code is copyright under the Gnu General Public Licence (GLP) version 3 or any later version
The text of the GPL can be found at http://www.gnu.org/licenses/gpl.html

Many thanks to TK Boyd for creating the tutorial above.



The RX pin on the display is hooked up to digital pin 3 on the arduino. The wiper on the potentiometer is hooked up to analog pin 0 on the arduino.

This code requires the newsoftserial library. If you don't have it installed, do so.

*/



#include <NewSoftSerial.h> //Make sure you have this library installed,

#define SerInToArdu 2 // input pin to arduino. Not used in this example
#define SerOutFrmArdu 3 // output pin from arduino




NewSoftSerial mySerialPort(SerInToArdu,SerOutFrmArdu); /* creates a serial channel to send the data to and from the display. */

char text[] = " HELLO TO YOU ALL IN YOUTUBE LAND "; /* Array with our text. Blank spaces are so characters start from the right and disappear off the left side There should be 3 blank spaces in the beginning of the array text and 4 blank spaces at the end. Blogger is being stupid and only showing one blank space.*/



void setup() {
pinMode(SerOutFrmArdu,OUTPUT); //sets pin to output
pinMode(SerInToArdu,INPUT); /* Not actually needed... put in to be explicit as to data direction over serial lines */

mySerialPort.begin(9600);

mySerialPort.print("v"); /* a special code to reset the display. See tutorial above for more info on special codes */

}

void loop() {
mySerialPort.print("v"); //rest display
for (int num = 0; num <= sizeof(text) - 5; num++) { /* simple for loop. sizeof function checks size of array. Avoids having to hard code array size. The arduino laguage reference used a -1 in their example. I ended up having to use a -5 to get it to work right. Not sure exactly how it works, but it does. See arduino language reference for more info on sizeof() */


mySerialPort.print(text[num]); /* send character in array index num, to display */
mySerialPort.print(text[num+1]);/* send next character in array after index num */
mySerialPort.print(text[num+2]);/* send third character in array after index num */
mySerialPort.print(text[num+3]); /* send fourth character in array after index num */

/*In first time through loop. above code would send the contents of array indexes 0123.
Second time in loop it would send contents of indexes 1234. And so on.
The text is shifted one space each time through the loop. 4 characters are send to the display each time

Here is what it looks like. X is a blank space
1st time through loop XXXH
2nd XXHE
3rd XHEL
4th HELL
5th ELLO
6th LLOX
7th LOXT
8th OXTO
ETC ETC
*/


delay(analogRead(0)); /* delay by pot value. This controls the speed the text scrolls at */

}
delay(500); //Short pause after text is done scrolling

1 comment:

Vasile Guta-Ciucur said...

Hi, if you want google to play nice with your code, use the html tags "code" and/or "pre"...