Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: python
python: 2.7
install:
- python setup.py install
script:
- flake8 --version
- flake8 --ignore=E501 Adafruit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import time
import smbus
from Adafruit_I2C import Adafruit_I2C
from Adafruit.I2C import Adafruit_I2C

# ===========================================================================
# ADS1x15 Class
Expand Down
1 change: 1 addition & 0 deletions Adafruit/ADS1x15/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .Adafruit_ADS1x15 import ADS1x15
34 changes: 34 additions & 0 deletions Adafruit/ADS1x15/ads1x15_ex_comparator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/python

import time, signal, sys
from Adafruit.ADS1x15 import ADS1x15

def signal_handler(signal, frame):
print 'You pressed Ctrl+C!'
print adc.getLastConversionResults()/1000.0
adc.stopContinuousConversion()
sys.exit(0)

def main():
signal.signal(signal.SIGINT, signal_handler)
# Print 'Press Ctrl+C to exit'

ADS1015 = 0x00 # 12-bit ADC
ADS1115 = 0x01 # 16-bit ADC

# Initialise the ADC using the default mode (use default I2C address)
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
adc = ADS1x15(ic=ADS1115)

# start comparator on channel 2 with a thresholdHigh=200mV and low=100mV
# in traditional mode, non-latching, +/-1.024V and 250sps
adc.startSingleEndedComparator(2, 200, 100, pga=1024, sps=250, activeLow=True, traditionalMode=True, latching=False, numReadings=1)

while True:
print adc.getLastConversionResults()/1000.0
time.sleep(0.25)

#time.sleep(0.1)

if __name__ == '__main__':
main()
32 changes: 32 additions & 0 deletions Adafruit/ADS1x15/ads1x15_ex_differential.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python

import time, signal, sys
from Adafruit.ADS1x15 import ADS1x15

def signal_handler(signal, frame):
#print 'You pressed Ctrl+C!'
sys.exit(0)

def main():
signal.signal(signal.SIGINT, signal_handler)
#print 'Press Ctrl+C to exit'

ADS1015 = 0x00 # 12-bit ADC
ADS1115 = 0x01 # 16-bit ADC

# Initialise the ADC using the default mode (use default I2C address)
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
adc = ADS1x15(ic=ADS1115)

# Read channels 2 and 3 in single-ended mode, at +/-4.096V and 250sps
volts2 = adc.readADCSingleEnded(2, 4096, 250)/1000.0
volts3 = adc.readADCSingleEnded(3, 4096, 250)/1000.0

# Now do a differential reading of channels 2 and 3
voltsdiff = adc.readADCDifferential23(4096, 250)/1000.0

# Display the two different reading for comparison purposes
print "%.8f %.8f %.8f %.8f" % (volts2, volts3, volts3-volts2, -voltsdiff)

if __name__ == '__main__':
main()
48 changes: 48 additions & 0 deletions Adafruit/ADS1x15/ads1x15_ex_singleended.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python

import time, signal, sys
from Adafruit.ADS1x15 import ADS1x15

def signal_handler(signal, frame):
print 'You pressed Ctrl+C!'
sys.exit(0)

def main():
signal.signal(signal.SIGINT, signal_handler)
#print 'Press Ctrl+C to exit'

ADS1015 = 0x00 # 12-bit ADC
ADS1115 = 0x01 # 16-bit ADC

# Select the gain
# gain = 6144 # +/- 6.144V
gain = 4096 # +/- 4.096V
# gain = 2048 # +/- 2.048V
# gain = 1024 # +/- 1.024V
# gain = 512 # +/- 0.512V
# gain = 256 # +/- 0.256V

# Select the sample rate
# sps = 8 # 8 samples per second
# sps = 16 # 16 samples per second
# sps = 32 # 32 samples per second
# sps = 64 # 64 samples per second
# sps = 128 # 128 samples per second
sps = 250 # 250 samples per second
# sps = 475 # 475 samples per second
# sps = 860 # 860 samples per second

# Initialise the ADC using the default mode (use default I2C address)
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
adc = ADS1x15(ic=ADS1115)

# Read channel 0 in single-ended mode using the settings above
volts = adc.readADCSingleEnded(0, gain, sps) / 1000

# To read channel 3 in single-ended mode, +/- 1.024V, 860 sps use:
# volts = adc.readADCSingleEnded(3, 1024, 860)

print "%.6f" % (volts)

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from Adafruit_I2C import Adafruit_I2C
from Adafruit.I2C import Adafruit_I2C


class Adafruit_ADXL345(Adafruit_I2C):
Expand Down Expand Up @@ -100,10 +100,8 @@ def read(self):
res.append(g)
return res


# Simple example prints accelerometer data once per second:
if __name__ == '__main__':

def main():
"""Simple example prints accelerometer data once per second:"""
from time import sleep

accel = Adafruit_ADXL345()
Expand All @@ -112,3 +110,6 @@ def read(self):
while True:
print accel.read()
sleep(1) # Output is fun to watch if this is commented out

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions Adafruit/ADXL345/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .Adafruit_ADXL345 import Adafruit_ADXL345
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python

import time
from Adafruit_I2C import Adafruit_I2C
from Adafruit.I2C import Adafruit_I2C

# ===========================================================================
# BMP085 Class
Expand Down
39 changes: 39 additions & 0 deletions Adafruit/BMP085/Adafruit_BMP085_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python

from Adafruit.BMP085 import BMP085

def main():
# ===========================================================================
# Example Code
# ===========================================================================

# Initialise the BMP085 and use STANDARD mode (default value)
# bmp = BMP085(0x77, debug=True)
bmp = BMP085(0x77)

# To specify a different operating mode, uncomment one of the following:
# bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode
# bmp = BMP085(0x77, 1) # STANDARD Mode
# bmp = BMP085(0x77, 2) # HIRES Mode
# bmp = BMP085(0x77, 3) # ULTRAHIRES Mode

temp = bmp.readTemperature()

# Read the current barometric pressure level
pressure = bmp.readPressure()

# To calculate altitude based on an estimated mean sea level pressure
# (1013.25 hPa) call the function as follows, but this won't be very accurate
altitude = bmp.readAltitude()

# To specify a more accurate altitude, enter the correct mean sea level
# pressure level. For example, if the current pressure level is 1023.50 hPa
# enter 102350 since we include two decimal places in the integer value
# altitude = bmp.readAltitude(102350)

print "Temperature: %.2f C" % temp
print "Pressure: %.2f hPa" % (pressure / 100.0)
print "Altitude: %.2f" % altitude

if __name__ == '__main__':
main()
73 changes: 73 additions & 0 deletions Adafruit/BMP085/Adafruit_BMP085_googledocs_ex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/python

import sys
import time
import datetime
import gspread
from Adafruit.BMP085 import BMP085

def main():
# ===========================================================================
# Google Account Details
# ===========================================================================

# Account details for google docs
email = 'you@somewhere.com'
password = '$hhh!'
spreadsheet = 'SpreadsheetName'

# ===========================================================================
# Example Code
# ===========================================================================

# Initialise the BMP085 and use STANDARD mode (default value)
# bmp = BMP085(0x77, debug=True)
bmp = BMP085(0x77)

# To specify a different operating mode, uncomment one of the following:
# bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode
# bmp = BMP085(0x77, 1) # STANDARD Mode
# bmp = BMP085(0x77, 2) # HIRES Mode
# bmp = BMP085(0x77, 3) # ULTRAHIRES Mode

# Login with your Google account
try:
gc = gspread.login(email, password)
except:
print "Unable to log in. Check your email address/password"
sys.exit()

# Open a worksheet from your spreadsheet using the filename
try:
worksheet = gc.open(spreadsheet).sheet1
# Alternatively, open a spreadsheet using the spreadsheet's key
# worksheet = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE')
except:
print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet
sys.exit()

# Continuously append data
while(True):
temp = bmp.readTemperature()
pressure = bmp.readPressure()
altitude = bmp.readAltitude()

print "Temperature: %.2f C" % temp
print "Pressure: %.2f hPa" % (pressure / 100.0)
print "Altitude: %.2f" % altitude

# Append the data in the spreadsheet, including a timestamp
try:
values = [datetime.datetime.now(), temp, pressure, altitude]
worksheet.append_row(values)
except:
print "Unable to append data. Check your connection?"
sys.exit()

# Wait 5 seconds before continuing
print "Wrote a row to %s" % spreadsheet
time.sleep(5)

if __name__ == '__main__':
main()

1 change: 1 addition & 0 deletions Adafruit/BMP085/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .Adafruit_BMP085 import BMP085
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ def message(self, text):
else:
self.write4bits(ord(char), True)


if __name__ == '__main__':
def main():
lcd = Adafruit_CharLCD()
lcd.clear()
lcd.message(" Adafruit 16x2\n Standard LCD")

if __name__ == '__main__':
main()
29 changes: 29 additions & 0 deletions Adafruit/CharLCD/Adafruit_CharLCD_IPclock_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python

from Adafruit.CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime


def run_cmd(cmd):
p = Popen(cmd, shell=True, stdout=PIPE)
output = p.communicate()[0]
return output

def main():
lcd = Adafruit_CharLCD()

cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"

lcd.begin(16, 1)

while 1:
lcd.clear()
ipaddr = run_cmd(cmd)
lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n'))
lcd.message('IP %s' % (ipaddr))
sleep(2)

if __name__ == '__main__':
main()
22 changes: 22 additions & 0 deletions Adafruit/CharLCD/LCD_MCP230XX_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python
# Example script to show usage of MCP230xx GPIO extender to drive character LCD.

from Adafruit.CharLCD import Adafruit_CharLCD
from Adafruit.MCP230xx import MCP230XX_GPIO

def main():
bus = 1 # Note you need to change the bus number to 0 if running on a revision 1 Raspberry Pi.
address = 0x20 # I2C address of the MCP230xx chip.
gpio_count = 8 # Number of GPIOs exposed by the MCP230xx chip, should be 8 or 16 depending on chip.

# Create MCP230xx GPIO adapter.
mcp = MCP230XX_GPIO(bus, address, gpio_count)

# Create LCD, passing in MCP GPIO adapter.
lcd = Adafruit_CharLCD(pin_rs=1, pin_e=2, pins_db=[3,4,5,6], GPIO=mcp)

lcd.clear()
lcd.message(" Adafruit 16x2\n Standard LCD")

if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions Adafruit/CharLCD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .Adafruit_CharLCD import Adafruit_CharLCD
from .Adafruit_MCP230xx import MCP230XX_GPIO
Loading