Loading...
  Show Posts
Pages: [1] 2 3 ... 8
1  Products / Arduino Due / Re: Octave/Matlab Vector Programming in Due on: February 28, 2013, 11:19:33 am

Binary sketch size: 183,028 bytes (of a 524,288 byte maximum) - 34% used

So the LDA eample that has slightly different number results but did one calculation correctly i would have to try it with some of the sample data or octave or r example data to see if it continues to work.

Well I got the code to compile for a pc and compile for the arduino due. Now the pc I tested it will this run on the arduino due? Sorry about the mess.

Code:
//Josh W
//lda example reference http://people.revoledu.com/kardi/tutorial/LDA/Numerical%20Example.html
//reference http://eigen.tuxfamily.org/dox/TutorialMatrixArithmetic.html
// Example By: RandomVibe
// Eigen Doc: http://eigen.tuxfamily.org/dox/
// Quick Reference: http://eigen.tuxfamily.org/dox/QuickRefPage.html

#include <iostream>
#include <math.h>
#include <Eigen312.h>     // Calls main Eigen3.1.2 matrix class library
#include <Dense>
#include <LU>             // Calls inverse, determinant, LU decomp., etc.
using namespace Eigen;    // Eigen related statement; simplifies syntax for declaration of matrices
using Eigen::MatrixXd;
using namespace std;

void print_mtxf(const Eigen::MatrixXf& K);


void setup() {

    Serial.begin(9600);
   
    // DECLARE MATRICES
    //--------------------
  //data matrix x row col
MatrixXd x(4,2);
//cur
x(0,0) = 2.95;//g0
x(1,0) = 2.53;
x(2,0) = 3.57;
x(3,0) = 3.16;

//dia
x(0,1) = 6.63;//g0
x(1,1) = 7.79;
x(2,1) = 5.65;
x(3,1) = 5.47;

MatrixXd x1(3,2);

x1(0,0) = 2.58;//g1
x1(1,0) = 2.16;
x1(2,0) = 3.27;

x1(0,1) = 4.46;//g1
x1(1,1) = 6.22;
x1(2,1) = 3.52;

MatrixXd ui(1,2);//group/feature

ui(0,0)=(x(0,0) + x(1,0) + x(2,0) + x(3,0))/4.0;
ui(0,1)=(x(0,1) + x(1,1) + x(2,1) + x(3,1))/4.0;

//transpose ui to uit
MatrixXd uit(1,2);//group/feature
uit=ui.transpose();


MatrixXd ui1(1,2);//group/feature

ui1(0,0)=(x1(0,0) + x1(1,0) + x1(2,0))/3.0;
ui1(0,1)=(x1(0,1) + x1(1,1) + x1(2,1))/3.0;

MatrixXd ui1t(1,2);//group/feature
ui1t=ui1.transpose();

MatrixXd u(1,2);//all group/feature
u(0,0)=(x(0,0) + x(1,0) + x(2,0) + x(3,0) + x1(0,0) + x1(1,0) + x1(2,0))/7.0;

u(0,1)=(x(0,1) + x(1,1) + x(2,1) + x(3,1) + x1(0,1) + x1(1,1) + x1(2,1))/7.0;

MatrixXd ximinu(4,2);
//cur
ximinu(0,0) = x(0,0) - u(0,0);//f0
ximinu(1,0) = x(1,0) - u(0,0);
ximinu(2,0) = x(2,0) - u(0,0);
ximinu(3,0) = x(3,0) - u(0,0);
//dia
ximinu(0,1) = x(0,1) - u(0,1);//f1
ximinu(1,1) = x(1,1) - u(0,1);
ximinu(2,1) = x(2,1) - u(0,1);
ximinu(3,1) = x(3,1) - u(0,1);
std::cout << ximinu << std::endl;
cout << "" << endl;

MatrixXd ximinu1(3,2);
//cur
ximinu1(0,0) = x1(0,0) - u(0,0);
ximinu1(1,0) = x1(1,0) - u(0,0);
ximinu1(2,0) = x1(2,0) - u(0,0);
//dia
ximinu1(0,1) = x1(0,1) - u(0,1);//g1
ximinu1(1,1) = x1(1,1) - u(0,1);
ximinu1(2,1) = x1(2,1) - u(0,1);

MatrixXd ximinut(4,2);
ximinut= ximinu.transpose();

MatrixXd ximinu1t(3,2);
ximinu1t= ximinu1.transpose();

MatrixXd ci(2,2);
ci = ( ximinut * ximinu ) /4.0;

MatrixXd ci1(2,2);
ci1 = ( ximinu1t * ximinu1 ) /3.0;

MatrixXd c(2,2);
c(0,0) = 4.0/7.0 * ci(0,0) + 3.0/7.0 * ci1(0,0);
c(1,0) = 4.0/7.0 * ci(1,0) + 3.0/7.0 * ci1(1,0);
c(0,1) = 4.0/7.0 * ci(0,1) + 3.0/7.0 * ci1(0,1);
c(1,1) = 4.0/7.0 * ci(1,1) + 3.0/7.0 * ci1(1,1);

MatrixXd cinverse(2,2);
cinverse=c.inverse();
 
MatrixXd xk(1,2);//new data
xk(0,0) = 2.81;//f1
xk(0,1) = 5.46;

MatrixXd xkt(1,2);//new data
xkt=xk.transpose();

MatrixXd lnp1(1,1);//p1 4/7
lnp1(0,0) = 0.0;
lnp1(0,0)=log(4.0/7.0);

MatrixXd lnp2(1,1);//p1 3/7
lnp2(0,0) = 0.0;
lnp2(0,0)=log(4.0/7.0);

MatrixXd f1(1,1);//ui   * cinverse * xkt  -1.0/2.0 * ui  * cinverse * uit + lnp1
MatrixXd f2(1,1);//ui1  * cinverse * xkt -1.0/2.0 * ui1 * cinverse * ui1t + lnp2

f1 = ui   * cinverse * xkt  -1.0/2.0 * ui  * cinverse * uit + lnp1;
f2 = ui1  * cinverse * xkt -1.0/2.0 * ui1 * cinverse * ui1t + lnp2;
 
if (f1(0,0)>f2(0,0)) cout << "the data is in group 1" << endl;
if (f1(0,0)<f2(0,0)) cout << "the data is in group 2" << endl;
    // Print Result
    //----------------------------
     //print_mtxf(K);      // Print Matrix Result (passed by reference)
   
}




void loop() {
  // put your main code here, to run repeatedly:
 
}




// PRINT MATRIX (float type)
//-----------------------------
void print_mtxf(const Eigen::MatrixXf& X)
{
    int i, j, nrow, ncol;
   
    nrow = X.rows();
    ncol = X.cols();

    Serial.print("nrow: "); Serial.println(nrow);
    Serial.print("ncol: "); Serial.println(ncol);       
    Serial.println();
   
    for (i=0; i<nrow; i++)
    {
        for (j=0; j<ncol; j++)
        {
            Serial.print(X(i,j), 6);   // print 6 decimal places
            Serial.print(", ");
        }
        Serial.println();
    }
    Serial.println();
}
2  Products / Arduino Due / Re: Octave/Matlab Vector Programming in Due on: February 27, 2013, 12:03:13 pm
I switched the board type to duo and it must look into the sam libraries folder so now the example compiles. I will try my code latter. Thank You.  smiley-grin  smiley-mr-green  smiley-lol
3  Products / Arduino Due / Re: Octave/Matlab Vector Programming in Due on: February 27, 2013, 11:59:18 am
Thanks I downloaded Arduino 1.5 ...
I put the eigen subdirectory into arduino hardware sam libraries then the eigen.h file in there. That is in the adafruit post.

Now I am getting errors with namespace...
using namespace Eigen;    // Eigen related statement; simplifies syntax for declaration of matrices
The print out option of the matrix tipe I am not shure how that works.

I useualy use standard c and arduino c.
4  Products / Arduino Due / Is their a way in the data sheet or some way to add more program memory to due. on: February 27, 2013, 10:17:52 am
I wanted to program the arduino due to do some linear algebra operations. Linear Discriminant Analysis. The code blocks c++ release code is over 520k already So I wonder is their ways to compile the program smaller and will it be smaller put into the arduino due as shown in the forums? It is on my pc now.
What are ways to add more program memory???
5  Products / Arduino Due / Re: Arduino Due libraries (official and 3rd party) on: February 27, 2013, 08:44:08 am
I am using the Eigen library and want to run it in the arduino due I have posted some of my codeblocks c++ code for my windows machine.

Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.

http://eigen.tuxfamily.org/index.php?title=Main_Page

Code:
#include <iostream>
#include <Eigen/Dense>
#include <Eigen/LU>
using Eigen::MatrixXd;
using namespace std;
int main()
{
cout << "Hello Pattern matching Linear Discriminent Analisis!" << endl;
cout << "" << endl;
cout << "x data" << endl;

//data matrix x row col
MatrixXd x(4,2);
//cur
x(0,0) = 2.95;//g0
x(1,0) = 2.53;
x(2,0) = 3.57;
x(3,0) = 3.16;

//dia
x(0,1) = 6.63;//g0
x(1,1) = 7.79;
x(2,1) = 5.65;
x(3,1) = 5.47;

std::cout << x << std::endl;
cout << "End of x data" << endl;
cout << "" << endl;

cout << "x1 data" << endl;

MatrixXd x1(3,2);

x1(0,0) = 2.58;//g1
x1(1,0) = 2.16;
x1(2,0) = 3.27;

x1(0,1) = 4.46;//g1
x1(1,1) = 6.22;
x1(2,1) = 3.52;

std::cout << x1 << std::endl;
cout << "End of x1 data" << endl;
cout << "" << endl;

//group adv
cout << "x data adverage ui" << endl;

MatrixXd ui(1,2);//group/feature
ui(0,0)=(x(0,0) + x(1,0) + x(2,0) + x(3,0))/4;
ui(0,1)=(x(0,1) + x(1,1) + x(2,1) + x(3,1))/4;
std::cout << ui << std::endl;
cout << "" << endl;

cout << "x1 data adverage ui1" << endl;

MatrixXd ui1(1,2);//group/feature

ui1(0,0)=(x1(0,0) + x1(1,0) + x1(2,0))/3.0;
ui1(0,1)=(x1(0,1) + x1(1,1) + x1(2,1))/3.0;
std::cout << ui1 << std::endl;
cout << "" << endl;

cout << "x & x1 data adverage u" << endl;
MatrixXd u(1,2);//all group/feature
u(0,0)=(x(0,0) + x(1,0) + x(2,0) + x(3,0) + x1(0,0) + x1(1,0) + x1(2,0))/7.0;

u(0,1)=(x(0,1) + x(1,1) + x(2,1) + x(3,1) + x1(0,1) + x1(1,1) + x1(2,1))/7.0;

std::cout << u << std::endl;
cout << "" << endl;


cout << "mean corrected data xig - u" << endl;
MatrixXd ximinu(4,2);
//cur
ximinu(0,0) = x(0,0) - u(0,0);//f0
ximinu(1,0) = x(1,0) - u(0,0);
ximinu(2,0) = x(2,0) - u(0,0);
ximinu(3,0) = x(3,0) - u(0,0);
//dia
ximinu(0,1) = x(0,1) - u(0,1);//f1
ximinu(1,1) = x(1,1) - u(0,1);
ximinu(2,1) = x(2,1) - u(0,1);
ximinu(3,1) = x(3,1) - u(0,1);
std::cout << ximinu << std::endl;
cout << "" << endl;

cout << "mean corrected data xi1 - u" << endl;


MatrixXd ximinu1(3,2);
//cur
ximinu1(0,0) = x1(0,0) - u(0,0);
ximinu1(1,0) = x1(1,0) - u(0,0);
ximinu1(2,0) = x1(2,0) - u(0,0);
//dia
ximinu1(0,1) = x1(0,1) - u(0,1);//g1
ximinu1(1,1) = x1(1,1) - u(0,1);
ximinu1(2,1) = x1(2,1) - u(0,1);

std::cout << ximinu1 << std::endl;

cout << " " << endl;

cout << "Transpose matricies" << endl;
cout << "xi - u T" << endl;

MatrixXd ximinut(4,2);
ximinut= ximinu.transpose();
std::cout << ximinut<< std::endl;
cout << " " << endl;

cout << "xi1 - u T" << endl;
MatrixXd ximinu1t(3,2);
ximinu1t= ximinu1.transpose();
std::cout << ximinu1t << std::endl;
cout << " " << endl;

cout << "Covariance matrix of group ci" << endl;
MatrixXd ci(2,2);
ci = ( ximinut * ximinu ) /4.0;
std::cout << ci << std::endl;
cout << "" << endl;

cout << "Covariance matrix of group ci1" << endl;
MatrixXd ci1(2,2);
ci1 = ( ximinu1t * ximinu1 ) /3.0;
std::cout << ci1 << std::endl;
cout << "" << endl;

cout << "Pooled within group Covariance matrix c" << endl;
MatrixXd c(2,2);
c(0,0) = 4.0/7.0 * ci(0,0) + 3.0/7.0 * ci1(0,0);
c(1,0) = 4.0/7.0 * ci(1,0) + 3.0/7.0 * ci1(1,0);
c(0,1) = 4.0/7.0 * ci(0,1) + 3.0/7.0 * ci1(0,1);
c(1,1) = 4.0/7.0 * ci(1,1) + 3.0/7.0 * ci1(1,1);
std::cout << c << std::endl;
cout << "" << endl;

cout << "inverse of Pooled within group Covariance matrix cinverse" << endl;
MatrixXd cinverse(2,2);
 cinverse=c.inverse();
std::cout << cinverse << std::endl;
cout << "" << endl;

cout << "Probability of a group" << endl;
cout << "x = 4/7 x1 = 3/7" << endl;

//create a vector of a probability...
cout << "" << endl;

//formula for calculatin likelyhood of data in a group...
//fi = uig cinverse xkt - 1/2uig cinverse uitg + ln probability

cout << "End of program!" << endl;

    return 0;
}
6  Products / Arduino Due / Re: Octave/Matlab Vector Programming in Due on: February 27, 2013, 08:41:13 am
Pattern Matching in arduino c++
I don't have the Arduino Due yet but I did write  this code in c++ code blocks on the release compile the size is Output size is 531.00 KB on my windows 8 computer and want to try it in a due. I wonder if the arduino due will be able to hold it and any suggestions to make it fit if not?

It inverts and multiplies and divides a constant from a matrix...

Code:
#include <iostream>
#include <Eigen/Dense>
#include <Eigen/LU>
using Eigen::MatrixXd;
using namespace std;
int main()
{
cout << "Hello Pattern matching Linear Discriminent Analisis!" << endl;
cout << "" << endl;
cout << "x data" << endl;

//data matrix x row col
MatrixXd x(4,2);
//cur
x(0,0) = 2.95;//g0
x(1,0) = 2.53;
x(2,0) = 3.57;
x(3,0) = 3.16;

//dia
x(0,1) = 6.63;//g0
x(1,1) = 7.79;
x(2,1) = 5.65;
x(3,1) = 5.47;

std::cout << x << std::endl;
cout << "End of x data" << endl;
cout << "" << endl;

cout << "x1 data" << endl;

MatrixXd x1(3,2);

x1(0,0) = 2.58;//g1
x1(1,0) = 2.16;
x1(2,0) = 3.27;

x1(0,1) = 4.46;//g1
x1(1,1) = 6.22;
x1(2,1) = 3.52;

std::cout << x1 << std::endl;
cout << "End of x1 data" << endl;
cout << "" << endl;

//group adv
cout << "x data adverage ui" << endl;

MatrixXd ui(1,2);//group/feature
ui(0,0)=(x(0,0) + x(1,0) + x(2,0) + x(3,0))/4;
ui(0,1)=(x(0,1) + x(1,1) + x(2,1) + x(3,1))/4;
std::cout << ui << std::endl;
cout << "" << endl;

cout << "x1 data adverage ui1" << endl;

MatrixXd ui1(1,2);//group/feature

ui1(0,0)=(x1(0,0) + x1(1,0) + x1(2,0))/3.0;
ui1(0,1)=(x1(0,1) + x1(1,1) + x1(2,1))/3.0;
std::cout << ui1 << std::endl;
cout << "" << endl;

cout << "x & x1 data adverage u" << endl;
MatrixXd u(1,2);//all group/feature
u(0,0)=(x(0,0) + x(1,0) + x(2,0) + x(3,0) + x1(0,0) + x1(1,0) + x1(2,0))/7.0;

u(0,1)=(x(0,1) + x(1,1) + x(2,1) + x(3,1) + x1(0,1) + x1(1,1) + x1(2,1))/7.0;

std::cout << u << std::endl;
cout << "" << endl;


cout << "mean corrected data xig - u" << endl;
MatrixXd ximinu(4,2);
//cur
ximinu(0,0) = x(0,0) - u(0,0);//f0
ximinu(1,0) = x(1,0) - u(0,0);
ximinu(2,0) = x(2,0) - u(0,0);
ximinu(3,0) = x(3,0) - u(0,0);
//dia
ximinu(0,1) = x(0,1) - u(0,1);//f1
ximinu(1,1) = x(1,1) - u(0,1);
ximinu(2,1) = x(2,1) - u(0,1);
ximinu(3,1) = x(3,1) - u(0,1);
std::cout << ximinu << std::endl;
cout << "" << endl;

cout << "mean corrected data xi1 - u" << endl;


MatrixXd ximinu1(3,2);
//cur
ximinu1(0,0) = x1(0,0) - u(0,0);
ximinu1(1,0) = x1(1,0) - u(0,0);
ximinu1(2,0) = x1(2,0) - u(0,0);
//dia
ximinu1(0,1) = x1(0,1) - u(0,1);//g1
ximinu1(1,1) = x1(1,1) - u(0,1);
ximinu1(2,1) = x1(2,1) - u(0,1);

std::cout << ximinu1 << std::endl;

cout << " " << endl;

cout << "Transpose matricies" << endl;
cout << "xi - u T" << endl;

MatrixXd ximinut(4,2);
ximinut= ximinu.transpose();
std::cout << ximinut<< std::endl;
cout << " " << endl;

cout << "xi1 - u T" << endl;
MatrixXd ximinu1t(3,2);
ximinu1t= ximinu1.transpose();
std::cout << ximinu1t << std::endl;
cout << " " << endl;

cout << "Covariance matrix of group ci" << endl;
MatrixXd ci(2,2);
ci = ( ximinut * ximinu ) /4.0;
std::cout << ci << std::endl;
cout << "" << endl;

cout << "Covariance matrix of group ci1" << endl;
MatrixXd ci1(2,2);
ci1 = ( ximinu1t * ximinu1 ) /3.0;
std::cout << ci1 << std::endl;
cout << "" << endl;

cout << "Pooled within group Covariance matrix c" << endl;
MatrixXd c(2,2);
c(0,0) = 4.0/7.0 * ci(0,0) + 3.0/7.0 * ci1(0,0);
c(1,0) = 4.0/7.0 * ci(1,0) + 3.0/7.0 * ci1(1,0);
c(0,1) = 4.0/7.0 * ci(0,1) + 3.0/7.0 * ci1(0,1);
c(1,1) = 4.0/7.0 * ci(1,1) + 3.0/7.0 * ci1(1,1);
std::cout << c << std::endl;
cout << "" << endl;

cout << "inverse of Pooled within group Covariance matrix cinverse" << endl;
MatrixXd cinverse(2,2);
 cinverse=c.inverse();
std::cout << cinverse << std::endl;
cout << "" << endl;

cout << "Probability of a group" << endl;
cout << "x = 4/7 x1 = 3/7" << endl;

//create a vector of a probability...
cout << "" << endl;

//formula for calculatin likelyhood of data in a group...
//fi = uig cinverse xkt - 1/2uig cinverse uitg + ln probability

cout << "End of program!" << endl;

    return 0;
}
7  Products / Arduino Due / Re: Octave/Matlab Vector Programming in Due on: February 24, 2013, 09:26:29 am
This is awsome and might work with the maple. I wonder if it would compile for fpga somehow like a xillinx.

I am interested in this and want to try to do linear discriminent analisis pattern matching.

The matrix inverse multiplication addition etc is needed for it.

I do not have a duo yet so i will try it in code blocks then on my leaflabs maple then the duo maby.

Has anyone tried this i like their documentation.

 smiley-cool  smiley-lol  smiley-mr-green
8  Forum 2005-2010 (read only) / Troubleshooting / Re: I have a sketch with loop & setup functions & one on: October 12, 2010, 07:00:09 am
I checked the wireing the wire came loose I get now 10010010 so I guess it is working I can read from the SPI the next test I will do is read & write to a different register that is read and write able.
9  Forum 2005-2010 (read only) / Troubleshooting / Re: I have a sketch with loop & setup functions & one on: October 12, 2010, 06:40:15 am
this is what it says it should be on the data sheet
010 = ADS1298; 24-bit resolution, 8 channels
the lower bits of Address = 00h
page 39
it is now showing all 1's
10  Forum 2005-2010 (read only) / Troubleshooting / Re: I have a sketch with loop & setup functions & one on: October 11, 2010, 04:40:45 pm
thanks andy brown

so what I did is:
  • I took the global vareables section pins and vareables.
  • coppied it into my function definition sketch
  • removed the declarations because it caused a error and they were allready defined in the main function.
  • I have not tried running this yet but it would be a good tutorial for the arduino community to have with the examples a 2 sketch main loop and setup and function defintion sketch.
11  Forum 2005-2010 (read only) / Troubleshooting / Re: I have a sketch with loop & setup functions & one on: October 11, 2010, 04:05:31 pm
here is the 2nd function sketch I wanted to seperate it because it was getting large but I think that might be causing bugs...
Code:
void ads1298_Set_Pins(void){
  SerialUSB.println("ADS1298 power up!");
  //setup pins for inputs and outputs
  pinMode(ledPin, OUTPUT);
  pinMode(RESET, OUTPUT);  
  pinMode(START, OUTPUT);  
  pinMode(DRDY, INPUT);
  pinMode(cs_main, OUTPUT);
  pinMode(cs_secondary, OUTPUT);
  pinMode(sclk, OUTPUT);
  pinMode(doutMISO_0, INPUT);
  pinMode(dinMOSI, OUTPUT);
}

void ads1298_Power_Up(void){
  //tie all low
  digitalWrite(START, LOW);
  digitalWrite(ledPin, LOW);
  digitalWrite(cs_main, LOW);
  digitalWrite(cs_secondary, LOW);
  digitalWrite(sclk, LOW);
  digitalWrite(dinMOSI, LOW);
  //step 1 wait 500ms instead of recomended 150ms
  //for power supplies to stableise
  delay(500);
  //set CLKSEL=1 wait 20us //allready set to 1 unless tie to pin.
  delay(500); //wait 500ms instead of 20us to let clk stableise
  //wait 2^16 tclk = 65536 tclk 2.x Mhz
  delay(1000); //wait 1 s instead of 65536 tclk
  //reset pulse low wait 18tclks longer low wait 5 sec for power on reset
  //reset allready tied HIGH
  digitalWrite(RESET, LOW);
  delay(100);
  digitalWrite(RESET, HIGH);
  delay(1000);
  delay(1000);
  delay(1000);
  delay(1000);
  delay(1000);
}

void send_Reset_Command(void){
  //0000 0110
  //msb first
  //set configuration registers...

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//msb 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //doutMISO 6 =0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //doutMISO 5 =0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //doutMISO 4 =0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //doutMISO 3 =0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, HIGH); //dinMOSI b2=1
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //doutMISO b1=1
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//dinMOSI b0=0
  digitalWrite(sclk, LOW);
}

void sdatac(void){
  //SDATAC
  //0001 0001
  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//msb7 = 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b6 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b5 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, HIGH);//b4 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//b3 = 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b2 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b1 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, HIGH);//b0=1
  digitalWrite(sclk, LOW);
}

void rreg (void){
  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//msb7 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b6 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, HIGH);//b5 1
  digitalWrite(sclk, LOW);
}

void wr_defalt_pre_num_of_bytes(void){
  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//msb 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b6 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b5 0
  digitalWrite(sclk, LOW);
}

void rwrite(void){  
  //rwrite = WREG
  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//msb 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, HIGH);//b7 1
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//b6 0
  digitalWrite(sclk, LOW);
}

void read_reg_0(void){
  rreg();
  
  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//b4 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b3 0
  digitalWrite(sclk, LOW);


  digitalWrite(sclk, HIGH);
  //b2 0
  digitalWrite(sclk, LOW);


  digitalWrite(sclk, HIGH);
  //b1 1
  digitalWrite(sclk, LOW);


  digitalWrite(sclk, HIGH);
  //b0 0
  digitalWrite(sclk, LOW);
}

void read_byte_1(void){
//wr_defalt_pre_num_of_bytes
wr_defalt_pre_num_of_bytes();
//number of bytes 0


    digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);  //b4 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b3 0
  digitalWrite(sclk, LOW);


  digitalWrite(sclk, HIGH);
  //b2 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b1 0
  digitalWrite(sclk, LOW);

  digitalWrite(sclk, HIGH);
  //b0 0
  digitalWrite(sclk, LOW);
}
12  Forum 2005-2010 (read only) / Troubleshooting / Re: I have a sketch with loop & setup functions on: October 11, 2010, 03:56:52 pm
Sorry I don't know how that happened

here is the first sketch the main setup() and loop() sketch of the 2 sketches the second is function definitons.


Code:
[color=#7E7E7E]//set pin names[/color]
[color=#CC6600]int[/color] ledPin =  13;      [color=#7E7E7E]// LED connected to digital pin 13 d13[/color]
[color=#CC6600]int[/color] RESET = 11;        [color=#7E7E7E]//reset pin active reset low d10.[/color]
[color=#CC6600]int[/color] START = 10;        [color=#7E7E7E]//start pin activate conversion when high d11.[/color]
[color=#CC6600]int[/color] DRDY = 12;         [color=#7E7E7E]//active low when data is ready to be read d12. [/color]
[color=#CC6600]int[/color] cs_main = 9;       [color=#7E7E7E]//selects main chip to configure registers d9[/color]
[color=#CC6600]int[/color] cs_secondary =8;   [color=#7E7E7E]//selects non-main chip to configure registers d9[/color]
[color=#CC6600]int[/color] sclk=14;          [color=#7E7E7E]//system clock for all the other pins d14[/color]
[color=#CC6600]int[/color] doutMISO_0=0;          [color=#7E7E7E]//doutMISO of the main chip 2-7 secondary chips master in slave out[/color]
[color=#CC6600]int[/color] dinMOSI=15;           [color=#7E7E7E]//data in to all other pins Master out slave in[/color]

[color=#7E7E7E]//global vareables[/color]
[color=#CC6600]int[/color] buttonState=[color=#006699]LOW[/color];
[color=#CC6600]int[/color] drdy_State=[color=#006699]HIGH[/color];
[color=#CC6600]int[/color] dout_input=[color=#006699]HIGH[/color];

[color=#7E7E7E]// The setup() method runs once, when the sketch starts[/color]

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()   {                

  ads1298_Set_Pins();
  ads1298_Power_Up();

  send_Reset_Command();
  [color=#7E7E7E]//delay after reset[/color]
  [color=#CC6600]delay[/color](1000);  
  [color=#CC6600]delay[/color](1000);  
  [color=#CC6600]delay[/color](1000);  
  [color=#CC6600]delay[/color](1000);  
  [color=#CC6600]delay[/color](1000);

  [color=#7E7E7E]//Stop Read Data Continuously mode [/color]
  sdatac();

  [color=#7E7E7E]//read = RREG When in RDATAC mode, the RREG command is ignored.[/color]



  [color=#7E7E7E]//read register 0[/color]
  read_reg_0();

  read_byte_1();


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b7[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b6[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b5[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b4[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b3[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b2[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b1[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);


  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]HIGH[/color]);
  [color=#7E7E7E]//b0[/color]
  [color=#CC6600]digitalWrite[/color](sclk, [color=#006699]LOW[/color]);
  dout_input = [color=#CC6600]digitalRead[/color](doutMISO_0);
  [color=#CC6600][b]SerialUSB[/b][/color].[color=#CC6600]print[/color](dout_input);



  [color=#7E7E7E]//  digitalWrite(START, HIGH);[/color]

  [color=#7E7E7E]//check for drdy change before filling registers...[/color]
  [color=#CC6600]while[/color](drdy_State==[color=#006699]HIGH[/color]){
    drdy_State = [color=#CC6600]digitalRead[/color](DRDY);
    [color=#CC6600]if[/color](drdy_State==[color=#006699]LOW[/color]){  
      [color=#CC6600]digitalWrite[/color](ledPin, [color=#006699]HIGH[/color]);
    }
  }

}
[color=#7E7E7E]// the loop() method runs over and over again,[/color]
[color=#7E7E7E]// as long as the Arduino has power[/color]

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()                    
{
  buttonState = [color=#CC6600]digitalRead[/color](DRDY);

  [color=#CC6600]if[/color](buttonState==[color=#006699]LOW[/color]){  
    [color=#7E7E7E]//    lowsig++;       [/color]
  }           [color=#7E7E7E]// wait for a second[/color]
  [color=#CC6600]if[/color](buttonState==[color=#006699]HIGH[/color]){  
    [color=#7E7E7E]//    highsig++;       [/color]
  }

  [color=#7E7E7E]//SerialUSB.println("Hello World! low");[/color]
  [color=#7E7E7E]//  SerialUSB.println(lowsig);[/color]
  [color=#7E7E7E]//  SerialUSB.println(highsig);[/color]

}




here is the second program in another post their isnt enough room.
13  Forum 2005-2010 (read only) / Troubleshooting / Re: I have a sketch with loop & setup functions & one on: October 11, 2010, 01:05:27 pm
yea you can all see it it was long so I was trying to be respectful here are both of them their for my open source electronics project talking to a ads1298 ti's biopotential mesurement chip a very advanced ADC.

Also my hardware the sensors board is made in kicad a open source hardware design piece of software much nicer than eagle.

https://sites.google.com/site/openloopproject/

The cad files can be downloaded there here is the code.

Quote
//set pin names
int ledPin =  13;      // LED connected to digital pin 13 d13
int RESET = 11;        //reset pin active reset low d10.
int START = 10;        //start pin activate conversion when high d11.
int DRDY = 12;         //active low when data is ready to be read d12.
int cs_main = 9;       //selects main chip to configure registers d9
int cs_secondary =8;   //selects non-main chip to configure registers d9
int sclk=14;          //system clock for all the other pins d14
int doutMISO_0=0;          //doutMISO of the main chip 2-7 secondary chips master in slave out
int dinMOSI=15;           //data in to all other pins Master out slave in

//global vareables
int buttonState=LOW;
int drdy_State=HIGH;
int dout_input=HIGH;

// The setup() method runs once, when the sketch starts

void setup()   {                

  ads1298_Set_Pins();
  ads1298_Power_Up();

  send_Reset_Command();
  //delay after reset
  delay(1000);  
  delay(1000);  
  delay(1000);  
  delay(1000);  
  delay(1000);

  //Stop Read Data Continuously mode
  sdatac();

  //read = RREG When in RDATAC mode, the RREG command is ignored.



  //read register 0
  read_reg_0();

  read_byte_1();


  digitalWrite(sclk, HIGH);
  //b7
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);


  digitalWrite(sclk, HIGH);
  //b6
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);


  digitalWrite(sclk, HIGH);
  //b5
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);


  digitalWrite(sclk, HIGH);
  //b4
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);


  digitalWrite(sclk, HIGH);
  //b3
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);


  digitalWrite(sclk, HIGH);
  //b2
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);


  digitalWrite(sclk, HIGH);
  //b1
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);


  digitalWrite(sclk, HIGH);
  //b0
  digitalWrite(sclk, LOW);
  dout_input = digitalRead(doutMISO_0);
  SerialUSB.print(dout_input);



  //  digitalWrite(START, HIGH);

  //check for drdy change before filling registers...
  while(drdy_State==HIGH){
    drdy_State = digitalRead(DRDY);
    if(drdy_State==LOW){  
      digitalWrite(ledPin, HIGH);
    }
  }

}
// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  buttonState = digitalRead(DRDY);

  if(buttonState==LOW){  
    //    lowsig++;      
  }           // wait for a second
  if(buttonState==HIGH){  
    //    highsig++;      
  }

  //SerialUSB.println("Hello World! low");
  //  SerialUSB.println(lowsig);
  //  SerialUSB.println(highsig);

}




Quote

void ads1298_Set_Pins(void){
  SerialUSB.println("ADS1298 power up!");
  //setup pins for inputs and outputs
  pinMode(ledPin, OUTPUT);
  pinMode(RESET, OUTPUT);  
  pinMode(START, OUTPUT);  
  pinMode(DRDY, INPUT);
  pinMode(cs_main, OUTPUT);
  pinMode(cs_secondary, OUTPUT);
  pinMode(sclk, OUTPUT);
  pinMode(doutMISO_0, INPUT);
  pinMode(dinMOSI, OUTPUT);
}

void ads1298_Power_Up(void){
  //tie all low
  digitalWrite(START, LOW);
  digitalWrite(ledPin, LOW);
  digitalWrite(cs_main, LOW);
  digitalWrite(cs_secondary, LOW);
  digitalWrite(sclk, LOW);
  digitalWrite(dinMOSI, LOW);
  //step 1 wait 500ms instead of recomended 150ms
  //for power supplies to stableise
  delay(500);
  //set CLKSEL=1 wait 20us //allready set to 1 unless tie to pin.
  delay(500); //wait 500ms instead of 20us to let clk stableise
  //wait 2^16 tclk = 65536 tclk 2.x Mhz
  delay(1000); //wait 1 s instead of 65536 tclk
  //reset pulse low wait 18tclks longer low wait 5 sec for power on reset
  //reset allready tied HIGH
  digitalWrite(RESET, LOW);
  delay(100);
  digitalWrite(RESET, HIGH);
  delay(1000);
  delay(1000);
  delay(1000);
  delay(1000);
  delay(1000);
}

void send_Reset_Command(void){
  //0000 0110
  //msb first
  //set configuration registers...

  digitalWrite(sclk, HIGH);
  digitalWrite(dinMOSI, LOW);//msb 0
  
14  Forum 2005-2010 (read only) / Troubleshooting / I have a sketch with loop & setup functions & one on: October 11, 2010, 12:49:39 pm
I have a sketch with loop & setup functions & one for my function definitions.

If the pin int is defined in the main sketch with loop and setip will the function be able to toggle it?

I have a program that toggles a serial clock for a spi device and prints out the results all the functions are in a second sketch where the functions are defined.

It is returning all 0's and their should not be acording to the registers on the data sheet.

what would this do with basic blink hello world and buttion sketches?
15  Forum 2005-2010 (read only) / Troubleshooting / Re: how do I use 1 clock cycle in easy to read code? on: February 25, 2010, 03:59:56 pm
thanks for adding the details I would have just put
NOP
then
NOP; on a line and scrached my head and started googleing when it didn't work.
It would be funny if it was renamed to LOLCAT NOM. ;D
Pages: [1] 2 3 ... 8