Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumWiring HardwareTangible computing › Xport

Page Index Toggle Pages: 1
Xport (Read 10891 times)
06/03/08 at 21:35:09

gokce   Offline
YaBB Newbies

Posts: 12
*
 
Hi,
I am using Xport and Sparkfun RGB Led Matrix for my project. They both work great individually. However, when I combine the codes xport doesn't work.

My Xport code is based on the USB weatherboard code. RGB led matrix code is based on the halfmachine.dk code.

Here some of the code:

Code:
void setup() {
  // Xport setup
  pinMode(deviceResetPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial1.begin(57600);
  resetDevice();

  //RGB Matrix setup
  matrixInit();

  // Diagnostics
  Serial.begin(57600);
  Serial.println("Setup");
  //arrayDiagnostic();
}

void loop() {
  // Xport loop
  stateCheck();

  // RGB Matrix loop
  //arrayRandom();
  writeMatrix();
} 




Xport only gets two characters and prints D (which means disconnected).

Altough, when I comment out the writeMatrix function from the void loop(), Xport works. Is it the delays in the writeMatrix() which causes the problem? Delay in a function is affecting working speed of an another function?


Here is the writeMatrix function:

Code:
void writeMatrix()
{
  for(int display = 0;display <12;display++)
  {
    digitalWrite(clock, LOW);    //sets the clock for each display, running through 0 then 1
    digitalWrite(data, LOW);    //ditto for data.

    delayMicroseconds(10);
    digitalWrite(cs[display], LOW);     //ditto for cs.
    delayMicroseconds(10);
    for(int x = 0; x < 8;x++)
    {
      for (int y = 0 ; y < 8;y++)
      {
        writeByte(displayPicture[display][x][y], display); //Drawing the grid. x across then down to next y then x across.
        delayMicroseconds(10);
      }
    }
    delayMicroseconds(10);
    digitalWrite(cs[display], HIGH);
  }
} 



I am stuck, thank you. I could post more of the code if it will be helpful,
Gokce
 
IP Logged
 
Reply #1 - 06/04/08 at 15:59:58

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
Could you please post the mixed code?
 
IP Logged
 
Reply #2 - 06/04/08 at 17:08:15

gokce   Offline
YaBB Newbies

Posts: 12
*
 
Here is the mixed code in two parts because it is too long:

Code:
#include <String.h>

// Xport pins
int deviceResetPin = 7;      // resets Lantronix Device

// Xport variables
int inByte= -1;              // incoming byte from serial RX
int i = 0;
int status = 0;              // Lantronix device's connection status
long lastCompletionTime = 0; // counter for delay after last completion

String buffer = String("");  // buffer to read data from xport
int ready = 0;  // used to mark when we have a complete string to process
int val;  // use to read a byte from the serial
int newline = 1;

// Diagnostics
int delayTime = 1000;
int ledPin = 48;

// RGB Matrix pins
int clock = 9;  
int data = 8;
int cs[12] = {
  15,14,37,36,31,30,29,28,27,26,25,24};

// RGB Matrix variables
int bits[8] = {
  128, 64, 32, 16, 8, 4, 2, 1   };
byte displayPicture[12][8][8];

// Diagnostics


void setup() {
  // Xport setup
  pinMode(deviceResetPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial1.begin(57600);
  resetDevice();

  //RGB Matrix setup
  matrixInit();

  // Diagnostics
  Serial.begin(57600);
  Serial.println("Setup");
  //arrayDiagnostic();
}

void loop() {
  // Xport loop
  stateCheck();

  // RGB Matrix loop
  //arrayRandom();
  writeMatrix();
}

void stateCheck() {
  switch (status) {
  case 0:
    // attempt to connect to the server:
    Serial.println("Connecting");
    deviceConnect();
    break;
  case 1:
    // until you get a C, keep trying to connect:
    // read the serial port:
    if (Serial1.available()) {
      inByte = Serial1.read();
      if (inByte == 'C') {  // 'C' in ascii
        Serial.print("First inByte= ");
        Serial.print(inByte);
        Serial.print("\n");
        status = 2;    
      }
      else {
        // if you got anything other than a C, try again:
        deviceConnect();
      }
    }
    break;
  case 2:
    // send HTTP GET request for CGI script:
    Serial.println("Requesting");
    httpRequest();
    break;
  case 3:
    //Serial.println("Looking For Data");
    lookForData();
    break;
  case 4:
    //Serial.println("Waiting Next Request");
    //waitForNextRequest();
    break;
  }
}
void deviceConnect() {
  //   fill in your server's numerical address below:
  Serial1.print("C192.168.1.66/80\n");
  status = 1;
}

/*
  Send a HTTP GET request
 */
void httpRequest() {
  // make sure you've cleared the last byte
  // from the last request:
  inByte = -1;  
  //  Make HTTP GET request. Fill in the path to your version
  //  of the CGI script:
  Serial1.print("GET /index.php HTTP/1.0\n");
  //  Fill in your server's name:
  Serial1.print("HOST: lan\n\n");
  // update the state of the program:
  status = 3;
}

/*
  Read the results sent by the server until you get a < character.
 */
void lookForData() {
  while(Serial1.available() > 0) {  // if data vailable from the weather board
    val = Serial1.read();  // read it
    Serial.print(char(val));
    if((val != '\n' && newline == 1)) {  // if no end of line
      buffer.append(char(val));  // add it to the buffer
    }
    else {  // if end of line reached, ready to parse the buffer
      ready = 1;
      newline = 0;
      break;
    }  
  }
  if(ready == 1) {  // parse the buffer
    //if(buffer.contains("#")) {  // verify if it is a good reading
    Serial.println("test0");
    Serial.println(buffer);  // just to see what we got
    Serial.println("test1");
    processReading(buffer.toCharArray());  // parse the buffer extracting the data
    //}
    Serial.println("test2");
    buffer = String("");  // clean up the buffer for next reading
    Serial.println("test3");
    ready = 0;
    status = 4;
  }
}

/*
  Wait two minutes before initiating a new request.
 */
void waitForNextRequest() {
  if (millis() - lastCompletionTime >= 100) {
    // reset Lantronix device before next request:
    resetDevice();
    status = 0;
  }
}

/*
  Take the Lantronix device's reset pin low to reset it
 */
void resetDevice() {
  digitalWrite(deviceResetPin, LOW);
  delay(50);
  digitalWrite(deviceResetPin, HIGH);
  // pause to let Lantronix device boot up:
  delay(10000);
}

void processReading(char packet[]) {
  Serial.println(packet);
  arrayShow(packet);
} 


 
IP Logged
 
Reply #3 - 06/04/08 at 17:08:55

gokce   Offline
YaBB Newbies

Posts: 12
*
 
second part:


Code:
// --------------------
// RGB Matrix Functions

void matrixInit()
{
  pinMode(clock, OUTPUT); // sets the digital pin as output
  pinMode(data, OUTPUT);
  for(int display = 0;display <12;display++) //Running through each display (0 and 1)
  {
    pinMode(cs[display], OUTPUT);
  }
}

void writeByte(byte myByte, int display) //prints out bytes. Each colour is printed out.
{

  for (int b = 0; b < 8; b++) { //converting it to binary from colour code.
    digitalWrite(clock, LOW);
    if ((myByte & bits[b])  > 0)
    {
	digitalWrite(data, HIGH);
    }
    else
    {
	digitalWrite(data, LOW);
    }
    digitalWrite(clock, HIGH);
    delayMicroseconds(10);
    digitalWrite(clock, LOW);
  }
}

void writeMatrix()
{
  for(int d = 0;d <12;d++)
  {
    digitalWrite(clock, LOW);    //sets the clock for each display, running through 0 then 1
    digitalWrite(data, LOW);    //ditto for data.

    delayMicroseconds(10);
    digitalWrite(cs[d], LOW);     //ditto for cs.
    delayMicroseconds(10);
    for(int x = 0; x < 8;x++)
    {
	for (int y = 0 ; y < 8;y++)
	{
	  writeByte(displayPicture[d][x][y], d); //Drawing the grid. x across then down to next y then x across.
	  delayMicroseconds(10);
	}
    }
    delayMicroseconds(10);
    digitalWrite(cs[d], HIGH);
  }
}

void arrayShow(char toShow[])
{
  for (int disp = 0; disp < 12;disp++) {
    for(int x = 0; x < 8;x++)
    {
	for (int y = 0 ; y < 8;y++)
	{
	  displayPicture[disp][x][y] = toShow[(disp*64)+(x*8)+y];
	}
    }
  }
}
void arrayRandom()
{
  for (int f = 0; f < 12;f++) {
    for(int x = 0; x < 8;x++)
    {
	for (int y = 0 ; y < 8;y++)
	{
	  displayPicture[f][x][y] = random(7)+1;
	}
    }
  }
} 


 
IP Logged
 
Reply #4 - 06/06/08 at 08:18:41

gokce   Offline
YaBB Newbies

Posts: 12
*
 
I tried to use two Wiring boards. First one is connected to Xport and the second is connected to RGB Led matrixes.

First one receives data perfectly and prints it through the serial port. Second receives data perfectly if I comment out the writeMatrix() function.

So the problem is, writeMatrix() function in the RGB Led Matrix code doesn't let the board to get consistent data from the serial connection.

Any ideas to solve this?


I modified the RGB Led Matrix code so it is lighter now. Here is the code:
Code:
#include <String.h>

String buffer = String("");  // buffer to read data from xport
String buff = String("");
char toShow[768];
int m = 0;
int ready = 1;  // used to mark when we have a complete string to process
int val;  // use to read a byte from the serial
int newline = 1;

// RGB Matrix pins
int clock = 9;
int data = 8;
int cs[12] = {
  15,14,37,36,31,30,29,28,27,26,25,24};

// RGB Matrix variables
int bits[8] = {
  128, 64, 32, 16, 8, 4, 2, 1   };

// Diagnostics


void setup() {
  Serial1.begin(9600);

  //RGB Matrix setup
  matrixInit();

  // Diagnostics
  Serial.begin(9600);
  Serial.println("Setup");
  //arrayDiagnostic();
}

void loop() {
  lookForData();

  // RGB Matrix loop
  //arrayRandom();
  //writeMatrix();
}

/*
  Read the results sent by the server until you get a < character.
 */
void lookForData() {
  while(Serial1.available() > 0) {  // if data vailable from the weather board
    val = Serial1.read();  // read it
    //Serial.print(val);
    if((val != '\n' && ready == 1)) {  // if no end of line
	toShow[m] = char(val);
	Serial.print(toShow[m]);
	m++;
	//buffer.append(char(val));
	//Serial.println("test");
	//Serial.print(buffer);
    }
    else {  // if end of line reached, ready to parse the buffer
	ready = 1;
	m = 0;
	break;
    }
  } /*
  if(ready == 4) {
    Serial.println("test1");
    toShow = buffer.toCharArray();
    buffer = String("");
    ready = 1;
  }*/
  //writeMatrix();
}

// --------------------
// RGB Matrix Functions

void matrixInit()
{
  pinMode(clock, OUTPUT); // sets the digital pin as output
  pinMode(data, OUTPUT);
  for(int display = 0;display <12;display++) //Running through each display (0 and 1)
  {
    pinMode(cs[display], OUTPUT);
  }
}

void writeByte(byte myByte, int display) //prints out bytes. Each colour is printed out.
{

  for (int b = 0; b < 8; b++) { //converting it to binary from colour code.
    digitalWrite(clock, LOW);
    if ((myByte & bits[b])  > 0)
    {
	digitalWrite(data, HIGH);
    }
    else
    {
	digitalWrite(data, LOW);
    }
    digitalWrite(clock, HIGH);
    delayMicroseconds(10);
    digitalWrite(clock, LOW);
  }
}

void writeMatrix()
{
  for(int d = 0;d <12;d++)
  {
    digitalWrite(clock, LOW);    //sets the clock for each display, running through 0 then 1
    digitalWrite(data, LOW);    //ditto for data.

    delayMicroseconds(10);
    digitalWrite(cs[d], LOW);     //ditto for cs.
    delayMicroseconds(10);
    for(int x = 0; x < 8;x++)
    {
	for (int y = 0 ; y < 8;y++)
	{
	  writeByte(toShow[(d*64)+(x*8)+y], d); //Drawing the grid. x across then down to next y then x across.
	  delayMicroseconds(10);
	}
    }
    delayMicroseconds(10);
    digitalWrite(cs[d], HIGH);
  }
}

 



 
IP Logged
 
Reply #5 - 06/06/08 at 23:15:50

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
Please post the code you use when merging both xport and matrix using 1 Wiring board. I suspect there might be some delays causing the display to skip refresh, I just want to check what´s going on.

 
IP Logged
 
Reply #6 - 06/06/08 at 23:34:50

gokce   Offline
YaBB Newbies

Posts: 12
*
 
I already posted it. It is Reply #2 and #3.

It is in two parts because message input field in the forum has limit of maximum 5500 characters.
 
IP Logged
 
Reply #7 - 09/03/08 at 18:18:58

cmk1523   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 1
*
 
To all Xport users:

Do you know how to access the UART in order to send/receive from the web? Using the Xport AR, I've successfully set up a Terminal and SSH tunnel to the UART, but I want to control the device through through a webpage, nto a terminal.
 
IP Logged
 
Reply #8 - 09/04/08 at 14:44:50

gokce   Offline
YaBB Newbies

Posts: 12
*
 
Do you mean the main control interface which could be accessed via ip number?

In the other hand it is possible to setup a website which runs in the Xport.
 
IP Logged
 
Page Index Toggle Pages: 1