Show Posts
|
|
Pages: 1 [2] 3 4 ... 6
|
|
17
|
Using Arduino / Programming Questions / ADS1114 convert bi-directional output to positive
|
on: March 31, 2013, 11:53:17 pm
|
Hi. Another question in my quest to learn. I am using an ADS1114 16 bit a/d converter and the Adafruit ADS1115 library https://github.com/adafruit/Adafruit_ADS1X15although I suppose this is common with many ADC's. My sensor has a total output from 0.3v to 1.4v so only approx 1v full scale. The ads1114 is giving me approximately -6000 to 6000 as an output which is about right I guess, 12000 counts for a 1v input. My question is how do convert the input into a positive ONLY value in the most efficient way for processing time. I know i could just add 7000 to the value and always have it positive but I am sure there is a more efficient way done by the pro's?
|
|
|
|
|
18
|
Using Arduino / Programming Questions / Re: AttachInterrupt? issues
|
on: March 30, 2013, 11:06:35 pm
|
|
Thank you John. Thats what I suspected. So to confirm, the only way to return to a Menu type function that will need to display options and accept inputs will be like what I have done in the main loop() ? minus the delays of course, those are mainly just for testing the structure.
|
|
|
|
|
19
|
Using Arduino / Programming Questions / AttachInterrupt? issues
|
on: March 30, 2013, 07:14:29 pm
|
I am setting up the structure for a new application and trying to use the hardware interrupt, but I must be misunderstanding the use case or something else. Basically, after a welcome message the device will detect the sensor filed size and start reading the sensor continuously which it does. I want to use a button to interrupt this and go to a Menu function that may offer choices like calibrate etc. I can do this with a While statement as shown and it works but this means it polls the button every loop. If I hit the Interrupt button, everything stops and it just hangs. I have read that there can be no Print or delays in the interrupt which I removed. Right now the fMenu() function only calls another function just for testing. Any help appreciated. int sensorReading;
int sensorLevel; void fMenu() { // Serial.println("This is the Menu Function"); //delay (200); //Serial.println("waiting"); // while (digitalRead (5)== HIGH); //delay (1000); fFieldChoice(); } //=========================================================================== void setup() { // setup serial - diagnostics - port Serial.begin(9600); analogReference(INTERNAL); pinMode(5, INPUT); pinMode (6, INPUT); // measure sensor for (int i=0; i<10; i++) { sensorReading = analogRead(A0); // Range : 0..1024 } // Button on pin 2, Int0 attachInterrupt(0, fMenu, RISING);
//welcome message
Serial.println("Hello"); //Set up Switch Statement in fFieldChoice. if(sensorReading < 299) {sensorLevel = 1;} else {sensorLevel = 2;} Serial.println("Press FUNCTION key to start");
Serial.println("waiting"); while (digitalRead (5)== LOW); delay (1000); fFieldChoice(); } //============================================================================== void loop() { while (digitalRead (6)== LOW){ sensorReading = analogRead(A0); // Range : 0..1024 Serial.println(sensorReading); delay(100); } fMenu(); } //=============================================================================== void fCalibrate() { Serial.println("This is the Calibrate Function"); delay (200); } //================================================================================= void MultiMap() { Serial.println("This is the MultiMap Function"); delay(200); } //=================================================================================
//================================================================================= void fFieldChoice() { Serial.println("This is the FieldChoice Function"); delay (200); switch (sensorLevel) { case 1: Serial.println("sensorlevel = 1"); Serial.println("Big field detected"); delay (2000); break; case 2: Serial.println("sensorlevel = 2"); Serial.println("Small field deteted"); delay (2000); break; } } //==================================================================================
|
|
|
|
|
21
|
Using Arduino / Networking, Protocols, and Devices / Re: Another I2C question
|
on: March 05, 2013, 09:45:59 pm
|
|
Thank you. That was going to be my next question. Although the sensor is powered off 5v, the output is only between 0 and 2.5v. Before using the ADS I was using the internal 1.1v reference to improve reolution a little. So in this case I would power both off the 3.3V rail? The Atmega328 is still using 5v so that is ok, correct?
Thanks again for your time and input.
|
|
|
|
|
22
|
Using Arduino / Networking, Protocols, and Devices / Another I2C question
|
on: March 05, 2013, 05:00:51 pm
|
|
I have 2 devices that will use the I2C bus talking to an UNO. I understand that I need 1 set of Pullup resistors between the SDA/SCL lines and VCC. My problem is the 2 devices have different supply voltages. One is an LCD display that only has 3.3v supply and the other is ADS1114 A-D converter that will read a sensor powered off 5v, so I intended to use a 5V supply for this part. Can these 2 communicate on the same I2C bus? Where do I connect the pullup resistors to? 5v or 3.3v?
Any help would be appreciated.
|
|
|
|
|
24
|
Using Arduino / Networking, Protocols, and Devices / Re: I2C help needed
|
on: March 04, 2013, 01:17:39 am
|
So I gather you are getting valid readings, and your question is "why am I getting valid readings?"
Hi Nick. Yes exactly. At least it appears i am getting valid readings. I just dont understand that if the data is contained in 254 and 255, why it only works when I call 255? I am not calling 254 at all but it seems to be getting the data from it. Here is the HEX output with the bits shifted 6 0, E 0, 34 1, 6C 3, C7 3, F8 5, 153 6, 1B6 9, 242 C, 312 F, 3DD 12, 483 15, 543 16, 5A1 17, 5D6 1A, 699 1B, 6F7 1F, 7C9 23, 8D4 25, 964 28, A29 2A, AA7 2D, B7C 33, CCC 35, D70 39, E46 3D, F4E 41, 1065 45, 1144 4A, 1292 4E, 139F 55, 1575 5E, 17BF 63, 18CA 6C, 1B06 72, 1C93 78, 1E2B 78, 1E2B 78, 1E17 82, 2083 8D, 2378 96, 259B A1, 2844 AA, 2A82 B0, 2C00 B5, 2D58 BD, 2F40 C8, 322F D4, 3518 E1, 386C ED, 3B4A F3, 3CD7 F4, 3D10 F4, 3D0E F9, 3E4D ' Here is the decimal output 0, 18 2, 130 8, 522 15, 975 24, 1582 34, 2237 45, 2936 58, 3723 72, 4640 89, 5730 98, 6315 112, 7223 128, 8231 132, 8470 132, 8471 139, 8936 153, 9849 170, 10894 181, 11597 190, 12190 200, 12846 215, 13766 225, 14435 228, 14642 233, 14968 240, 15399 247, 15836 251, 16116 255, 16347 with this code #include <Wire.h>
void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial communication at 9600bps }
unsigned int reading = 0; int reading1 = 0; void loop() { Wire.beginTransmission(66); // transmit to device #66 Wire.write(byte(255)); // sets register pointer to echo #1 register Wire.endTransmission(); // stop transmitting
// step 4: request reading from sensor Wire.requestFrom(66, 2); // request 2 bytes from slave device #112
// step 5: receive reading from sensor if(2 <= Wire.available()) // if two bytes were received { reading = Wire.read(); // receive high byte (overwrites previous reading) Serial.print(reading); // print the reading Serial.print(", "); reading = reading << 6; // shift high byte to be high 8 bits reading |= Wire.read(); // receive low byte as lower 8 bits Serial.println(reading); // print the reading }
delay(300); // wait a bit since people have to read the output :) }
|
|
|
|
|
25
|
Using Arduino / Networking, Protocols, and Devices / Re: I2C help needed
|
on: March 04, 2013, 12:57:00 am
|
You may need to be shifting the first byte you read by 8 bits, not 6 bits, If i do that then the output goes to 16-bit (0 - 65535) which is clearly incorrect. I'm a bit confused about the relationship between the numbers 66 and 112. As I said above, the 112 is part of the comments from the arduino code example, I changed the address to 66
|
|
|
|
|
26
|
Using Arduino / Networking, Protocols, and Devices / Re: I2C help needed
|
on: March 04, 2013, 12:31:01 am
|
|
I really do not know, All i can tell you is that it says not found. If I try the scanner with an LCD I have i see it operates correctly and finds the LCD Address. On the data sheet is says you can program the address but it only allows 1 time. I have not done this as yet so is it possible that it will not answer an inquiry (Whatever the scanner is sending) but will respond to a write command if the correct default address is used?
|
|
|
|
|
27
|
Using Arduino / Networking, Protocols, and Devices / Re: I2C help needed
|
on: March 03, 2013, 03:24:38 pm
|
Is it 66 or 112?
Sorry, the comments were from original code. It is 66 that can communicate with. I have the manual bits set to A1=0 and A2 = 1 so according to the data sheet the defalt address is 10000 plus A2 A1 which is 1000010 = 66 and this works. I tried the I2C scanner but it does not find any device. The datasheet doesn't show the ability to do sequential reads. I would read the two registers separately:
When I try that code, it seems to be random data that doesnt change logically when I rotate the device. 3543 407 2826 2425 2930 2610 2482 2610 3183 1571 1630 990 1758 1306 656 716 2827 2186 767 53 3891 3699 3571 807 1058 801 736 601 538 730 794 602 538 Using my posted code I get good data smoothly changing as i rotate the device 14 74 76 75 220 579 801 1160 1473 1691 2005 2256 2427 2663 2832 3024 3251 3520 4038 4303 4624 4914 5220 5922 6707 7407 7946 8529 9568 10686 11401 12014 12632 12637 12640 12718 13130 13520 14093 14244 14463 14802 14697 14698 I am just trying to understand why I only get this result when reading register 255 with 2 bytes? How does it get the readings from 254 in there.
|
|
|
|
|
30
|
Using Arduino / Networking, Protocols, and Devices / I2C help needed
|
on: March 02, 2013, 07:07:38 pm
|
I am tring to understand and learn I2C better and in doing so have come accross the following question. I am using part of the I2C example code on the Arduino Learning website for the WIre Library SFR_Ranger reader. My particular I2C device has a 14-bit reolution and the data is stored in Registers 254 and 255. In 255 the bits 6 and 7 are not used, hence the 14 bits. Question 1) I am confused about why I read register 255 in the code with 2 bytes, I would have thought it should read register 254 first but that just gives garbage. Question 2) In the statement reading = reading << 6; // shift high byte to be high 8 bits I read the correct 14 bit data with range of 0 - 16383. If I change the 6 to an 8 as in original code, which i understand is 16 bit, the output range is 0 - 65535. While I assume this is just the 14 bit data interpolated into the 16 bit range so resolution would not be any greater, My question is how does it do this? It is now reading 8 bits from each register but 2 of the bits are unused in the first register. The answer is probably staring me in the face but i dont get it. here is the working code. #include <Wire.h>
void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial communication at 9600bps }
unsigned int reading = 0;
void loop() { Wire.beginTransmission(66); // transmit to device #112 Wire.write(byte(255)); // sets register pointer to echo #1 register (0x02) Wire.endTransmission(); // stop transmitting
// step 4: request reading from sensor Wire.requestFrom(66, 2); // request 2 bytes from slave device #112
// step 5: receive reading from sensor if(2 <= Wire.available()) // if two bytes were received { reading = Wire.read(); // receive high byte (overwrites previous reading) reading = reading << 6; // shift high byte to be high 8 bits reading |= Wire.read(); // receive low byte as lower 8 bits Serial.println(reading); // print the reading }
delay(300); // wait a bit since people have to read the output :) }
|
|
|
|
|