C 1
Adc - lcd - i2c By tecan on 27th March 2018 12:02:09 AM
  1. /* YourDuino.com Example Software Sketch
  2.  16 character 2 line I2C Display
  3.  Backpack Interface labelled "A0 A1 A2" at lower right.
  4.  ..and
  5.  Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"
  6.  MOST use address 0x27, a FEW use 0x3F
  7.  terry@yourduino.com
  8. https://arduino-info.wikispaces.com/LCD-Blue-I2C?responseToken=04692e995ead61617f2cdbd47f1dabcb6
  9.  0x20 i2c expansion 9 pin
  10.  0x48 adc
  11.  0x27 lcd
  12.  
  13.  */
  14. /*-----( Import needed libraries )-----*/
  15. #include <Wire.h>  // Comes with Arduino IDE
  16. // Get the LCD I2C Library here:
  17. // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
  18. // Move any other LCD libraries to another folder or delete them
  19. // See Library "Docs" folder for possible commands etc.
  20. #include <LiquidCrystal_I2C.h>
  21. #include "PCF8574.h"
  22.  
  23.  
  24. #include <Adafruit_ADS1015.h>
  25. Adafruit_ADS1115 ads(0x48);
  26. float Voltage = 0.0;
  27.  
  28. // Set i2c address
  29. PCF8574 pcf8574(0x20);
  30.  
  31. /*-----( Declare Constants )-----*/
  32. /*-----( Declare objects )-----*/
  33. // set the LCD address to 0x27 for a 16 chars 2 line display
  34. // A FEW use address 0x3F
  35. // Set the pins on the I2C chip used for LCD connections:
  36. //                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
  37. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
  38.  
  39. /*-----( Declare Variables )-----*/
  40. //NONE
  41.  
  42. void setup()   /*----( SETUP: RUNS ONCE )----*/
  43. {
  44.   Serial.begin(115200);  // Used to type in characters
  45.   pcf8574.pinMode(P0, OUTPUT);
  46.   pcf8574.pinMode(P1, INPUT);
  47.   pcf8574.begin();
  48.   lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight
  49.  
  50. // ------- Quick 3 blinks of backlight  -------------
  51.   for(int i = 0; i< 3; i++)
  52.   {
  53.     lcd.backlight();
  54.     delay(250);
  55.     lcd.noBacklight();
  56.     delay(250);
  57.   }
  58.   lcd.backlight(); // finish with backlight on  
  59.  
  60. //-------- Write characters on the display ------------------
  61. // NOTE: Cursor Position: (CHAR, LINE) start at 0  
  62.   lcd.setCursor(0,0); //Start at character 4 on line 0
  63.   lcd.print("Hello, world!");
  64.   delay(1000);
  65.   lcd.setCursor(0,1);
  66.   lcd.print("HI!YourDuino.com");
  67.   delay(8000);  
  68.  
  69. // Wait and then tell user they can start the Serial Monitor and type in characters to
  70. // Display. (Set Serial Monitor option to "No Line Ending")
  71.   lcd.clear();
  72.   lcd.setCursor(0,0); //Start at character 0 on line 0
  73.   lcd.print("Use Serial Mon");
  74.   lcd.setCursor(0,1);
  75.   lcd.print("Type to display");  
  76.  
  77.  
  78. }/*--(end setup )---*/
  79.  
  80.  
  81. void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
  82. {
  83.   {
  84.     // when characters arrive over the serial port...
  85.     if (Serial.available()) {
  86.       // wait a bit for the entire message to arrive
  87.       delay(100);
  88.       // clear the screen
  89.       lcd.clear();
  90.       // read all the available characters
  91.       while (Serial.available() > 0) {
  92.         // display each character to the LCD
  93.         lcd.write(Serial.read());
  94.       }
  95.     }
  96.   }
  97.     int16_t adc0;  // we read from the ADC, we have a sixteen bit integer as a result
  98. int16_t adc1;
  99. int16_t adc2;
  100. int16_t adc3;
  101.   adc0 = ads.readADC_SingleEnded(0);
  102.   adc1 = ads.readADC_SingleEnded(1);
  103.   adc2 = ads.readADC_SingleEnded(2);
  104.   adc3 = ads.readADC_SingleEnded(3);
  105.  
  106.   Voltage = (adc0 * 0.1875)/1000;
  107.    
  108.   Serial.print("AIN0: ");
  109.   Serial.print(adc0);
  110.   Serial.print("\tVoltage: ");
  111.   Serial.println(Voltage, 7);  
  112.   Serial.println();
  113.  
  114.         pcf8574.digitalWrite(P0, HIGH);
  115.         delay(1000);
  116.         pcf8574.digitalWrite(P0, LOW);
  117.         delay(1000);
  118. }/* --(end main loop )-- */
  119.  
  120.  
  121. /* ( THE END ) */

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.