How to connect SCP1000 pressure sensor

we are just using the i/o pins.

Well, I'm curious if you're using a 3.3V model of Arduino or a 5v model. I think most are 5v, in which case you need to level shift the output pins to be compatible with the SCP1000. The sensor is a 3.3V device and shouldn't have 5V on its inputs.

I'm using a 5v Arduino and on each of SCK, MOSI, and CSB, I have a resistor voltage divider to drop down to ~3.3v. From the Arduino pin I have 2.2k resistor to a 3.3k resistor to ground. The SCP pins connect to the junction between the resistors.

The SCP output (MISO) can go directly to the Arduino input pin.

We are using a 5v arduino with no resistors. but its working correctly.

It would be best to use resistors as over time the overvoltage on the input pins could shorten the life of the device. It's stressing the input protection.

Although I'm using 2.2k and 3.3k, 1.8k and 3.3k would be closer to the desired values. I just had the 2.2k on hand because it's a more commonly used value.

Kathy says: The code worked for a day and then it starting giving us the same random values. I unplugged the 3.3v pin and the values normalized. we check the temp reading against a thermostat. and the pressure is generally 989-990 indoors which is reasonable. can anyone explain why the chip is working without the 3.3v pin?

I can't explain but I can confirm this: I also got mosty random values (all temperatures were false and only 10% of pressure values were near correct. Then I read Kathy's post, unplugged 3.3V pin and then all values normalized.

My configuration:

  • Macbook Pro 15" and Mac Os X 10.6
  • Arduino Duemilanove (which has 5V and 3.3V pins), plugged in with USB cable
  • Sparkfun SCP1000
  • dilbert98122's library code is placed in directory Arduino/libraries/scp1000/

EDIT: I measured voltage between some pins in SCP1000 (all but 3.3V are connected to Arduino):
GND-3.3V: 4.3V
GND-SCK: 0.0V
GND-MOSI: 4.9V
GND-MISO: 2.3V
GND-CSB: 4.9V

Is this 4.9V bad or normal? Should I have some resistor between SCP1000 and Arduino in some pins as dilbert98122 suggested?
(I'm very new to this Arduino and electronics stuff. :slight_smile:


Here are some values 3.3V pin unplugged:

---------------------------------
Temprature (C): 22.85
Pressure (hPa): 1011.32
---------------------------------
Temprature (C): 22.85
Pressure (hPa): 1011.33
---------------------------------
Temprature (C): 22.85
Pressure (hPa): 1011.36
---------------------------------
Temprature (C): 22.90
Pressure (hPa): 1011.33
---------------------------------

And 3.3V pin plugged in:

---------------------------------
Temprature (C): 29.45
Pressure (hPa): 683.92
---------------------------------
Temprature (C): -50.45
Pressure (hPa): 683.88
---------------------------------
Temprature (C): 33.25
Pressure (hPa): 683.95
---------------------------------
Temprature (C): -50.45
Pressure (hPa): 684.08
---------------------------------
Temprature (C): 34.40
Pressure (hPa): 1011.76
---------------------------------
Temprature (C): 34.70
Pressure (hPa): 1011.59
---------------------------------
Temprature (C): 34.95
Pressure (hPa): 684.17
---------------------------------
Temprature (C): -50.45
Pressure (hPa): 1011.52
---------------------------------
Temprature (C): -50.45
Pressure (hPa): 683.83
---------------------------------

I suspect that the reason it works with the 3.3V supply unplugged is that the 5v on the I/O lines is bleeding through the input protection diodes to the Vdd pin and that the bypass capacitor is storing enough charge between low-bits on the I/O lines to power the chip. (supporting evidence is that the measured Vdd voltage is 0.6V less than the two inputs, CSB and MOSI.)

I'm not sure why this would be more stable than when the normal power supply is connected, but it may have to do with having higher voltages on the I/O pins than at Vdd. With 3.3V connected, the supply pin would be held at that voltage. With it disconnected, it can float up to the 4.3 that was measured.

In any case, it's not a good idea. It puts more stress on the device and is likely to shorten its life.

I've been running this device for about a month now using the 3.3V supply and the resistors mentioned, and it has been working reliably. Temperature tracks well compared to two different sensors within expected tolerances. Pressure tracks well with local NOAA stations after compensating for altitude.

I have found this forum thread to be very useful. I have recently begun using the SCP1000 and I have made some observations that may be useful to others.

I have the Sparkfun breakout board, I am using the 3.3 v supply from the Arduino, and I am using resistor voltage dividers to connect the Arduino outputs to the sensor. It all seemed to be working well but on inspecting the data I felt that there was more noise than I had expected even though I had the sensor in the high resolution (17 bit) mode. I set up Hyperterminal to connect to the Arduino (the USB interface showed up as COM7) and captured 256 consecutive readings from the sensor . I copied these readings into spreadsheet and found that the standard deviation was >6 Pascals. That was a far cry from the 1.5 Pa quoted in the data sheet.

I don't intend to use this with the USB interface so I powered the Arduino with a wallwart power supply and connected to Hyperterminal through a standard RS232 interface ( I used a Kronos Robotics Easy RS232 interface to convert the Arduino serial port to RS232). With this setup I repeated my measurements and found that the standard deviation was now between 1.4 and 1.3 Pascal.

I don't know if this is unique to my computer but this may be of help to others who are looking for maximum resolution.

Incidentally, at my altitude (near sea level) the difference in pressure over a distance of 6 feet is about 33 Pa. This sensor can easily detect small changes in altitude if you can minimize external noise sources.

A final note: If you duplicate the RS232 connection as I described here then you need to disconnect it when you want to communicate through the Arduino USB port.

Hi
I have found your library for SCP1000,
It's Good, but I have to implement your library using the standard Firmata to connect arduino and Max Msp.
I have to use the pin from 2 to 5 for the sensor, i've yet modified the firmata to ignore these pin, and try to modify your library to use those, but he doesent work.
i send you the code i have change
your scp1000.cpp

line 12     const byte DataOutPin = 3;
               const byte DataInPin = 4;
               const byte SPIClockPin = 5;

StandardFirmata.pde

#include <scp1000.h>
#define SelectPin 2
SCP1000 scp1000(SelectPin);

Can You Help Me?
more at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1273007365/0

Good question. In Spi.h, the SS pin defaults to digital 10. The class definition doesn't seem to allow the creation of more than one instance of Spi either.

Nope, this isn't true, the SS pin is only implemented in hardware in SPI slave mode, and here the ATmega is the master - use any pin(s) you like for chip selects, just make sure to use pinMode() to select them as outputs. Not sure what the Spi class does, but I bet you can just assert a chip select pin before using it and de-assert afterwards.

Driving the ATmega SPI hardware direct isn't too hard either if you want.

There is a diagram and some code here:

Hello all.

Can any one please help me?

How I can transfer the the above files into the library?

I tried to copy them into a text file renamed it with .h and .cpp, put them in a folder into the library but didn't work.
I copy them to the sketch window and save them with the extension .h and .cpp and it didn't result also.

So your help is appreciated.

Thanks in advance.

regards,
Manuel Silva

Hello all,

I forgoten to say that the files I am refering are the ones on post number 14 of this topic.

Thanks
Manuel Silva

I tried to copy them into a text file renamed it with .h and .cpp, put them in a folder into the library but didn't work.

What didn't work? You were not able to save them as text files? You were not able to rename them? Do you know where library files are supposed to be located for your operating system and version of the IDE?

I copy them to the sketch window and save them with the extension .h and .cpp and it didn't result also.

Didn't result in what?

Hey Guys Im pretty new at this so sorry if this is basic or incoherent. I'm trying to use three SCP1000 sensors using the Mega. The way I'm doing it now is just calling each sensor to get the data then move on to the next one. For whatever reason I can't get this to work. I'm not sure if there is something in the SPI protocol that isn't letting it work right but it only will receive and print data that is from the sensor that is first in line. I'll post my code. Thanks for any help you can be.

/*

1   VSS/GND           gnd      
2   AVDD              3.3 v
3   TRIG              Connect to gnd if not used      
4   DRDY (Int)        n/a      
5   DVDD              3.3 V      
6   PD                connect to gnd if not used      
7   SCLK              pin 13/52 using 10K resistor
8   MOSI              pin 11/51 using 10K resistor
9   MISO              pin 12/50 straight through (no resistor needed)
10  CSB               pin 10/53 using 1K with 10K 3.3v pull up from
                        sensor side of 1K
*/

// define spi bus pins
#define SLAVESELECT 53   // CS/SS pin 10 or 53
#define SPICLOCK 52      // clk pin 13 or 52
#define DATAOUT 51       //MOSI pin 11 or 51
#define DATAIN 50       //MISO pin 12 or 50
#define UBLB(a,b)  ( ( (a) << 8) | (b) )
#define UBLB19(a,b) ( ( (a) << 16 ) | (b) )

//Addresses
#define REVID 0x00      //ASIC Revision Number
#define OPSTATUS 0x04   //Operation Status
#define STATUS 0x07     //ASIC Status
#define START 0x0A      //Constant Readings
#define PRESSURE 0x1F   //Pressure 3 MSB
#define PRESSURE_LSB 0x20 //Pressure 16 LSB
#define TEMP 0x21       //16 bit temp
#define SELPIN39 39
#define SELPIN40 40
#define SELPIN41 41

char rev_in_byte;          
int temp_in;
unsigned long pressure_lsb;
unsigned long pressure_msb;
unsigned long temp_pressure;
unsigned long pressure;

void setup()
{
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device  

  for ( int SELPIN=39; SELPIN < 42; SELPIN++)
  {
    pinMode(SELPIN,OUTPUT);
    digitalWrite(SELPIN,OUTPUT);
  }
  

  SPCR = B01010011; //MPIE=0, SPE=1 (on), DORD=0 (MSB first), MSTR=1 (master), CPOL=0 (clock idle when low), CPHA=0 (samples MOSI on rising edge), SPR1=0 & SPR0=0 (500kHz)
  clr=SPSR;
  clr=SPDR;
  delay(10);
  Serial.begin(9600);
  delay(500);

  Serial.println("Initialize High Speed Constant Reading Mode");
  write_register(0x03,0x09);
}

void loop()
{
  
  rev_in_byte = read_register(REVID);
  
  pressure_msb = read_register(PRESSURE);
  pressure_msb &= B00000111;
  pressure_lsb = read_register16(PRESSURE_LSB);
  pressure_lsb &= 0x0000FFFF;  // this is BLP's fix
  pressure = UBLB19(pressure_msb, pressure_lsb);
  pressure /= 4;
  
//  Serial.print("PRESSURE (Pa)[");
  Serial.print(pressure, DEC);
  Serial.println("]");
  
 // Serial.print("PRESSURE (Atm)[");
 // float pAtm=float(pressure)/101325.0;
  //Serial.print(pAtm, 3);
 // Serial.println("]");
  
  temp_in = read_register16(TEMP);
  float tempC = float(temp_in)/20; // use 20 by the spec sheet - my board seems closer to 19
  //Serial.print("TEMP C [");
  Serial.print(tempC , 0);  Serial.println("]");
 // float tempF = tempC*1.8 + 32;
 // Serial.print("TEMP F [");
//  Serial.print(tempF , 0);  Serial.println("]");
 // Serial.println("--------------------------");
  //delay(2500);
  
}

char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait for the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}


char read_register(char register_name)
{
    char in_byte;
    register_name <<= 2;
    register_name &= B11111100; //Read command
  
 
    
     digitalWrite(SELPIN40,LOW); //Select SPI Device
    spi_transfer(register_name); //Write byte to device
    in_byte = spi_transfer(0x00); //Send nothing, but we should get back the register value
    digitalWrite(SELPIN40,HIGH);
    delay(10);
    return(in_byte);
 
   digitalWrite(SELPIN39,LOW); //Select SPI Device
    spi_transfer(register_name); //Write byte to device
    in_byte = spi_transfer(0x00); //Send nothing, but we should get back the register value
    digitalWrite(SELPIN39,HIGH);
    delay(10);
    return(in_byte);
  
}

unsigned long read_register16(char register_name)
{
    byte in_byte1;
    byte in_byte2;
    float in_word;
    
    register_name <<= 2;
    register_name &= B11111100; //Read command

 
    
     digitalWrite(SELPIN40,LOW); //Select SPI Device
    spi_transfer(register_name); //Write byte to device
    in_byte1 = spi_transfer(0x00);    
    in_byte2 = spi_transfer(0x00);
    digitalWrite(SELPIN40,HIGH);
    in_word = UBLB(in_byte1,in_byte2);
    return(in_word);
    
    digitalWrite(SELPIN39,LOW); //Select SPI Device
    spi_transfer(register_name); //Write byte to device
    in_byte1 = spi_transfer(0x00);    
    in_byte2 = spi_transfer(0x00);
    digitalWrite(SELPIN39,HIGH);
    in_word = UBLB(in_byte1,in_byte2);
    return(in_word);
 }

void write_register(char register_name, char register_value)
{
    register_name <<= 2;
    register_name |= B00000010; //Write command


       
       digitalWrite(SELPIN40,LOW); //Select SPI device
    spi_transfer(register_name); //Send register location
    spi_transfer(register_value); //Send value to record into register
    digitalWrite(SELPIN40,HIGH);
     
        digitalWrite(SELPIN39,LOW); //Select SPI device
    spi_transfer(register_name); //Send register location
    spi_transfer(register_value); //Send value to record into register
    digitalWrite(SELPIN39,HIGH);
 
}