Show Posts
Pages: 1 ... 5 6 [7] 8 9 ... 11
91  Using Arduino / Project Guidance / Re: Transport Control via RS232 on: February 01, 2013, 09:13:11 am
Your next step should be to find and post a link to the card reader device.

I think it's been discontinued, but here is a link to the manual:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CFcQFjAA&url=http%3A%2F%2Fwww.jingle.org%2FmarantzPMD570manual.pdf&ei=MM0LUc6KHMy10AH47YGIAg&usg=AFQjCNFUSecX8QBoKGxGHluo-O0MxmSc3Q&sig2=PjQmuONOSwNUyObHL7w_AA&bvm=bv.41867550,d.dmQ
92  Using Arduino / Project Guidance / Re: Transport Control via RS232 on: February 01, 2013, 09:06:41 am
Then I suggest you find out. If your CF reader needs RS232 and you aren't supplying RS232 signal levels, it's not going to work.

My next step will be to see if I can generate a schematic by tracing pins.  More to follow on that front...


This is what the manual says in terms of commands:

Quote

Command format
Start character:   @
End character:   0Dh

Notes:
The receiving side ignores data received prior to "@". If code data is received without receiving "@", the data receive error code will be returned. The tolerance for send/receive clock error is ±10%. For sending a command, wait more than 20ms after reception of a response (OK, ERR or Status). Reception of 0Dh or timeout is used to determine the end of a command. Timeout occurs 1 second after the reception of the last byte.




The manual also lists a table of commands and request commands.  This is the one I was trying to use as my test:

Card Condition .............. “@0?CD” + CR

Would the line
Code:
Serial2.println("@0?CD");
fulfill the start and end characters?
93  Using Arduino / Project Guidance / Re: Transport Control via RS232 on: February 01, 2013, 07:00:39 am
I'm not sure.  I'm not able to find the schematic anymore. 
94  Using Arduino / Project Guidance / Transport Control via RS232 on: February 01, 2013, 06:46:00 am
I have a CF card recorder that can be controlled by RS232.  I've been trying to control it with this sketch but without any luck:

Code:
int i;
void setup(){
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial2.begin(9600);
  i = 0;

}

void loop(){
  if(i==0){
    Serial2.println("@0?CD\n");
    Serial.println("message sent");
  }
  if(i==100){
    i=0;
  }
  if (Serial2.available()){
    //Serial.print("MIDI:  ");
    Serial.println("we got stuff");
    int inByte = Serial1.read();
    Serial.println(inByte);


  }
    if (Serial1.available()){
    //Serial.print("MIDI:  ");
    Serial.println("serial 1 we got stuff");
    int inByte = Serial1.read();
    Serial.println(inByte);


  }

  i++;
}


I've gone over the manual a few times and this morning stumbled across this:

Quote
1. The host requests data by setting RTS to L.
2. Upon data request by CTS, the PMD570 responds
by setting RTS to H if not busy.
3. The host checks if CTS is H and stats data output
on TxD.
4. When data output finishes, the host sets RTS to H.
5. The PMD570 checks if CTS is H and sets RTS to L.

The shield that I am using only has the following pins:

Tx
Rx
Vcc
Gnd

I would assume that since I am not able to set RTS low that my attempts to controll the device will not succeed.  Is that correct? 


Loren
95  Using Arduino / Interfacing w/ Software on the Computer / Error: RXTX Warning: Removing stale lock file. on: January 29, 2013, 07:23:03 pm
This morning I was working away got into a groove and then I got the error:

Code:
RXTX Warning:  Removing stale lock file.

Now I can't communicate with the mega from eclipse on my mac.  I can still connect via the arduino serial monitor (not at the same time of course).

I did some googleing but couldn't find any solutions.

Any suggestions?

Edit:  my java app will not communicate with my uno either.
96  Using Arduino / Programming Questions / Re: error: avrdude: stk500v2_ReceiveMessage(): timeout on: January 28, 2013, 08:57:18 pm
It seemed to me that the last statement could get memory intensive so I modified Midi and Card  like this:

Midi:

Code:
#include "Arduino.h"
#include "Midi.h"
#include "Card.h"

void Midi::init(){
 pinMode(STAT1,OUTPUT);
 pinMode(STAT2,OUTPUT);
 
}

void Midi::blinky(){
 for(int i = 0; i < 10; i++){
  digitalWrite(STAT1,HIGH);
  digitalWrite(STAT2,LOW);
  delay(30);
  digitalWrite(STAT1,LOW);
  digitalWrite(STAT2,HIGH);
  delay(30);
 }
 digitalWrite(STAT1,HIGH);
 digitalWrite(STAT2,HIGH);
}

void Midi::rxComm(){
  Card card;
  if (Serial1.available()){
   Serial.print("MIDI:  ");
    digitalWrite(STAT2,LOW);
   int inByte = Serial1.read();
    Serial.println(inByte);
  delay(10);
 digitalWrite(STAT2,HIGH);

  if(inByte > 191){
   if (inByte <208){
     //card.midiCommand(inByte);
  }
  }
}
}

Card:
Code:
#include "Arduino.h"
#include "Card.h"

void Card::init(){
 CS_pin = 4;
pinMode(CS_pin, OUTPUT);
if(!SD.begin(CS_pin)){
  Serial.println("Card Failed");
  return;
}
Serial.println("Card Ready");
cardReady = true;
}

void Card::midiCommand(int stuff){
 /*Serial.println("midi command called");
  int n = 0;
 myFile = SD.open("midiComm.csv");
 Serial.println("File should be open");
 while (myFile.available()){
 
   c = myFile.read();
     if (c != '\n'){
      LineFromFile[n] = c;
     n++;
    int xyz;
     for (xyz = 0; xyz < n; xyz++){
        if (LineFromFile[xyz] != ','){
          junk += LineFromFile[xyz];
          Serial.print(LineFromFile[xyz]);
          if(junk == stuff){
             Serial.println("GOOOD!!!!  ");
          }
        }else{
          Serial.print(" ");
        }   
     }
     }else{
       Serial.println(" ");
 }
 n = 0;
 
}*/

}

I basically eliminated the midiCommand method from card. 

So it seems like I should use a computer to do all of the table lookup tasks of this since they seem to be really memory intensive.  Does that seem like a good idea?  I'll also kick around playing with monitoring the memory situation.

Thanks,

Loren
97  Using Arduino / Programming Questions / Re: error: avrdude: stk500v2_ReceiveMessage(): timeout on: January 28, 2013, 09:03:27 am
Code:
   Serial1.flush();
Why? Why do you need to block until all serial data has been sent, on a port you only read from?

You are right.  That line is gone.

Why is n a field of the Card class. It is only used in one method. It should be local to that method.
Moved to method.

Are the records on the SD card really 255 characters?
No but close to 100 so I've reduced the size of that char to 100

Which Arduino are you trying to upload this to? A 328-based Arduino only has 2k or SRAM. The SD class uses more than 1/4 of that. The Card class is using 1/8 of the memory just for the LineFromFile array.

I'm using a mega 2560.

You bring up some really good points that I need to learn more about.  After the couple of tweaks listed above I'm still having the same problem.   I'll look into memory usage a little later today. 

If this truely is a memory problem why would it lock up on upload when my sketch is only 18,000 bytes of an available 250,000?

Thanks again,

Loren 
98  Using Arduino / Programming Questions / Re: error: avrdude: stk500v2_ReceiveMessage(): timeout on: January 28, 2013, 08:34:50 am
Ok

Sketch:

Code:
#include "Midi.h"
#include "Card.h"
//#include "eht.h"
#include "SD.h"
#include "SPI.h"
#include "Ethernet.h"


Midi midi;
Card card;
//Eth eth;

void setup(){
  Serial.begin(9600);
  Serial1.begin(31250);
  Serial2.begin(9600);
  Serial.println("Setup has begun");
  midi.init();
  card.init();
 
  //eth.init();
  midi.blinky();
 
}

void loop(){
 midi.rxComm();
}

Card.h:
Code:
#ifndef Card_h
#define Card_h

#include "Arduino.h"
#include <SD.h>


class Card{


public:
void init();
void midiCommand(int stuff);


private:
int CS_pin;
File myFile;
SdFile root;
SdVolume volume;
boolean cardReady;

//midi command variables
int n;
char d;
char c;
char LineFromFile[255];
int stuff;
int junk;

};


#endif

Card source:
Code:
#include "Arduino.h"
#include "Card.h"

void Card::init(){
 CS_pin = 4;
pinMode(CS_pin, OUTPUT);
if(!SD.begin(CS_pin)){
  Serial.println("Card Failed");
  return;
}
Serial.println("Card Ready");
cardReady = true;
}

void Card::midiCommand(int stuff){
 Serial.println("midi command called");
  n = 0;
 myFile = SD.open("midiComm.csv");
 Serial.println("File should be open");
 while (myFile.available()){
 
   c = myFile.read();
     if (c != '\n'){
      LineFromFile[n] = c;
     n++;
    int xyz;
     for (xyz = 0; xyz < n; xyz++){
        if (LineFromFile[xyz] != ','){
          junk += LineFromFile[xyz];
          Serial.print(LineFromFile[xyz]);
          if(junk == stuff){
             Serial.println("GOOOD!!!!  ");
          }
        }else{
          Serial.print(" ");
        }   
     }
     }else{
       Serial.println(" ");
 }
 n = 0;
 
}

}

Midi.h:
Code:
#ifndef Midi_h
#define Midi_h

#include "Arduino.h"

class Midi{
 
 public:
 void init();
 void blinky();
 void rxComm();

private:
#define STAT1 7
#define STAT2 6

};

#endif

Midi source:

Code:
#include "Arduino.h"
#include "Midi.h"
#include "Card.h"

void Midi::init(){
 pinMode(STAT1,OUTPUT);
 pinMode(STAT2,OUTPUT);
 
}

void Midi::blinky(){
 for(int i = 0; i < 10; i++){
  digitalWrite(STAT1,HIGH);
  digitalWrite(STAT2,LOW);
  delay(30);
  digitalWrite(STAT1,LOW);
  digitalWrite(STAT2,HIGH);
  delay(30);
 }
 digitalWrite(STAT1,HIGH);
 digitalWrite(STAT2,HIGH);
}

void Midi::rxComm(){
  Card card;
  if (Serial1.available()){
   Serial.print("MIDI:  ");
    digitalWrite(STAT2,LOW);
   int inByte = Serial1.read();
    Serial.println(inByte);
   Serial1.flush();
  delay(10);
 digitalWrite(STAT2,HIGH);

  if(inByte > 191){
   if (inByte <208){
     card.midiCommand(inByte);
  }
  }
}
}
99  Using Arduino / Programming Questions / error: avrdude: stk500v2_ReceiveMessage(): timeout on: January 28, 2013, 08:27:15 am
I receive the error listed above when I attempt to upload a sketch with a couple of libraries that I have written.  I can up load other sketches successfully.  Originally I thought that it was a corrupt library file so I retyped everything into a new sketch (including the libraries).

I'm happy to post any other information that might be helpful. 


Thoughts?  Suggestions?


Loren

PS if I have posted in the wrong place feel free to move my post.
100  Using Arduino / Programming Questions / Re: SD not declared in this scope on: January 27, 2013, 03:01:28 pm
We need to see your sketch, too. I'm guessing, though, that it does not include SD.h. It needs to.

Yep that was it.  Thanks again

101  Using Arduino / Programming Questions / SD not declared in this scope on: January 27, 2013, 02:43:28 pm
h
Code:
#ifndef Card_h
#define Card_h

#include "Arduino.h"
#include <SD.h>"

class Card{
 
public:
 void init();

private:
  int CS_pin;
};



#endif

source:

Code:
#include "Arduino.h"
#include "Card.h"

void Card::init(){

pinMode(CS_pin, OUTPUT);
if(!SD.begin(CS_pin)){
    Serial.println("Card Failed");
    return;
  }
  Serial.println("Card Ready");

 
}

I've read some web articles describing how to write libraries and I seem to be consistently failing at making this work.  I wrote a single sketch to see if I could read some info off of a SD card.  When I start to try and write a library to accomplish the task I get the error:

Code:
Card.cpp:9: error: 'SD' was not declared in this scope
  can someone explain why this doesn't work?

Thanks,

Loren
102  Using Arduino / Programming Questions / Reading csv to Array on: January 27, 2013, 10:18:56 am
I'm trying to read csv data from a micro SD card to an array.

Here is the code that I've come up with:

Code:
#include "SD.h"


int CS_pin = 4;
File myFile;
File aFile;
int index = 0;
  int row = 0;
  int col = 0;

void setup(){
Serial.begin(9600);
pinMode(CS_pin, OUTPUT);


// check if the card is ready

  if(!SD.begin(CS_pin)){
    Serial.println("Card Failed");
    return;
  }
  Serial.println("Card Ready");
 

  char LineData[255];
  char d;
  char o; //char counter
  aFile = SD.open("two.csv");
 
  while (aFile.available()){
   
    d = aFile.read();
    // if this is not a newline char, store and move on
            if (d != '\n') { //not a new line
               LineData[o] = d;
                o++;
                if (LineData[o] != ','){
                 }else{
                    col++;
                  }
            }else {
             
                row++;
                col = 0;

            }//close checking for new line char
           
  }//Close While
  aFile.close();
  col++;
     Serial.println("One Column Added");
     Serial.print("Columns:  ");
     Serial.println(col);
     Serial.print("Rows:  ");
     Serial.println(row);
 
  String dArray [row][col];
   myFile = SD.open("two.csv");
   
 int n = 0; // the character counter
 int prev = 0;
 String inString;
int aRow=0;
int aCol=0;
char LineFromFile[255]; 
char c; // character read in from file


 while (myFile.available()) {
    c = myFile.read();
       // if this is not a newline char, store and move on
            if (c != '\n') {
             LineFromFile[n] = c;
                n++;
               
                   // this works fine for now
                    int xyz;
                      for (xyz = 0; xyz< n; xyz++){
                      if (LineFromFile[xyz] != ','){
                          dArray[aRow][aCol] += LineFromFile[xyz];
                         Serial.print(LineFromFile[xyz]);
                      }else{
                          Serial.print(" ");
                          aCol++;
                          Serial.print("ci ");
                        }
                       
                      }
                     
            // we reached end of the line, process what we found
            } else {
                   
                 Serial.println(" ");     

               
               aRow++;
                    aCol=0;
                   Serial.print("c0 ");
            }
    n = 0;
  }
   
   
   
int y;
int z;
Serial.println(" ");
Serial.println("Info:  ");
Serial.println(" ");
Serial.print("Row:  ");
Serial.println(row);
Serial.print("Column:  ");
Serial.println(col);
Serial.println(" ");

int col2 = col + 1;
for (y=0; y < row; y++){
 for (z=0; z < col2; z++){
  Serial.print(dArray[y][z]);
  Serial.print(" ");
 
 }
Serial.println(" ");
}
  }

void loop(){

}

Here is the file that I'm reading:
Code:
id,twoCommands,description
1,@02353,Play
2,@02354,Stop
3,@02355,Record
4,@023MT,ManTrack

Here is what the serial monitor reads out:

Code:
Card Ready
One Column Added
Columns:  2
Rows:  4
id ci twoCommands ci description
c0 1 ci @02353 ci Play
c0 2 ci @02354 ci Stop
c0 3 ci @02355 ci Record
c0 4 ci @023MT ci ManTrack
Info: 
 
Row:  4
Column:  2
 
id twoCommands description1 
description1 @02353 Play2 
Play2 @02354 Stop3 
Stop3 @02355 Record4

When the serial monitor reads the data being parsed to the array it appears as though the process is happening correctly.  I used the c0 and ci to ensure that the column ints were be changed at the appropriate time.  I think that here is something going on in the way that the array is being read back at the end, but I can't figure it out. 

Any help would be awesome!

Loren
103  Using Arduino / Programming Questions / Re: declarations in libraries on: January 25, 2013, 11:27:43 am
That was the only place I could find to create it "Globally" that the source file could see it.  Where should it be declared?
104  Using Arduino / Programming Questions / Re: declarations in libraries on: January 25, 2013, 07:59:22 am
I think this will be the last step in helping me figure out how to write libraries.  Here is the code as it stands now:

sketch:
Code:
#include <SPI.h>
#include <Ethernet.h>
#include "eth.h"

Eth eth;

EthernetServer server(80);

void setup(){
  Serial.begin(9600);
  Serial.println("Setup has begun");
eth.init();
}


void loop(){
  //Serial.println("Loop");
 eth.servClient();
}

eth.h:
Code:
#ifndef eth_h
#define eth_h

#include <SPI.h>
#include <Ethernet.h>
#include "Arduino.h"
 



class Eth{


 public:


void init();
void servClient();

private:
byte mac[5];

};
#endif

eth.cpp:
Code:
#include "Arduino.h"
#include "eth.h"

void Eth::init(){
 mac[0] = 0xDE;
 mac[1] = 0xAD;
 mac[2] = 0xBE;
 mac[3] = 0xEF;
 mac[4] = 0xFE;
 mac[5] = 0xED;
IPAddress ip(192,168,1,177);
extern EthernetServer server;
  Ethernet.begin(mac, ip);
  server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP());
 
}

void Eth::servClient(){
   Serial.print("Server is at:  ");
 Serial.println(Ethernet.localIP());
  //Serial.println("servClient called");
  extern EthernetServer server;
   // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<head><title>Lorens Page</title></head>");
                    // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
         
          //client.print("Transport is currently:  ");
          //client.print(stat);
          client.println("<br />");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");       
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }

}

Clients are unable to connect to the server.  I have a feeling this has something to do with the way that I have declared "EthernetServer server(80)" and the way I'm using extern. 

Are the functions "init" and "serveClient" in the Eth class creating their own instance of server?

Again many many thanks!

Loren
105  Using Arduino / Programming Questions / Re: declarations in libraries on: January 25, 2013, 06:30:41 am
For those trying to avoid the pain of what I just went through here is what I found:

Please explain why those are global variables (that is why they are created twice), rather than class fields.

You could define the variables in the sketch, and add extern in front of the declaration statements in the header. That way, the header file would simply affirm that the variables are defined somewhere else, and would allow access to them, wherever they are defined.

I didn't necessarily want them to be global variables.  After seeing that comment I took another look at the library tutorial and noticed that I should be declaring the variables below with the private declarations for the class:

Code:
#ifndef eth_h
#define eth_h

#include <SPI.h>
#include <Ethernet.h>
#include "Arduino.h"
 
class Eth{

public:
void init();

private:
byte mac[5];
};
#endif

Pages: 1 ... 5 6 [7] 8 9 ... 11