Show Posts
|
|
Pages: [1]
|
|
1
|
Using Arduino / Sensors / Re: SensorTechnics i2c Pressure Sensor
|
on: March 28, 2013, 03:47:07 am
|
Pylon, Thanks for your help, you've helped me solve it! Thank you. I found that it was a voltage dip in the 5v supply from the Arduino board. I measured it at just less than 4.3v and running the Mega off separate power supply rather than the USB power the sensor came to life. Attached is an image of the results (me blowing air into the sensor), the values are in counts of course. For reference (in case I lose it!), here's the final code I used: //Code to read a SensorTronics SSIB001GU9AH5 Pressure Sensor //Thanks to 'Pylon' on Arduino Forum.
#include <Wire.h> //For I2C comms byte byte_msb, byte_lsb; // 8bit values int16_t pressure; // 16bit value
void setup(void) { // Set I2C unit to I2C master mode, clock speed 100 kHz and 7 bit addressing // ### configureI2C (I2C_MASTER | CLK_SPEED_100KHZ | ADDRESSING_7BIT); Serial.begin(115200); // Initialize the serial port. Wire.begin(); }
void loop(void) { // Set the target address of the sensor (0x78 = 120dec) // ### I2C_set_target(0x78); // Send start condition for reading from sensor (slave) // ### I2C_send_start_read(); Wire.requestFrom(0x78, 2); // request two bytes from I2C slave address 0x78 // Read first (MSB) data byte and answer with ACK (continue communication) // ### I2C_read (&byte_msb, SEND_ACK); byte_msb = Wire.read(); // Read second (LSB) data byte and answer with NACK (end communication) // ### I2C_read (&byte_lsb, SEND_NACK); byte_lsb = Wire.read(); // Send Stop condition // ### I2C_send_stop(); // Put both values together pressure = ((int16_t)byte_msb << 8) | byte_lsb; //Serial.print("P="); Serial.println (pressure); delay(50); }
|
|
|
|
|
3
|
Using Arduino / Sensors / Re: SensorTechnics i2c Pressure Sensor
|
on: March 27, 2013, 12:40:47 pm
|
Thanks very much for taking the time to reply Pylon, The code makes sense now, but I cant get the device to be recognised on the i2C bus with the 4k7 pullup resistors installed. I've tried the following i2c scanner with a HMC5883L connected onto the bus, which is detected, but not so the SSI device so I guess its a wiring\pull up resistor\address issue? I might have to resort to the analogue pin after all.....  #include <Wire.h> void setup() { Wire.begin(); Serial.begin(115200); Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 120; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknown error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan }
|
|
|
|
|
4
|
Using Arduino / Sensors / SensorTechnics i2c Pressure Sensor
|
on: March 27, 2013, 03:59:14 am
|
Hello All, I'm trying to interface a SensorTechnics pressure sensor to a Mega. The device is a SSIB001GU9AH5 0-1bar stainless steel housed pressure sensor, seemingly ideal (if a little expensive @£80) for what I need. It's i2c capable, but also has a analogue voltage out. I'd like to us the i2c function as (if I can get it working) because ultimately I'd like an array of the units. Attached are the datasheets that I've managed to track down. In one of these there is the code snippet below, which I'm guessing is C ??, but as a Arduio beginner I'm finding it hard to follow/translate this into something I can use on the Arduino. The datasheet also specifies that the device needs 1.5 K Ohm pullup resistors on from the 5v supply as well as 240 Ohm resistors on the SDA\SCL lines My question is two fold: 1) Can anyone help me to understand this code and how to get it working? 2) Does the Arduino already have these pullup resistors on the SDA & SCL lines? I wondered if this might be a device that could be added to the Arduino library.... Many thanks, byte byte_msb, byte_lsb; // 8bit values int16 pressure; // 16bit value // Set I2C unit to I2C master mode, clock speed 100 kHz and 7 bit addressing configureI2C (I2C_MASTER | CLK_SPEED_100KHZ | ADDRESSING_7BIT); // Set the target address of the sensor (0x78 = 120dec) I2C_set_target(0x78); // Send start condition for reading from sensor (slave) I2C_send_start_read(); // Read first (MSB) data byte and answer with ACK (continue communication) I2C_read (&byte_msb, SEND_ACK); // Read second (LSB) data byte and answer with NACK (end communication) I2C_read (&byte_lsb, SEND_NACK); // Send Stop condition I2C_send_stop(); // Put both values together pressure = ((int16)byte_msb << 8) | byte_lsb;
|
|
|
|
|
6
|
Using Arduino / Sensors / Re: Current Sensor ACS714 Wandering Values
|
on: February 20, 2013, 07:36:29 am
|
|
Erdin,
Many thanks, that did the trick. I still have a lot to learn about data types in this language, I'm more used to Visual Studio where things seems a little more straightforward...!
I would have replied earlier but we seem to have lost the forum for a day?
Thanks
|
|
|
|
|
7
|
Using Arduino / Sensors / Current Sensor ACS714 Wandering Values
|
on: February 19, 2013, 06:15:48 am
|
|
Hello everyone,
My first post & and I'm a newbie to Arduino so forgive me if I'm being a bit stupid. I've hooked up a ACS714 (-30A to +30A), a RTC and SD card onto my MEGA (also fitted with Ethernet Shield but removing it makes no difference) but am a bit perplexed as to why, with nothing connected, the sensorValue wanders around from about 506 to 511. I was expected a little fluctuation but around 0.4A seems a lot. I have my ACS board connected to my MEGA as follows:
OUT: A0 Vcc: 5v GND: GND
Should I be using a resistor anywhere? Is there a reference GND I should be using? and finally do I have my maths right for calculating the mA readings - as hunting around the internet there seems to be several ways of doing this.
Any advice gratefully received...
Here's my code:
#include <LiquidCrystal.h> //For the LCD #include <RTClib.h>// For the RTC #include <Wire.h> //For I2C comms #include <SdFat.h> // Include the standard SD card library
SdFat sd; //alias for the SD library SdFile DataFile; //alias for the datalog file const int chipSelect = 53; //Initialise the SD card outputs on the Arduino. Mega = 53
// initialize the LCD library with the numbers of the interface pins. You can use any (but wire to those specified obviously!) LiquidCrystal lcd(22, 23, 24, 25, 26, 27); //LCD pins RS(4), DB4(11), DB5(12), DB6(13), DB7(14)
RTC_DS1307 RTC; //Initialise the RTC
int analogInPin = A0; // Analog input pin that the carrier board OUT is connected to int sensorValue = 0; // value read from the carrier board int outputValue = 0; // output in milliamps String TimeString=""; //Used to concatenate the time & date string int lastTime = -1; //Used to set a time interval int led = 13;//LED to show logging
void setup() { Serial.begin(9600); // initialize serial communications at 9600 bps: lcd.begin(20, 4);// LCD set up. Set the LCD's number of columns and rows: Wire.begin();//set off the I2C comand RTC.begin(); //Start the RTC //RTC.adjust(DateTime(__DATE__, __TIME__)); //Running this sets the RTC Clock via the controller PC pinMode(chipSelect, OUTPUT); //Set SD Chip Select pin on the Arduino as output (even if not using this function) pinMode(led, OUTPUT); }
void loop() {
{digitalWrite(led, LOW);} // turn the LED off by making the voltage LOW delay(500); DateTime now = RTC.now(); //Get the Time int time = now.minute();
// read the analog in value: sensorValue = analogRead(analogInPin); // convert to milli amps outputValue = ((long)sensorValue - 512 ) * 73.982L; //outputValue = ((long)sensorValue - 512 ) * 234375 / 4000000; //outputValue = ( ((long)sensorValue * 5000 / 1024) - 2500 ) * 1000 / 66; /* Analog read produces a value of 0-1023, equating to 0v to 5v. With a sensitivity of 66 mV per A the optimized -30 to 30 range would be (Vcc/2)-1.98V to (Vcc/2)+1.98V (0.52V to 4.48V). That's something like .073982 A per step. 73,982 microamps per step. */
// lcd.clear(); lcd.setCursor(0,0); lcd.print(TimeString); lcd.setCursor(0,1); lcd.print(sensorValue); lcd.setCursor(0,2); lcd.print(outputValue);
if (abs(time - lastTime) >= 1) { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
//create the time string TimeString=String(now.day(),DEC) + "/" + String(now.month(),DEC) + "/" + String(now.year(),DEC) + " " + String(now.hour(),DEC) + ":" + String(now.minute(),DEC) + ":" + String(now.second(),DEC); // print the results to the serial monitor: /* Serial.print(TimeString); Serial.print("Sensor Count (0-1023)= " ); Serial.print(sensorValue); Serial.print("\t Current (ma) = "); Serial.println(outputValue); */
// Initialize SdFat or print a detailed error message and halt // Use half speed like the native library. // change to SPI_FULL_SPEED for more performance. if (!sd.begin(chipSelect, SPI_QUARTER_SPEED)) sd.initErrorHalt();
// open the file for write at end like the Native SD library if (!DataFile.open("ampleak.txt", O_RDWR | O_CREAT | O_AT_END)) sd.errorHalt("ERROR opening ampleak.txt for write!");
// if the file opened okay, write to it: Serial.println("Writing " + TimeString + "," + String(sensorValue) + + "," + String(outputValue) + " to ampleak.txt..."); lastTime = time; DataFile.println(TimeString + "," + String(sensorValue) + "," + String(outputValue));
delay(500); DataFile.close();// close the file to complete the write process:
} }
|
|
|
|
|