Pages: [1]   Go Down
Author Topic: Sketch wont run.  (Read 539 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi gents,

Currently I have an issue with a sketch, See the following code:

Code:
//Add libraries for using the LED Matrices
#include <RGB.h>
#include <RGBMatrix.h>


//Define how many LED matrices are connected to create the frame.
int NUM_BOARDS = 6;
unsigned long starttime;
//Colors are defined in the RGB.h file
//Creating an array of the colors makes them easier to cycle through. Read the rest of the sketch to see how this is done.
char colors[8] = {BLACK, RED, GREEN, BLUE, ORANGE, MAGENTA, TEAL, WHITE};

#define INLENGTH 130
#define INTERMINATOR '^'
char intString[INLENGTH+1];
int intCount;

void setup()
{
  Serial.begin(9600);
  Serial.println("starting up");
    delay(5000);        //The matrices won't start accepting data for 5 seconds after they are powered up.
    RGBMatrix.begin(NUM_BOARDS);    //Start the communication with the LED matrices.

}

void loop()
{
intCount = 0;

Serial.println("ready");
          do
          {
while (!Serial.available());             // wait for input
            intString[intCount] = Serial.read();       // get it
            if (intString [intCount] == INTERMINATOR) break;
            intCount++;
          } while(true);
          intString[intCount] = 0;                     // null terminate the string

Serial.println("busy");

RGBMatrix.fillPixel(0, 0, 0, WHITE);
RGBMatrix.display();
//RGBMatrix.scroll("TEST", WHITE, 60);
}

If I uncomment the .scroll and comment the .fillpixel and display it short of freeze. Is don't even send out the Serial.println..
Does Anybody have an idea why?

rgbmatrix.h for info.
Code:
/*
 * Copyright 2010 SparkFun Electronic
 * Written by Ryan Owens
*/

#ifndef RGBMatrix_h
#define RGBMatrix_h

#include <avr/pgmspace.h>
#include "WProgram.h"

//Define the SPI Pin Numbers
#define DATAOUT 11 //MOSI
#define DATAIN  12 //MISO
#define SPICLOCK  13 //sck
#define SLAVESELECT 10 //ss

#define NUM_ROWS 8
#define NUM_COLUMNS 8
#define NUM_PIXELS 64
#define BUFFER 10 //Maximum frame is 8 boards. Buffer can hold an additional char
//before and after first/last character.

class cRGBMatrix
{
public:
/*
RGB Class constructor
Sets the number of boards currently connected in the matrix system
Inputs: int num_boards - The number of boards in the system
Usage: RGBMatrix myMatrix(NUM_BOARDS);
*/
cRGBMatrix(int num_boards);
cRGBMatrix(void);

/*
Configures SPI and I/O for communication with an RGB Matrix.
Note: Pinout should reflect the pin assignments in the RGBMatrix.h file
*/
void begin(int num_boards);

/*
Sets the color of a pixel on a given matrix
Inputs: int screen - The specific matrix to have a pixel set
int row - The row of the pixel to be set
int column - The column of the pixel to be set
char color - The color to be used for the pixel fill.
Returns: 1 - Success
0 - Failure (invalid screen, row or column)
*/
char fillPixel(int screen, int row, int column, char color);

/*
Fills a coloumn on a single matrix of the screenBuffer.
Note: display won't be updated until display() function is called.
Inputs: int screen - The specific matrix to have a column filled
int column - The column number to be filled
char color - The color used for the fill
Returns: 1 - Success
0 - Failure (causes are invalued screen or column number)
*/
char fillColumn(int screen, int column, char color);

/*
Fills a row on a single matrix of the screenBuffer.
Note: display won't be updated until the display() function is called
Inputs: int screen - The matrix to have a row filled
int row - The row to be filled
char color - The color to be used for the fill
Returns: 1 - Success
0 - Failure (invalid screen or row)
*/
char fillRow(int screen, int row, char color);

/*
Fills a screen in the screenBuffer
Note: display won't be updated until the display() function is called.
Inputs: int screen - The screen to be filled
char color - The color to be used for the fill.
Returns: 1 - Success
0 - Failure (invalid board)
*/
char fillScreen(int screen, char color);

/*
Puts a character into a posotion in the screenBuffer
Note: display won't be updated until the display() function is called.
Inputs: int screen - The matrix that will get the character
char letter - The letter to put onto the screen
char color - The color of the letter
Returns: 1 - Success
*/
char fillChar(int screen, char letter, char color);

/*
Scrolls an entire message on and off of the frame.
Inputs: char * message - The message to be scrolled
char color - The color for the text
int speed - The scroll speed for the message
*/
char scroll(char * message, char color, int speed);

/*
Sends the data in screenBuffer to the matrices.
*/
void display(void);
/*
Clears the entire frame by filling all the screens with Black
*/
void clear(void);

private:
/*
Sends/receives a single byte to the SPI port.
Inputs: char value - The value to be sent to the SPI port
Returns: Value received from the SPI port
*/
char spiTransfer(char value);

/*
Sends the frame of data determined by the screen parameter
Inputs: char * screen - The 64 byte buffer to send over SPI
*/
void sendScreen(char * screen);

/*
Scrolls a single fame onto and off of the frame.
Inputs: int speed - The scroll speed
*/
void scrollBuffer(int speed);
int _num_boards;
};

extern cRGBMatrix RGBMatrix;

#endif
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25854
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What stops you running off the end of your input buffer if you miss the terminator?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Change this:
Code:
          do
          {
while (!Serial.available());             // wait for input
            intString[intCount] = Serial.read();       // get it
            if (intString [intCount] == INTERMINATOR) break;
            intCount++;
          } while(true);
          intString[intCount] = 0;                     // null terminate the string

To this:
Code:
int i;
for (i = 0; i< INLENGTH - 1; i++) {
  while (!Serial.available());
  intString[i] = Serial.read();
  if (intString[i] == INTERMINATOR) break;
}
i++;
if (i == INLENGTH) Serial.println("Didn't find the terminator");
intString[i] = 0;
Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1557
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The original code did not include the terminator in the returned string so I would suggest this slight modification instead:
Code:
int i;
for (i = 0; i< INLENGTH - 1; i++) {
    while (!Serial.available());
    intString[i] = Serial.read();
    if (intString[i] == INTERMINATOR) break;
}
intString[i] = 0;
if (i >= INLENGTH - 1) Serial.println("Didn't find the terminator");

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks so far, the problem is not that it is totally not working. interdependent from each other the code is working. But together it is not running. Do you have any idea why it is conflicting?

The idea was to push the text serial to the arduino when it is saying ready, then the arduino moves the text over an RGB matrix (SPI connection) and when finished it states ready again and wait for the next serial text.
Logged

Pages: [1]   Go Up
Jump to: