Connecting The BMP085 In Arduino With Python Coding

Introduction

In this article I will explain about connecting the BMP085 in Arduino and Python. In Arduino it will be used to see the temperature measurement in the Serial monitor. But in Python it will display in the run module.
 
Parts Of Lists

HardWareParts
  • Arduino Uno
  • BMP085
  • Hook up wires
  • Bread Board.
Software Required
  • Arduino IDE 
  • Python 2.7.11
Connection

Connection From ArduinoUno To BMPO85 Sensor

 Sensor  Board
 Gnd  Gnd
 Vin  5v
 SDA  A3
 SCL  A4

Progarmming

Program Of Arduino
  1. #include "Wire.h"    // imports the wire library for talking over I2C   
  2. #include "Adafruit_BMP085.h"  // import the Pressure Sensor Library  
  3. Adafruit_BMP085 mySensor;  // create sensor object called mySensor  
  4.    
  5. float tempC;  // Variable for holding temp in C  
  6. float tempF;  // Variable for holding temp in F  
  7. float pressure; //Variable for holding pressure reading  
  8.    
  9. void setup(){  
  10. Serial.begin(9600); //turn on serial monitor  
  11. mySensor.begin();   //initialize mySensor  
  12. }  
  13.    
  14. void loop() {  
  15. tempC = mySensor.readTemperature(); //  Read Temperature  
  16. tempF = tempC*1.8 + 32.; // Convert degrees C to F  
  17. pressure=mySensor.readPressure(); //Read Pressure  
  18.    
  19. Serial.print("The Temp is: "); //Print Your results  
  20. Serial.print(tempF);  
  21. Serial.println(" degrees F");  
  22. Serial.print("The Pressure is: ");  
  23. Serial.print(pressure);  
  24. Serial.println(" Pa.");  
  25. Serial.println("");  
  26. delay(250); //Pause between readings.  
  27. }   
Program Of Python
  1. import serial # import Serial Library  
  2. import numpy  # Import numpy  
  3. import matplotlib.pyplot as plt #import matplotlib library  
  4. from drawnow import *  
  5.    
  6. tempF= []  
  7. pressure=[]  
  8. arduinoData = serial.Serial('com11', 115200) #Creating our serial object named arduinoData  
  9. plt.ion() #Tell matplotlib you want interactive mode to plot live data  
  10. cnt=0  
  11.    
  12. def makeFig(): #Create a function that makes our desired plot  
  13.     plt.ylim(80,90)                                 #Set y min and max values  
  14.     plt.title('My Live Streaming Sensor Data')      #Plot the title  
  15.     plt.grid(True)                                  #Turn the grid on  
  16.     plt.ylabel('Temp F')                            #Set ylabels  
  17.     plt.plot(tempF, 'ro-', label='Degrees F')       #plot the temperature  
  18.     plt.legend(loc='upper left')                    #plot the legend  
  19.     plt2=plt.twinx()                                #Create a second y axis  
  20.     plt.ylim(93450,93525)                           #Set limits of second y axis- adjust to readings you are getting  
  21.     plt2.plot(pressure, 'b^-', label='Pressure (Pa)') #plot pressure data  
  22.     plt2.set_ylabel('Pressrue (Pa)')                    #label second y axis  
  23.     plt2.ticklabel_format(useOffset=False)           #Force matplotlib to NOT autoscale y axis  
  24.     plt2.legend(loc='upper right')                  #plot the legend  
  25.       
  26.    
  27. while True: # While loop that loops forever  
  28.     while (arduinoData.inWaiting()==0): #Wait here until there is data  
  29.         pass #do nothing  
  30.     arduinoString = arduinoData.readline() #read the line of text from the serial port  
  31.     dataArray = arduinoString.split(',')   #Split it into an array called dataArray  
  32.     temp = float( dataArray[0])            #Convert first element to floating number and put in temp  
  33.     P =    float( dataArray[1])            #Convert second element to floating number and put in P  
  34.     tempF.append(temp)                     #Build our tempF array by appending temp readings  
  35.     pressure.append(P)                     #Building our pressure array by appending P readings  
  36.     drawnow(makeFig)                       #Call drawnow to update our live graph  
  37.     plt.pause(.000001)                     #Pause Briefly. Important to keep drawnow from crashing  
  38.     cnt=cnt+1  
  39.     if(cnt>50):                            #If you have 50 or more points, delete the first one from the array  
  40.         tempF.pop(0)                       #This allows us to just see the last 50 data points  
  41.         pressure.pop(0)  
Explanation

In this article  I  will explain about how the  BMP085 can be used to see the temperature level. In Arduino it will be displayed in the serial monitor but in Python I have used the matlab plot.

The matplot software is used to display the higher and lower levels of the temperature. Click the software below and download the software.
http:/pip.pypa.io/en/learning/installing

In Python write the code and click the run module or f5 to see the output.

In Python the data and the code will be read from Arduino because we have given the Arduino port in Python.The matlab plot can plot the temperature in the current level.

Output

 
Figure 1 : Output