SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By Mee_n_Mac
#169487
If you're still lost and have really given it a try, here's something close to the final answer. I say close as I don't know what you have for an external voltage divider for each voltage, and thus don't know what to use for the ADC gain. I could guess from the comments but I've got to leave something for you to do. :mrgreen:
Code: Select all
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <LiquidCrystal.h>

Adafruit_ADS1015 ads1015;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(void)
{
  Serial.begin(9600);
  lcd.begin(16, 2);
  Serial.println("Hello!");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");
  ads1015.begin();
}

void loop(void)
{
  int chgaReading = ads1015.readADC_SingleEnded(0);
  float chgaVolts = chgaReading * 1.0 / 27.0 ;

  lcd.setCursor(0, 0);
  lcd.print ("+     A");
  lcd.setCursor (1, 0);
  lcd.print(chgaVolts);

  int bavoltReading = ads1015.readADC_SingleEnded(2);
  float bavoltVolts = bavoltReading * 1.0 / 56.0 ;

  lcd.setCursor (9, 0);
  lcd.print ("      V");
  lcd.setCursor (10, 0);
  lcd.print (bavoltVolts);

  delay(1000);
}
I forsee one problem with the way you've got the display written (I copied your code). Think about what might happen if you send 48.125 to the LCD followed by 47.8 in the next loop for the same voltage display. What will show up on the LCD ?
By Newbie10
#169493
Yes, I am still lost.
I started from scratch and copied the (simplified) Adafruit sketch, wiped away the "Hello" stuff and added the basic minimum of my LCD stuff just to get this thing to fly. And yes, I have all 3 ".h" libraries.
Code: Select all
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <LiquidCrystal.h>

Adafruit_ADS1015 ads1015;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(void)
{
  Serial.begin(9600);
  lcd.begin(16, 2);
  
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");
  ads1015.begin();
}

void loop(void)
{
  int chgaReading = ads1015.readADC_SingleEnded(0);
  float chgaVolts = chgaReading * 1.0 / 27.0 ;

  lcd.setCursor(0, 0);
  lcd.print ("+     A");
  lcd.setCursor (1, 0);
  lcd.print(chgaVolts);

  int bavoltReading = ads1015.readADC_SingleEnded(2);
  float bavoltVolts = bavoltReading * 1.0 / 56.0 ;

  lcd.setCursor (9, 0);
  lcd.print ("      V");
  lcd.setCursor (10, 0);
  lcd.print (bavoltVolts);

  delay(1000);
}


Now on my IDE I get error : 'class Adafruit_ADS1015' has no member named 'begin' with "ads1015.begin();" highlighted, copied directly from Adafruit, followed by a few more errors. (I see that they also use "ads.begin()" which gives the same error!)
I am not concerned about voltages for now : all I want is to see the UNO, ADS and LCD running, together. Only then will I worry about details I'm familiar with - I've been in analog industrial electronics long enough. It's the micro's, sketches and C++'s that I can't quite get through my fingers....
By Mee_n_Mac
#169494
If the code I posted just above doesn't compile then you're missing a library. Post a screenshot of your installed ADC library.
See if your Arduino IDE lists the installed ADC library as shown below.
(click on to open)
ADCscreenshot.jpg
You do not have the required permissions to view the files attached to this post.
By Newbie10
#169509
Yup!
You were right. My library (correctly) uploads the "h" file and shows :

#include <Adafruit_ADS1015.h>

as one would expect to be correct but doesn't include the .cpp, etc, which is clearly the Humpty-Dumpty.
On re-reading the arduino/libraries/download/whatever I see that the full shopping basket is necessary and not just the ads1015.h on its own.
Silly of me, yes, but perhaps not clear enough in the soup for us newbies/dummies.
Also had a spot of trauma as the total file could not be saved to Library directly as per Arduino's download library-thing - the red block gave me a long story saying that the file name should not contain numbers, fleas and windscreenwipers. I needed to do the alternative and create a file (which I named Adafruit_ads1015) , move all the necessary files in and THEN pitched it into the cauldron as instructed before it worked.
What's interesting is that my (new) (correct) library file is now at bottom of the list (Sketch / Import Library) in the "Contributed" section and will not upload to a sketch automatically or list in the usual list of libraries - it keeps sucking up the ADS1015 number WITHOUT the shopping basket.
Is this perhaps because I have the existing (naughty) library called "ADS1015" in the main section/list of libraries and that there's conflict?

PS. Don't find any way to edit a previous entries/replies in the forum. Is this normal? Or is there a way one can change a previous entry which I don't know about? minor issue...
By Valen
#169510
Newbie10 wrote:...
PS. Don't find any way to edit a previous entries/replies in the forum. Is this normal? Or is there a way one can change a previous entry which I don't know about? minor issue...
Odd, can't see an edit button either on my posts. Some Sparkfunner must have consumed too much on St. Patrick's Day.

[edit]But on this one I do. Very odd.
By Mee_n_Mac
#169529
Newbie10 wrote:Also had a spot of trauma as the total file could not be saved to Library directly as per Arduino's download library-thing - the red block gave me a long story saying that the file name should not contain numbers, fleas and windscreenwipers. I needed to do the alternative and create a file (which I named Adafruit_ads1015) , move all the necessary files in and THEN pitched it into the cauldron as instructed before it worked.
I thought my post was clear ... yes the folder name must match the filename.h and filename.cpp. It's a mystery why people store the GitHub files the way they do, incompatible with the auto-import function and incompatible w/the Arduino folder&file naming convention (which has been around a long time now).
Newbie10 wrote:What's interesting is that my (new) (correct) library file is now at bottom of the list (Sketch / Import Library) in the "Contributed" section and will not upload to a sketch automatically or list in the usual list of libraries - it keeps sucking up the ADS1015 number WITHOUT the shopping basket.
I'm not sure what you mean by underlined above. For any library you add to your Arduino list of libraries, you'll have to have a #include library_name statement at the top of your sketch in order for it to be used. You can type that in manually or open the IDE w/the sketch you want, and then use the import library tool (that I showed in pic above).
Newbie10 wrote:Is this perhaps because I have the existing (naughty) library called "ADS1015" in the main section/list of libraries and that there's conflict?
Probably. I think it best to keep ones you add separate from the ones that are part of the "Arduino core" because when you upgrade from Arduino 1.0.5 to something else in the future, I don't know what'll happen to that folder. I'm fairly sure the libraries folder in the folder w/my code won't be touched.

So now that the code runs ... does it work ?
By Newbie10
#169567
On re-reading my post it's not very clear that YES, my sketch runs, now that the corrected library is coupled/linked correctly. So thanks for the help - really appreciated.
Regarding the libraries and tying them in, I am still experiencing hassles. The ARDUINO instructions are clear but don't necessarily work with my machine every time - is someone going to hit me for using Linux again?
For any library you add to your Arduino list of libraries, you'll have to have a #include library_name statement at the top of your sketch in order for it to be used. You can type that in manually or open the IDE w/the sketch you want, and then use the import library tool (that I showed in pic above).
Doesn't often work : perhaps my fingers, perhaps Linux, perhaps flaws I don't know about.

I sometimes find that replies/'help' is a bit mis-/disguided - perhaps intentionally or otherwise. I can understand that an Experienced may want One to research/investigate/learn. But sometimes a simple, clear, direct answer helps a lot more.
I for one, would appreciate DIRECT help a lot more, e.g. a straight up-and-down solution given directly in the sketch. It's easy enough to compare previous to corrected to find the answer to mistakes made.

But the long and the short is that my sketch runs thanks to all the help given. Still not perfectly, but now I can fly and correct/modify/add...
And thanks, Valen : I thought the EDIT problem was mine only.