Shop OBEX P1 Docs P2 Docs Learn Events
Need sample code interfacing Altimeter and Arduino SPI — Parallax Forums

Need sample code interfacing Altimeter and Arduino SPI

danidubdanidub Posts: 13
edited 2012-06-14 05:46 in Accessories
Hello, I recently buy a Altimeter Module MS5607 (http://www.parallax.com/Store/Sensors/AccelerationTilt/tabid/172/ProductID/780/List/0/Default.aspx?SortField=ProductName,ProductName) and I need to interface it with my Arduino UNO with SPI protocol.

Any advice there, any sample code? I cant figure how to communicate with the module.

Thanks, Daniel P

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2012-05-14 14:31
    All of the demo code that I have seen is for I2C. Arduino I2C code is at https://sites.google.com/site/parallaxinretailstores/home/altimeter-module-ms5607

    John Abshier
  • danidubdanidub Posts: 13
    edited 2012-05-14 14:34
    All of the demo code that I have seen is for I2C. Arduino I2C code is at https://sites.google.com/site/parallaxinretailstores/home/altimeter-module-ms5607

    John Abshier

    Hi John, thank you! I have already seen the I2C code, but I need to communicate with SPI.
    Daniel P.
  • FranklinFranklin Posts: 4,747
    edited 2012-05-14 15:56
    What is it you are having trouble with? How are you connected and what code have you tried? are you sure you set the protocol line correctly?
  • danidubdanidub Posts: 13
    edited 2012-05-14 16:48
    Franklin wrote: »
    What is it you are having trouble with? How are you connected and what code have you tried? are you sure you set the protocol line correctly?
    Hello Franklin, the connection is ok, I follow the datasheet of the altimeter, but I have no code at all.
    Thank you,
    Daniel P.
  • FranklinFranklin Posts: 4,747
    edited 2012-05-14 19:58
    If you are looking for Arduino code I would recommend the arduino site. http://arduino.cc
  • danidubdanidub Posts: 13
    edited 2012-05-16 14:55
    Franklin wrote: »
    If you are looking for Arduino code I would recommend the arduino site. http://arduino.cc

    Thank you, but I have searched all over the internet and forums with no success for this module connected with SPI :(
  • FranklinFranklin Posts: 4,747
    edited 2012-05-16 22:06
    All you should need to do is send the text using SPI rather than I2C. It seems to be mostly ascii commands and returns.
  • danidubdanidub Posts: 13
    edited 2012-05-18 05:01
    Franklin, can you give me an idea of code for Arduino using SPI and this module (if you have some), I'm really new at this and sometimes it gets really complicated, or perhaps you can tell me the logic used in this communication for me to try some coding.
    Thank you,
    Daniel P.
  • FranklinFranklin Posts: 4,747
    edited 2012-05-18 11:06
    If you look at the intersemabaro.h file the places where there are Wire.write() lines are what needs to be sent to the baro and Wire.read() is where stuff is read from the baro.
  • danidubdanidub Posts: 13
    edited 2012-05-18 15:33
    Thank you Franklin! I'll try to code that! if succeed I'll post it here, have a nice day.
    Daniel P
  • danidubdanidub Posts: 13
    edited 2012-06-14 05:46
    Hello, and here again!
    I'm still trying and I made this code, that when a "0" is recieved in the serial, the arduino sends the conversion and read commands to the altimeter and stores the 24 bit data of the altitude. Till now, I get the data in three bytes, but for some reason I only get 3 bytes of 11111111, 11111111, 11111111.
    I post the code:
    /*
    Circuit:
     SCK: pin 13
     MISO: pin 12
     MOSI: pin 11
     SS: pin 9
     */
    
    
    const int ss = 9;
    #include <SPI.h>
    
    
    //3 bytes to get the 24 bit adc read
    byte byte1; 
    byte byte2; 
    byte byte3;
    
    
    void setup() {
      Serial.begin(9600);
    
    
      SPI.begin();
      SPI.setBitOrder(MSBFIRST);
    
    
      pinMode(ss, OUTPUT);
    }
    
    
    void loop() {
    
    
      if (Serial.available() > 0) {
    
    
        byte incomingByte = Serial.read();
    
    
        switch (incomingByte){
        case '0':
          read_alt();
          break;
        } //endswitch
    
    
      }//enif
    
    
    }//endloop
    
    
    void read_alt()
    {
      //READ Altimeter
      digitalWrite(ss, LOW);
      SPI.transfer(0x50); //ADC conversion command
      delay(1);
    
    
      // and store read data into three bytes
      byte1 = SPI.transfer(0x00);//ADC conversion read command, first 8 bits
      byte2 = SPI.transfer(0x00);//ADC conversion read command, second 8 bits
      byte3 = SPI.transfer(0x00);//ADC conversion read command, third 8 bits
    
    
      //print the 3 bytes in serial
      Serial.println(byte1, BIN);
      Serial.println(byte2, BIN);
      Serial.println(byte3, BIN);
      Serial.println();
    
    
      //release chip, signal end transfer
      digitalWrite(ss, HIGH); 
    }
    
    
    
Sign In or Register to comment.