diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..de957f8b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: python +python: 2.7 +install: + - python setup.py install +script: + - flake8 --version + - flake8 --ignore=E501 Adafruit diff --git a/Adafruit_ADS1x15/Adafruit_ADS1x15.py b/Adafruit/ADS1x15/Adafruit_ADS1x15.py similarity index 99% rename from Adafruit_ADS1x15/Adafruit_ADS1x15.py rename to Adafruit/ADS1x15/Adafruit_ADS1x15.py index eb58087d..584ca1f9 100644 --- a/Adafruit_ADS1x15/Adafruit_ADS1x15.py +++ b/Adafruit/ADS1x15/Adafruit_ADS1x15.py @@ -2,7 +2,7 @@ import time import smbus -from Adafruit_I2C import Adafruit_I2C +from Adafruit.I2C import Adafruit_I2C # =========================================================================== # ADS1x15 Class diff --git a/Adafruit/ADS1x15/__init__.py b/Adafruit/ADS1x15/__init__.py new file mode 100644 index 00000000..d45b2009 --- /dev/null +++ b/Adafruit/ADS1x15/__init__.py @@ -0,0 +1 @@ +from .Adafruit_ADS1x15 import ADS1x15 \ No newline at end of file diff --git a/Adafruit/ADS1x15/ads1x15_ex_comparator.py b/Adafruit/ADS1x15/ads1x15_ex_comparator.py new file mode 100644 index 00000000..07df34f4 --- /dev/null +++ b/Adafruit/ADS1x15/ads1x15_ex_comparator.py @@ -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() diff --git a/Adafruit/ADS1x15/ads1x15_ex_differential.py b/Adafruit/ADS1x15/ads1x15_ex_differential.py new file mode 100644 index 00000000..e4f877c9 --- /dev/null +++ b/Adafruit/ADS1x15/ads1x15_ex_differential.py @@ -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() diff --git a/Adafruit/ADS1x15/ads1x15_ex_singleended.py b/Adafruit/ADS1x15/ads1x15_ex_singleended.py new file mode 100644 index 00000000..cd1582b8 --- /dev/null +++ b/Adafruit/ADS1x15/ads1x15_ex_singleended.py @@ -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() diff --git a/Adafruit_ADXL345/Adafruit_ADXL345.py b/Adafruit/ADXL345/Adafruit_ADXL345.py similarity index 96% rename from Adafruit_ADXL345/Adafruit_ADXL345.py rename to Adafruit/ADXL345/Adafruit_ADXL345.py index 50b00abe..f0b9d277 100755 --- a/Adafruit_ADXL345/Adafruit_ADXL345.py +++ b/Adafruit/ADXL345/Adafruit_ADXL345.py @@ -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): @@ -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() @@ -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() diff --git a/Adafruit/ADXL345/__init__.py b/Adafruit/ADXL345/__init__.py new file mode 100644 index 00000000..12eeb1e3 --- /dev/null +++ b/Adafruit/ADXL345/__init__.py @@ -0,0 +1 @@ +from .Adafruit_ADXL345 import Adafruit_ADXL345 \ No newline at end of file diff --git a/Adafruit_BMP085/Adafruit_BMP085.py b/Adafruit/BMP085/Adafruit_BMP085.py similarity index 99% rename from Adafruit_BMP085/Adafruit_BMP085.py rename to Adafruit/BMP085/Adafruit_BMP085.py index e8d0e314..7bc3fd26 100755 --- a/Adafruit_BMP085/Adafruit_BMP085.py +++ b/Adafruit/BMP085/Adafruit_BMP085.py @@ -1,7 +1,7 @@ #!/usr/bin/python import time -from Adafruit_I2C import Adafruit_I2C +from Adafruit.I2C import Adafruit_I2C # =========================================================================== # BMP085 Class diff --git a/Adafruit/BMP085/Adafruit_BMP085_example.py b/Adafruit/BMP085/Adafruit_BMP085_example.py new file mode 100755 index 00000000..d6bf93a9 --- /dev/null +++ b/Adafruit/BMP085/Adafruit_BMP085_example.py @@ -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() diff --git a/Adafruit/BMP085/Adafruit_BMP085_googledocs_ex.py b/Adafruit/BMP085/Adafruit_BMP085_googledocs_ex.py new file mode 100755 index 00000000..7f565217 --- /dev/null +++ b/Adafruit/BMP085/Adafruit_BMP085_googledocs_ex.py @@ -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() + diff --git a/Adafruit_BMP085/DEPRECATED.txt b/Adafruit/BMP085/DEPRECATED.txt similarity index 100% rename from Adafruit_BMP085/DEPRECATED.txt rename to Adafruit/BMP085/DEPRECATED.txt diff --git a/Adafruit/BMP085/__init__.py b/Adafruit/BMP085/__init__.py new file mode 100644 index 00000000..025b55ae --- /dev/null +++ b/Adafruit/BMP085/__init__.py @@ -0,0 +1 @@ +from .Adafruit_BMP085 import BMP085 \ No newline at end of file diff --git a/Adafruit_CharLCD/Adafruit_CharLCD.py b/Adafruit/CharLCD/Adafruit_CharLCD.py similarity index 99% rename from Adafruit_CharLCD/Adafruit_CharLCD.py rename to Adafruit/CharLCD/Adafruit_CharLCD.py index a4bb9a93..4d38ac23 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD.py +++ b/Adafruit/CharLCD/Adafruit_CharLCD.py @@ -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() diff --git a/Adafruit/CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit/CharLCD/Adafruit_CharLCD_IPclock_example.py new file mode 100755 index 00000000..3245d247 --- /dev/null +++ b/Adafruit/CharLCD/Adafruit_CharLCD_IPclock_example.py @@ -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() diff --git a/Adafruit/CharLCD/LCD_MCP230XX_test.py b/Adafruit/CharLCD/LCD_MCP230XX_test.py new file mode 100644 index 00000000..fb4b0a23 --- /dev/null +++ b/Adafruit/CharLCD/LCD_MCP230XX_test.py @@ -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() diff --git a/Adafruit/CharLCD/__init__.py b/Adafruit/CharLCD/__init__.py new file mode 100644 index 00000000..b5325ed0 --- /dev/null +++ b/Adafruit/CharLCD/__init__.py @@ -0,0 +1,2 @@ +from .Adafruit_CharLCD import Adafruit_CharLCD +from .Adafruit_MCP230xx import MCP230XX_GPIO \ No newline at end of file diff --git a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py b/Adafruit/CharLCDPlate/Adafruit_CharLCDPlate.py similarity index 100% rename from Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py rename to Adafruit/CharLCDPlate/Adafruit_CharLCDPlate.py diff --git a/Adafruit/CharLCDPlate/LCDtest.py b/Adafruit/CharLCDPlate/LCDtest.py new file mode 100644 index 00000000..768a3cc5 --- /dev/null +++ b/Adafruit/CharLCDPlate/LCDtest.py @@ -0,0 +1,39 @@ +#!/usr/bin/python + +from time import sleep +from Adafruit.CharLCDPlate import Adafruit_CharLCDPlate + +def main(): + # Initialize the LCD plate. Should auto-detect correct I2C bus. If not, + # pass '0' for early 256 MB Model B boards or '1' for all later versions + lcd = Adafruit_CharLCDPlate() + + # Clear display and show greeting, pause 1 sec + lcd.clear() + lcd.message("Adafruit RGB LCD\nPlate w/Keypad!") + sleep(1) + + # Cycle through backlight colors + col = (lcd.RED , lcd.YELLOW, lcd.GREEN, lcd.TEAL, + lcd.BLUE, lcd.VIOLET, lcd.ON , lcd.OFF) + for c in col: + lcd.backlight(c) + sleep(.5) + + # Poll buttons, display message & set backlight accordingly + btn = ((lcd.LEFT , 'Red Red Wine' , lcd.RED), + (lcd.UP , 'Sita sings\nthe blues' , lcd.BLUE), + (lcd.DOWN , 'I see fields\nof green' , lcd.GREEN), + (lcd.RIGHT , 'Purple mountain\nmajesties', lcd.VIOLET), + (lcd.SELECT, '' , lcd.ON)) + prev = -1 + while True: + for b in btn: + if lcd.buttonPressed(b[0]): + if b is not prev: + lcd.clear() + lcd.message(b[1]) + lcd.backlight(b[2]) + prev = b + break + diff --git a/Adafruit_CharLCDPlate/LCDtest_20x4.py b/Adafruit/CharLCDPlate/LCDtest_20x4.py similarity index 100% rename from Adafruit_CharLCDPlate/LCDtest_20x4.py rename to Adafruit/CharLCDPlate/LCDtest_20x4.py diff --git a/Adafruit/CharLCDPlate/__init__.py b/Adafruit/CharLCDPlate/__init__.py new file mode 100644 index 00000000..5bbdecec --- /dev/null +++ b/Adafruit/CharLCDPlate/__init__.py @@ -0,0 +1 @@ +from .Adafruit_CharLCDPlate import Adafruit_CharLCDPlate \ No newline at end of file diff --git a/Adafruit_DHT_Driver/Adafruit_DHT b/Adafruit/DHT_Driver/Adafruit_DHT similarity index 100% rename from Adafruit_DHT_Driver/Adafruit_DHT rename to Adafruit/DHT_Driver/Adafruit_DHT diff --git a/Adafruit_DHT_Driver/Adafruit_DHT.c b/Adafruit/DHT_Driver/Adafruit_DHT.c similarity index 100% rename from Adafruit_DHT_Driver/Adafruit_DHT.c rename to Adafruit/DHT_Driver/Adafruit_DHT.c diff --git a/Adafruit/DHT_Driver/Adafruit_DHT_googledocs.ex.py b/Adafruit/DHT_Driver/Adafruit_DHT_googledocs.ex.py new file mode 100755 index 00000000..dc1ccc88 --- /dev/null +++ b/Adafruit/DHT_Driver/Adafruit_DHT_googledocs.ex.py @@ -0,0 +1,76 @@ +#!/usr/bin/python + +import subprocess +import re +import sys +import time +import datetime +import gspread + +def main(): + # =========================================================================== + # Google Account Details + # =========================================================================== + + # Account details for google docs + email = 'you@somewhere.com' + password = '$hhh!' + spreadsheet = 'SpreadsheetName' + + # =========================================================================== + # Example Code + # =========================================================================== + + + # 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').sheet1 + except: + print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet + sys.exit() + + # Continuously append data + while(True): + # Run the DHT program to get the humidity and temperature readings! + + output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]); + print output + matches = re.search("Temp =\s+([0-9.]+)", output) + if (not matches): + time.sleep(3) + continue + temp = float(matches.group(1)) + + # search for humidity printout + matches = re.search("Hum =\s+([0-9.]+)", output) + if (not matches): + time.sleep(3) + continue + humidity = float(matches.group(1)) + + print "Temperature: %.1f C" % temp + print "Humidity: %.1f %%" % humidity + + # Append the data in the spreadsheet, including a timestamp + try: + values = [datetime.datetime.now(), temp, humidity] + worksheet.append_row(values) + except: + print "Unable to append data. Check your connection?" + sys.exit() + + # Wait 30 seconds before continuing + print "Wrote a row to %s" % spreadsheet + time.sleep(30) + +if __name__ == '__main__': + main() diff --git a/Adafruit_DHT_Driver/DEPRECATED.txt b/Adafruit/DHT_Driver/DEPRECATED.txt similarity index 100% rename from Adafruit_DHT_Driver/DEPRECATED.txt rename to Adafruit/DHT_Driver/DEPRECATED.txt diff --git a/Adafruit_DHT_Driver/Makefile b/Adafruit/DHT_Driver/Makefile similarity index 100% rename from Adafruit_DHT_Driver/Makefile rename to Adafruit/DHT_Driver/Makefile diff --git a/Adafruit/DHT_Driver/__init__.py b/Adafruit/DHT_Driver/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Adafruit_DHT_Driver_Python/Adafruit_DHT.py b/Adafruit/DHT_Driver_Python/Adafruit_DHT.py similarity index 100% rename from Adafruit_DHT_Driver_Python/Adafruit_DHT.py rename to Adafruit/DHT_Driver_Python/Adafruit_DHT.py diff --git a/Adafruit_DHT_Driver_Python/DEPRECATED.txt b/Adafruit/DHT_Driver_Python/DEPRECATED.txt similarity index 100% rename from Adafruit_DHT_Driver_Python/DEPRECATED.txt rename to Adafruit/DHT_Driver_Python/DEPRECATED.txt diff --git a/Adafruit_DHT_Driver_Python/README.md b/Adafruit/DHT_Driver_Python/README.md similarity index 100% rename from Adafruit_DHT_Driver_Python/README.md rename to Adafruit/DHT_Driver_Python/README.md diff --git a/Adafruit/DHT_Driver_Python/__init__.py b/Adafruit/DHT_Driver_Python/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Adafruit_DHT_Driver_Python/dhtreader.c b/Adafruit/DHT_Driver_Python/dhtreader.c similarity index 100% rename from Adafruit_DHT_Driver_Python/dhtreader.c rename to Adafruit/DHT_Driver_Python/dhtreader.c diff --git a/Adafruit_DHT_Driver_Python/setup.py b/Adafruit/DHT_Driver_Python/setup.py similarity index 100% rename from Adafruit_DHT_Driver_Python/setup.py rename to Adafruit/DHT_Driver_Python/setup.py diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit/I2C/Adafruit_I2C.py similarity index 96% rename from Adafruit_I2C/Adafruit_I2C.py rename to Adafruit/I2C/Adafruit_I2C.py index 2b24b67f..a970da6b 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit/I2C/Adafruit_I2C.py @@ -1,6 +1,13 @@ #!/usr/bin/python import re -import smbus +import warnings + +try: + import smbus + _HAS_SMBUS = True +except ImportError: + _HAS_SMBUS = False + #warnings.warn("Can't import '%s'" % 'smbus') # =========================================================================== # Adafruit_I2C Class @@ -153,9 +160,12 @@ def readS16(self, reg, little_endian=True): except IOError, err: return self.errMsg() -if __name__ == '__main__': +def main(): try: bus = Adafruit_I2C(address=0) print "Default I2C bus is accessible" except: print "Error accessing default I2C bus" + +if __name__ == '__main__': + main() diff --git a/Adafruit/I2C/__init__.py b/Adafruit/I2C/__init__.py new file mode 100644 index 00000000..e72a1fec --- /dev/null +++ b/Adafruit/I2C/__init__.py @@ -0,0 +1 @@ +from .Adafruit_I2C import Adafruit_I2C \ No newline at end of file diff --git a/Adafruit_LEDBackpack/Adafruit_7Segment.py b/Adafruit/LEDBackpack/Adafruit_7Segment.py similarity index 97% rename from Adafruit_LEDBackpack/Adafruit_7Segment.py rename to Adafruit/LEDBackpack/Adafruit_7Segment.py index f5965404..a1279e47 100644 --- a/Adafruit_LEDBackpack/Adafruit_7Segment.py +++ b/Adafruit/LEDBackpack/Adafruit_7Segment.py @@ -2,7 +2,7 @@ import time import datetime -from Adafruit_LEDBackpack import LEDBackpack +from Adafruit.LEDBackpack import LEDBackpack # =========================================================================== # 7-Segment Display diff --git a/Adafruit_LEDBackpack/Adafruit_8x8.py b/Adafruit/LEDBackpack/Adafruit_8x8.py similarity index 98% rename from Adafruit_LEDBackpack/Adafruit_8x8.py rename to Adafruit/LEDBackpack/Adafruit_8x8.py index df966dc9..3baed9c9 100644 --- a/Adafruit_LEDBackpack/Adafruit_8x8.py +++ b/Adafruit/LEDBackpack/Adafruit_8x8.py @@ -2,7 +2,7 @@ import time import datetime -from Adafruit_LEDBackpack import LEDBackpack +from Adafruit.LEDBackpack import LEDBackpack # =========================================================================== # 8x8 Pixel Display diff --git a/Adafruit_LEDBackpack/Adafruit_Bargraph.py b/Adafruit/LEDBackpack/Adafruit_Bargraph.py similarity index 96% rename from Adafruit_LEDBackpack/Adafruit_Bargraph.py rename to Adafruit/LEDBackpack/Adafruit_Bargraph.py index 804991fa..3d0598aa 100644 --- a/Adafruit_LEDBackpack/Adafruit_Bargraph.py +++ b/Adafruit/LEDBackpack/Adafruit_Bargraph.py @@ -2,7 +2,7 @@ import time import datetime -from Adafruit_LEDBackpack import LEDBackpack +from Adafruit.LEDBackpack import LEDBackpack # =========================================================================== # Bargraph Display diff --git a/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py b/Adafruit/LEDBackpack/Adafruit_LEDBackpack.py similarity index 96% rename from Adafruit_LEDBackpack/Adafruit_LEDBackpack.py rename to Adafruit/LEDBackpack/Adafruit_LEDBackpack.py index 00d7ba6c..34d82a86 100644 --- a/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py +++ b/Adafruit/LEDBackpack/Adafruit_LEDBackpack.py @@ -2,7 +2,7 @@ import time from copy import copy -from Adafruit_I2C import Adafruit_I2C +from Adafruit.I2C import Adafruit_I2C # ============================================================================ # LEDBackpack Class @@ -98,4 +98,8 @@ def clear(self, update=True): if (update): self.writeDisplay() -led = LEDBackpack(0x70) +def main(): + led = LEDBackpack(0x70) + +if __name__ == '__main__': + main() diff --git a/Adafruit/LEDBackpack/__init__.py b/Adafruit/LEDBackpack/__init__.py new file mode 100644 index 00000000..6fa4f5ed --- /dev/null +++ b/Adafruit/LEDBackpack/__init__.py @@ -0,0 +1,4 @@ +from .Adafruit_LEDBackpack import LEDBackpack +from .Adafruit_7Segment import SevenSegment +from .Adafruit_8x8 import EightByEight, ColorEightByEight +from .Adafruit_Bargraph import Bargraph diff --git a/Adafruit/LEDBackpack/ex_7segment_clock.py b/Adafruit/LEDBackpack/ex_7segment_clock.py new file mode 100644 index 00000000..e05758b8 --- /dev/null +++ b/Adafruit/LEDBackpack/ex_7segment_clock.py @@ -0,0 +1,33 @@ +#!/usr/bin/python + +import time +import datetime +from Adafruit.LEDBackpack import SevenSegment + +def main(): + # =========================================================================== + # Clock Example + # =========================================================================== + segment = SevenSegment(address=0x70) + + print "Press CTRL+Z to exit" + + # Continually update the time on a 4 char, 7-segment display + while(True): + now = datetime.datetime.now() + hour = now.hour + minute = now.minute + second = now.second + # Set hours + segment.writeDigit(0, int(hour / 10)) # Tens + segment.writeDigit(1, hour % 10) # Ones + # Set minutes + segment.writeDigit(3, int(minute / 10)) # Tens + segment.writeDigit(4, minute % 10) # Ones + # Toggle colon + segment.setColon(second % 2) # Toggle colon at 1Hz + # Wait a quarter second (less than 1 second to prevent colon blinking getting in phase with odd/even seconds). + time.sleep(0.25) + +if __name__ == '__main__': + main() diff --git a/Adafruit/LEDBackpack/ex_8x8_color_pixels.py b/Adafruit/LEDBackpack/ex_8x8_color_pixels.py new file mode 100644 index 00000000..e6ce7978 --- /dev/null +++ b/Adafruit/LEDBackpack/ex_8x8_color_pixels.py @@ -0,0 +1,27 @@ +#!/usr/bin/python + +import time +import datetime +from Adafruit.LEDBackpack import ColorEightByEight + +def main(): + # =========================================================================== + # 8x8 Pixel Example + # =========================================================================== + grid = ColorEightByEight(address=0x70) + + print "Press CTRL+Z to exit" + + iter = 0 + + # Continually update the 8x8 display one pixel at a time + while(True): + iter += 1 + + for x in range(0, 8): + for y in range(0, 8): + grid.setPixel(x, y, iter % 4 ) + time.sleep(0.02) + +if __name__ == '__main__': + main() diff --git a/Adafruit/LEDBackpack/ex_8x8_pixels.py b/Adafruit/LEDBackpack/ex_8x8_pixels.py new file mode 100644 index 00000000..bab13a27 --- /dev/null +++ b/Adafruit/LEDBackpack/ex_8x8_pixels.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +import time +import datetime +from Adafruit.LEDBackpack import EightByEight + +def main(): + # =========================================================================== + # 8x8 Pixel Example + # =========================================================================== + grid = EightByEight(address=0x70) + + print "Press CTRL+Z to exit" + + # Continually update the 8x8 display one pixel at a time + while(True): + for x in range(0, 8): + for y in range(0, 8): + grid.setPixel(x, y) + time.sleep(0.05) + time.sleep(0.5) + grid.clear() + time.sleep(0.5) + +if __name__ == '__main__': + main() diff --git a/Adafruit_LEDBackpack/ex_bargraph.py b/Adafruit/LEDBackpack/ex_bargraph.py similarity index 91% rename from Adafruit_LEDBackpack/ex_bargraph.py rename to Adafruit/LEDBackpack/ex_bargraph.py index 1fa0a31e..9eb8ca12 100644 --- a/Adafruit_LEDBackpack/ex_bargraph.py +++ b/Adafruit/LEDBackpack/ex_bargraph.py @@ -2,7 +2,7 @@ import time import datetime -from Adafruit_Bargraph import Bargraph +from Adafruit.LEDBackpack import Bargraph # =========================================================================== # Scroll through colors example diff --git a/Adafruit_LEDpixels/Adafruit_LEDpixels.py b/Adafruit/LEDpixels/Adafruit_LEDpixels.py similarity index 83% rename from Adafruit_LEDpixels/Adafruit_LEDpixels.py rename to Adafruit/LEDpixels/Adafruit_LEDpixels.py index 07e1a953..04f125a5 100644 --- a/Adafruit_LEDpixels/Adafruit_LEDpixels.py +++ b/Adafruit/LEDpixels/Adafruit_LEDpixels.py @@ -4,9 +4,6 @@ import RPi.GPIO as GPIO, time, os -DEBUG = 1 -GPIO.setmode(GPIO.BCM) - def slowspiwrite(clockpin, datapin, byteout): GPIO.setup(clockpin, GPIO.OUT) GPIO.setup(datapin, GPIO.OUT) @@ -19,12 +16,6 @@ def slowspiwrite(clockpin, datapin, byteout): GPIO.output(clockpin, True) GPIO.output(clockpin, False) - -SPICLK = 18 -SPIDO = 17 - -ledpixels = [0] * 25 - def writestrip(pixels): spidev = file("/dev/spidev0.0", "w") for i in range(len(pixels)): @@ -74,8 +65,20 @@ def rainbowCycle(pixels, wait): writestrip(pixels) time.sleep(wait) -colorwipe(ledpixels, Color(255, 0, 0), 0.05) -colorwipe(ledpixels, Color(0, 255, 0), 0.05) -colorwipe(ledpixels, Color(0, 0, 255), 0.05) -while True: - rainbowCycle(ledpixels, 0.00) +def main(): + DEBUG = 1 + GPIO.setmode(GPIO.BCM) + + SPICLK = 18 + SPIDO = 17 + + ledpixels = [0] * 25 + + colorwipe(ledpixels, Color(255, 0, 0), 0.05) + colorwipe(ledpixels, Color(0, 255, 0), 0.05) + colorwipe(ledpixels, Color(0, 0, 255), 0.05) + while True: + rainbowCycle(ledpixels, 0.00) + +if __name__ == '__main__': + main() diff --git a/Adafruit/LEDpixels/__init__.py b/Adafruit/LEDpixels/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Adafruit_LSM303/Adafruit_LSM303.py b/Adafruit/LSM303/Adafruit_LSM303.py similarity index 97% rename from Adafruit_LSM303/Adafruit_LSM303.py rename to Adafruit/LSM303/Adafruit_LSM303.py index 9af1e83a..88fa187f 100755 --- a/Adafruit_LSM303/Adafruit_LSM303.py +++ b/Adafruit/LSM303/Adafruit_LSM303.py @@ -26,7 +26,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_LSM303(Adafruit_I2C): @@ -108,10 +108,8 @@ def read(self): def setMagGain(gain=LSM303_MAGGAIN_1_3): self.mag.write8( LSM303_REGISTER_MAG_CRB_REG_M, gain) - -# Simple example prints accel/mag data once per second: -if __name__ == '__main__': - +def main(): + # Simple example prints accel/mag data once per second: from time import sleep lsm = Adafruit_LSM303() @@ -120,3 +118,6 @@ def setMagGain(gain=LSM303_MAGGAIN_1_3): while True: print lsm.read() sleep(1) # Output is fun to watch if this is commented out + +if __name__ == '__main__': + main() diff --git a/Adafruit/LSM303/__init__.py b/Adafruit/LSM303/__init__.py new file mode 100644 index 00000000..9c75e8fc --- /dev/null +++ b/Adafruit/LSM303/__init__.py @@ -0,0 +1 @@ +from .Adafruit_LSM303 import Adafruit_LSM303 diff --git a/Adafruit_MCP230xx/Adafruit_MCP230xx.py b/Adafruit/MCP230xx/Adafruit_MCP230xx.py similarity index 99% rename from Adafruit_MCP230xx/Adafruit_MCP230xx.py rename to Adafruit/MCP230xx/Adafruit_MCP230xx.py index dc1b9c27..3a544490 100755 --- a/Adafruit_MCP230xx/Adafruit_MCP230xx.py +++ b/Adafruit/MCP230xx/Adafruit_MCP230xx.py @@ -20,7 +20,7 @@ # 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 import smbus import time @@ -175,8 +175,7 @@ def output(self, pin, value): def pullup(self, pin, value): self.chip.pullup(pin, value) - -if __name__ == '__main__': +def main(): # *************************************************** # Set num_gpios to 8 for MCP23008 or 16 for MCP23017! # *************************************************** @@ -202,3 +201,6 @@ def pullup(self, pin, value): time.sleep(1); mcp.output(0, 0) # Pin 0 Low time.sleep(1); + +if __name__ == '__main__': + main() diff --git a/Adafruit/MCP230xx/__init__.py b/Adafruit/MCP230xx/__init__.py new file mode 100644 index 00000000..5f3c0f0f --- /dev/null +++ b/Adafruit/MCP230xx/__init__.py @@ -0,0 +1 @@ +from .Adafruit_MCP230xx import Adafruit_MCP230xx, MCP230XX_GPIO \ No newline at end of file diff --git a/Adafruit_MCP3002/MCP3002.py b/Adafruit/MCP3002/MCP3002.py similarity index 68% rename from Adafruit_MCP3002/MCP3002.py rename to Adafruit/MCP3002/MCP3002.py index 5b0b68b5..984bbf96 100644 --- a/Adafruit_MCP3002/MCP3002.py +++ b/Adafruit/MCP3002/MCP3002.py @@ -4,9 +4,6 @@ import RPi.GPIO as GPIO, time, os -DEBUG = 1 -GPIO.setmode(GPIO.BCM) - # this function is not used, its for future reference! def slowspiwrite(clockpin, datapin, byteout): GPIO.setup(clockpin, GPIO.OUT) @@ -68,27 +65,35 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin): adcout /= 2 # first bit is 'null' so drop it return adcout -# change these as desired -SPICLK = 18 -SPIMOSI = 17 -SPIMISO = 21 -SPICS = 22 -# set up the SPI interface pins -GPIO.setup(SPIMOSI, GPIO.OUT) -GPIO.setup(SPIMISO, GPIO.IN) -GPIO.setup(SPICLK, GPIO.OUT) -GPIO.setup(SPICS, GPIO.OUT) +def main(): + DEBUG = 1 + GPIO.setmode(GPIO.BCM) + + # change these as desired + SPICLK = 18 + SPIMOSI = 17 + SPIMISO = 21 + SPICS = 22 + + # set up the SPI interface pins + GPIO.setup(SPIMOSI, GPIO.OUT) + GPIO.setup(SPIMISO, GPIO.IN) + GPIO.setup(SPICLK, GPIO.OUT) + GPIO.setup(SPICS, GPIO.OUT) + + # Note that bitbanging SPI is incredibly slow on the Pi as its not + # a RTOS - reading the ADC takes about 30 ms (~30 samples per second) + # which is awful for a microcontroller but better-than-nothing for Linux -# Note that bitbanging SPI is incredibly slow on the Pi as its not -# a RTOS - reading the ADC takes about 30 ms (~30 samples per second) -# which is awful for a microcontroller but better-than-nothing for Linux + print "| #0 \t #1|" + print "-----------------------------------------------------------------" + while True: + print "|", + for adcnum in range(2): + ret = readadc(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS) + print ret,"\t", + print "|" -print "| #0 \t #1|" -print "-----------------------------------------------------------------" -while True: - print "|", - for adcnum in range(2): - ret = readadc(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS) - print ret,"\t", - print "|" +if __name__ == '__main__': + main() diff --git a/Adafruit/MCP3002/__init__.py b/Adafruit/MCP3002/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Adafruit/MCP3008/__init__.py b/Adafruit/MCP3008/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Adafruit_MCP3008/mcp3008.py b/Adafruit/MCP3008/mcp3008.py similarity index 97% rename from Adafruit_MCP3008/mcp3008.py rename to Adafruit/MCP3008/mcp3008.py index 73dcd7dd..1a4adcbb 100644 --- a/Adafruit_MCP3008/mcp3008.py +++ b/Adafruit/MCP3008/mcp3008.py @@ -4,9 +4,6 @@ import RPi.GPIO as GPIO, time, os -DEBUG = 1 -GPIO.setmode(GPIO.BCM) - # this function is not used, its for future reference! def slowspiwrite(clockpin, datapin, byteout): GPIO.setup(clockpin, GPIO.OUT) @@ -67,8 +64,10 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin): adcout /= 2 # first bit is 'null' so drop it return adcout - -if __name__=='__main__': + +def main(): + DEBUG = 1 + GPIO.setmode(GPIO.BCM) try: # change these as desired @@ -100,3 +99,6 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin): pass GPIO.cleanup() + +if __name__=='__main__': + main() diff --git a/Adafruit_MCP4725/Adafruit_MCP4725.py b/Adafruit/MCP4725/Adafruit_MCP4725.py similarity index 94% rename from Adafruit_MCP4725/Adafruit_MCP4725.py rename to Adafruit/MCP4725/Adafruit_MCP4725.py index 0cd66b20..dbf38fb5 100755 --- a/Adafruit_MCP4725/Adafruit_MCP4725.py +++ b/Adafruit/MCP4725/Adafruit_MCP4725.py @@ -1,12 +1,12 @@ #!/usr/bin/python -from Adafruit_I2C import Adafruit_I2C +from Adafruit.I2C import Adafruit_I2C # ============================================================================ # Adafruit MCP4725 12-Bit DAC # ============================================================================ -class MCP4725 : +class MCP4725(object): i2c = None # Registers diff --git a/Adafruit/MCP4725/__init__.py b/Adafruit/MCP4725/__init__.py new file mode 100644 index 00000000..6f8689d5 --- /dev/null +++ b/Adafruit/MCP4725/__init__.py @@ -0,0 +1 @@ +from .Adafruit_MCP4725 import MCP4725 diff --git a/Adafruit_MCP4725/sinewave.py b/Adafruit/MCP4725/sinewave.py similarity index 87% rename from Adafruit_MCP4725/sinewave.py rename to Adafruit/MCP4725/sinewave.py index 11928251..c7ad7e6d 100755 --- a/Adafruit_MCP4725/sinewave.py +++ b/Adafruit/MCP4725/sinewave.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from Adafruit_MCP4725 import MCP4725 +from Adafruit.MCP4725 import MCP4725 import time # Set this value to 9, 8, 7, 6 or 5 to adjust the resolution @@ -145,28 +145,31 @@ 2048, 1648, 1264, 910, 600, 345, 156, 39, 0, 39, 156, 345, 600, 910, 1264, 1648 ] -# Initialise the DAC using the default address -dac = MCP4725(0x62) +def main(): + # Initialise the DAC using the default address + dac = MCP4725(0x62) -if (DAC_RESOLUTION < 5) | (DAC_RESOLUTION > 9): - print "Invalid DAC resolution: Set DAC_RESOLUTION from 5..9" -else: - print "Generating a sine wave with %d-bit resolution" % DAC_RESOLUTION - print "Press CTRL+C to stop" - while(True): - if (DAC_RESOLUTION == 9): - for val in DACLookup_FullSine_9Bit: - dac.setVoltage(val) - if (DAC_RESOLUTION == 8): - for val in DACLookup_FullSine_8Bit: - dac.setVoltage(val) - if (DAC_RESOLUTION == 7): - for val in DACLookup_FullSine_7Bit: - dac.setVoltage(val) - if (DAC_RESOLUTION == 6): - for val in DACLookup_FullSine_6Bit: - dac.setVoltage(val) - if (DAC_RESOLUTION == 5): - for val in DACLookup_FullSine_5Bit: - dac.setVoltage(val) + if (DAC_RESOLUTION < 5) | (DAC_RESOLUTION > 9): + print "Invalid DAC resolution: Set DAC_RESOLUTION from 5..9" + else: + print "Generating a sine wave with %d-bit resolution" % DAC_RESOLUTION + print "Press CTRL+C to stop" + while(True): + if (DAC_RESOLUTION == 9): + for val in DACLookup_FullSine_9Bit: + dac.setVoltage(val) + if (DAC_RESOLUTION == 8): + for val in DACLookup_FullSine_8Bit: + dac.setVoltage(val) + if (DAC_RESOLUTION == 7): + for val in DACLookup_FullSine_7Bit: + dac.setVoltage(val) + if (DAC_RESOLUTION == 6): + for val in DACLookup_FullSine_6Bit: + dac.setVoltage(val) + if (DAC_RESOLUTION == 5): + for val in DACLookup_FullSine_5Bit: + dac.setVoltage(val) +if __name__ == '__main__': + main() diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py b/Adafruit/PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py similarity index 98% rename from Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py rename to Adafruit/PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py index 35c993ca..96072f5e 100644 --- a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py +++ b/Adafruit/PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py @@ -2,13 +2,13 @@ import time import math -from Adafruit_I2C import Adafruit_I2C +from Adafruit.I2C import Adafruit_I2C # ============================================================================ # Adafruit PCA9685 16-Channel PWM Servo Driver # ============================================================================ -class PWM : +class PWM(object): # Registers/etc. __MODE1 = 0x00 __MODE2 = 0x01 diff --git a/Adafruit/PWM_Servo_Driver/Servo_Example.py b/Adafruit/PWM_Servo_Driver/Servo_Example.py new file mode 100644 index 00000000..7639ae85 --- /dev/null +++ b/Adafruit/PWM_Servo_Driver/Servo_Example.py @@ -0,0 +1,38 @@ +#!/usr/bin/python + +from Adafruit.PWM_Servo_Driver import PWM +import time + +# =========================================================================== +# Example Code +# =========================================================================== + +def setServoPulse(channel, pulse): + pulseLength = 1000000 # 1,000,000 us per second + pulseLength /= 60 # 60 Hz + print "%d us per period" % pulseLength + pulseLength /= 4096 # 12 bits of resolution + print "%d us per bit" % pulseLength + pulse *= 1000 + pulse /= pulseLength + pwm.setPWM(channel, 0, pulse) + +def main(): + # Initialise the PWM device using the default address + pwm = PWM(0x40) + # Note if you'd like more debug output you can instead run: + #pwm = PWM(0x40, debug=True) + + servoMin = 150 # Min pulse length out of 4096 + servoMax = 600 # Max pulse length out of 4096 + + pwm.setPWMFreq(60) # Set frequency to 60 Hz + while (True): + # Change speed of continuous servo on channel O + pwm.setPWM(0, 0, servoMin) + time.sleep(1) + pwm.setPWM(0, 0, servoMax) + time.sleep(1) + +if __name__ == '__main__': + main() diff --git a/Adafruit/PWM_Servo_Driver/__init__.py b/Adafruit/PWM_Servo_Driver/__init__.py new file mode 100644 index 00000000..55c3f5ef --- /dev/null +++ b/Adafruit/PWM_Servo_Driver/__init__.py @@ -0,0 +1 @@ +from .Adafruit_PWM_Servo_Driver import PWM diff --git a/Adafruit_TCS34725/Adafruit_I2C.py b/Adafruit/TCS34725/Adafruit_I2C.py similarity index 99% rename from Adafruit_TCS34725/Adafruit_I2C.py rename to Adafruit/TCS34725/Adafruit_I2C.py index 3423461d..b989da47 100644 --- a/Adafruit_TCS34725/Adafruit_I2C.py +++ b/Adafruit/TCS34725/Adafruit_I2C.py @@ -162,9 +162,12 @@ def readS16Rev(self, reg): except IOError, err: return self.errMsg() -if __name__ == '__main__': +def main(): try: bus = Adafruit_I2C(address=0) print "Default I2C bus is accessible" except: print "Error accessing default I2C bus" + +if __name__ == '__main__': + main() diff --git a/Adafruit_TCS34725/Adafruit_TCS34725.py b/Adafruit/TCS34725/Adafruit_TCS34725.py similarity index 99% rename from Adafruit_TCS34725/Adafruit_TCS34725.py rename to Adafruit/TCS34725/Adafruit_TCS34725.py index 08a50f78..15637cc4 100644 --- a/Adafruit_TCS34725/Adafruit_TCS34725.py +++ b/Adafruit/TCS34725/Adafruit_TCS34725.py @@ -1,7 +1,7 @@ #!/usr/bin/python import time -from Adafruit_I2C import Adafruit_I2C +from Adafruit.I2C import Adafruit_I2C # =========================================================================== # TCS3472 Class diff --git a/Adafruit/TCS34725/Adafruit_TCS34725_Example.py b/Adafruit/TCS34725/Adafruit_TCS34725_Example.py new file mode 100644 index 00000000..9a1a624e --- /dev/null +++ b/Adafruit/TCS34725/Adafruit_TCS34725_Example.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +from time import sleep +from Adafruit.TCS34725 import TCS34725 + +def main(): + # =========================================================================== + # Example Code + # =========================================================================== + + # Initialize the TCS34725 and use default integration time and gain + # tcs34725 = TCS34725(debug=True) + tcs = TCS34725(integrationTime=0xEB, gain=0x01) + tcs.setInterrupt(False) + sleep(1) + + rgb = tcs.getRawData() + colorTemp = tcs.calculateColorTemperature(rgb) + lux = tcs.calculateLux(rgb) + print rgb + if colorTemp is None: + print 'Too dark to determine color temperature!' + else: + print "Color Temperature: %d K" % colorTemp + print "Luminosity: %d lux" % lux + tcs.setInterrupt(True) + sleep(1) + tcs.disable() + +if __name__ == '__main__': + main() diff --git a/Adafruit/TCS34725/__init__.py b/Adafruit/TCS34725/__init__.py new file mode 100644 index 00000000..a42cb58b --- /dev/null +++ b/Adafruit/TCS34725/__init__.py @@ -0,0 +1 @@ +from .Adafruit_TCS34725 import TCS34725 diff --git a/Adafruit_VCNL4000/Adafruit_VCNL4000.py b/Adafruit/VCNL4000/Adafruit_VCNL4000.py similarity index 100% rename from Adafruit_VCNL4000/Adafruit_VCNL4000.py rename to Adafruit/VCNL4000/Adafruit_VCNL4000.py diff --git a/Adafruit_VCNL4000/Adafruit_VCNL4000_example.py b/Adafruit/VCNL4000/Adafruit_VCNL4000_example.py similarity index 90% rename from Adafruit_VCNL4000/Adafruit_VCNL4000_example.py rename to Adafruit/VCNL4000/Adafruit_VCNL4000_example.py index 36baa422..708c1bf6 100755 --- a/Adafruit_VCNL4000/Adafruit_VCNL4000_example.py +++ b/Adafruit/VCNL4000/Adafruit_VCNL4000_example.py @@ -1,6 +1,6 @@ #!/usr/bin/python -from Adafruit_VCNL4000 import VCNL4000 +from Adafruit.VCNL4000 import VCNL4000 import time # =========================================================================== diff --git a/Adafruit/VCNL4000/__init__.py b/Adafruit/VCNL4000/__init__.py new file mode 100644 index 00000000..150aeba7 --- /dev/null +++ b/Adafruit/VCNL4000/__init__.py @@ -0,0 +1 @@ +from .Adafruit_VCNL4000 import VCNL4000 diff --git a/Adafruit/__init__.py b/Adafruit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Adafruit_ADS1x15/Adafruit_I2C.py b/Adafruit_ADS1x15/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_ADS1x15/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_ADS1x15/ads1x15_ex_comparator.py b/Adafruit_ADS1x15/ads1x15_ex_comparator.py deleted file mode 100644 index e10eb6cb..00000000 --- a/Adafruit_ADS1x15/ads1x15_ex_comparator.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/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) - -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) diff --git a/Adafruit_ADS1x15/ads1x15_ex_differential.py b/Adafruit_ADS1x15/ads1x15_ex_differential.py deleted file mode 100644 index 01614fdd..00000000 --- a/Adafruit_ADS1x15/ads1x15_ex_differential.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/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) -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) diff --git a/Adafruit_ADS1x15/ads1x15_ex_singleended.py b/Adafruit_ADS1x15/ads1x15_ex_singleended.py deleted file mode 100644 index 2c4dee43..00000000 --- a/Adafruit_ADS1x15/ads1x15_ex_singleended.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/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) -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) diff --git a/Adafruit_ADXL345/Adafruit_I2C.py b/Adafruit_ADXL345/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_ADXL345/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_BMP085/Adafruit_BMP085_example.py b/Adafruit_BMP085/Adafruit_BMP085_example.py deleted file mode 100755 index e7143c8a..00000000 --- a/Adafruit_BMP085/Adafruit_BMP085_example.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/python - -from Adafruit_BMP085 import BMP085 - -# =========================================================================== -# 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 diff --git a/Adafruit_BMP085/Adafruit_BMP085_googledocs_ex.py b/Adafruit_BMP085/Adafruit_BMP085_googledocs_ex.py deleted file mode 100755 index 4d62cd0b..00000000 --- a/Adafruit_BMP085/Adafruit_BMP085_googledocs_ex.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python - -import sys -import time -import datetime -import gspread -from Adafruit_BMP085 import BMP085 - -# =========================================================================== -# 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) - diff --git a/Adafruit_BMP085/Adafruit_I2C.py b/Adafruit_BMP085/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_BMP085/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py deleted file mode 100755 index f1be14cd..00000000 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python - -from Adafruit_CharLCD import Adafruit_CharLCD -from subprocess import * -from time import sleep, strftime -from datetime import datetime - -lcd = Adafruit_CharLCD() - -cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" - -lcd.begin(16, 1) - - -def run_cmd(cmd): - p = Popen(cmd, shell=True, stdout=PIPE) - output = p.communicate()[0] - return output - -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) diff --git a/Adafruit_CharLCD/Adafruit_I2C.py b/Adafruit_CharLCD/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_CharLCD/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_CharLCD/Adafruit_MCP230xx.py b/Adafruit_CharLCD/Adafruit_MCP230xx.py deleted file mode 120000 index 3df8faef..00000000 --- a/Adafruit_CharLCD/Adafruit_MCP230xx.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_MCP230xx/Adafruit_MCP230xx.py \ No newline at end of file diff --git a/Adafruit_CharLCD/LCD_MCP230XX_test.py b/Adafruit_CharLCD/LCD_MCP230XX_test.py deleted file mode 100644 index cc1e7bcd..00000000 --- a/Adafruit_CharLCD/LCD_MCP230XX_test.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 - -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") diff --git a/Adafruit_CharLCDPlate/Adafruit_I2C.py b/Adafruit_CharLCDPlate/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_CharLCDPlate/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_CharLCDPlate/Adafruit_MCP230xx.py b/Adafruit_CharLCDPlate/Adafruit_MCP230xx.py deleted file mode 120000 index 3df8faef..00000000 --- a/Adafruit_CharLCDPlate/Adafruit_MCP230xx.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_MCP230xx/Adafruit_MCP230xx.py \ No newline at end of file diff --git a/Adafruit_CharLCDPlate/LCDtest.py b/Adafruit_CharLCDPlate/LCDtest.py deleted file mode 100644 index cbda5c2c..00000000 --- a/Adafruit_CharLCDPlate/LCDtest.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python - -from time import sleep -from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate - -# Initialize the LCD plate. Should auto-detect correct I2C bus. If not, -# pass '0' for early 256 MB Model B boards or '1' for all later versions -lcd = Adafruit_CharLCDPlate() - -# Clear display and show greeting, pause 1 sec -lcd.clear() -lcd.message("Adafruit RGB LCD\nPlate w/Keypad!") -sleep(1) - -# Cycle through backlight colors -col = (lcd.RED , lcd.YELLOW, lcd.GREEN, lcd.TEAL, - lcd.BLUE, lcd.VIOLET, lcd.ON , lcd.OFF) -for c in col: - lcd.backlight(c) - sleep(.5) - -# Poll buttons, display message & set backlight accordingly -btn = ((lcd.LEFT , 'Red Red Wine' , lcd.RED), - (lcd.UP , 'Sita sings\nthe blues' , lcd.BLUE), - (lcd.DOWN , 'I see fields\nof green' , lcd.GREEN), - (lcd.RIGHT , 'Purple mountain\nmajesties', lcd.VIOLET), - (lcd.SELECT, '' , lcd.ON)) -prev = -1 -while True: - for b in btn: - if lcd.buttonPressed(b[0]): - if b is not prev: - lcd.clear() - lcd.message(b[1]) - lcd.backlight(b[2]) - prev = b - break diff --git a/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py b/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py deleted file mode 100755 index 9c9f6318..00000000 --- a/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python - -import subprocess -import re -import sys -import time -import datetime -import gspread - -# =========================================================================== -# Google Account Details -# =========================================================================== - -# Account details for google docs -email = 'you@somewhere.com' -password = '$hhh!' -spreadsheet = 'SpreadsheetName' - -# =========================================================================== -# Example Code -# =========================================================================== - - -# 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').sheet1 -except: - print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet - sys.exit() - -# Continuously append data -while(True): - # Run the DHT program to get the humidity and temperature readings! - - output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]); - print output - matches = re.search("Temp =\s+([0-9.]+)", output) - if (not matches): - time.sleep(3) - continue - temp = float(matches.group(1)) - - # search for humidity printout - matches = re.search("Hum =\s+([0-9.]+)", output) - if (not matches): - time.sleep(3) - continue - humidity = float(matches.group(1)) - - print "Temperature: %.1f C" % temp - print "Humidity: %.1f %%" % humidity - - # Append the data in the spreadsheet, including a timestamp - try: - values = [datetime.datetime.now(), temp, humidity] - worksheet.append_row(values) - except: - print "Unable to append data. Check your connection?" - sys.exit() - - # Wait 30 seconds before continuing - print "Wrote a row to %s" % spreadsheet - time.sleep(30) diff --git a/Adafruit_LEDBackpack/Adafruit_I2C.py b/Adafruit_LEDBackpack/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_LEDBackpack/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_LEDBackpack/ex_7segment_clock.py b/Adafruit_LEDBackpack/ex_7segment_clock.py deleted file mode 100644 index 51aee185..00000000 --- a/Adafruit_LEDBackpack/ex_7segment_clock.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python - -import time -import datetime -from Adafruit_7Segment import SevenSegment - -# =========================================================================== -# Clock Example -# =========================================================================== -segment = SevenSegment(address=0x70) - -print "Press CTRL+Z to exit" - -# Continually update the time on a 4 char, 7-segment display -while(True): - now = datetime.datetime.now() - hour = now.hour - minute = now.minute - second = now.second - # Set hours - segment.writeDigit(0, int(hour / 10)) # Tens - segment.writeDigit(1, hour % 10) # Ones - # Set minutes - segment.writeDigit(3, int(minute / 10)) # Tens - segment.writeDigit(4, minute % 10) # Ones - # Toggle colon - segment.setColon(second % 2) # Toggle colon at 1Hz - # Wait a quarter second (less than 1 second to prevent colon blinking getting in phase with odd/even seconds). - time.sleep(0.25) diff --git a/Adafruit_LEDBackpack/ex_8x8_color_pixels.py b/Adafruit_LEDBackpack/ex_8x8_color_pixels.py deleted file mode 100644 index 978db826..00000000 --- a/Adafruit_LEDBackpack/ex_8x8_color_pixels.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/python - -import time -import datetime -from Adafruit_8x8 import ColorEightByEight - -# =========================================================================== -# 8x8 Pixel Example -# =========================================================================== -grid = ColorEightByEight(address=0x70) - -print "Press CTRL+Z to exit" - -iter = 0 - -# Continually update the 8x8 display one pixel at a time -while(True): - iter += 1 - - for x in range(0, 8): - for y in range(0, 8): - grid.setPixel(x, y, iter % 4 ) - time.sleep(0.02) diff --git a/Adafruit_LEDBackpack/ex_8x8_pixels.py b/Adafruit_LEDBackpack/ex_8x8_pixels.py deleted file mode 100644 index 4a396ee3..00000000 --- a/Adafruit_LEDBackpack/ex_8x8_pixels.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/python - -import time -import datetime -from Adafruit_8x8 import EightByEight - -# =========================================================================== -# 8x8 Pixel Example -# =========================================================================== -grid = EightByEight(address=0x70) - -print "Press CTRL+Z to exit" - -# Continually update the 8x8 display one pixel at a time -while(True): - for x in range(0, 8): - for y in range(0, 8): - grid.setPixel(x, y) - time.sleep(0.05) - time.sleep(0.5) - grid.clear() - time.sleep(0.5) diff --git a/Adafruit_LSM303/Adafruit_I2C.py b/Adafruit_LSM303/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_LSM303/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_MCP230xx/Adafruit_I2C.py b/Adafruit_MCP230xx/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_MCP230xx/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_MCP4725/Adafruit_I2C.py b/Adafruit_MCP4725/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_MCP4725/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py b/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_PWM_Servo_Driver/Servo_Example.py b/Adafruit_PWM_Servo_Driver/Servo_Example.py deleted file mode 100644 index 66a0d7fa..00000000 --- a/Adafruit_PWM_Servo_Driver/Servo_Example.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python - -from Adafruit_PWM_Servo_Driver import PWM -import time - -# =========================================================================== -# Example Code -# =========================================================================== - -# Initialise the PWM device using the default address -pwm = PWM(0x40) -# Note if you'd like more debug output you can instead run: -#pwm = PWM(0x40, debug=True) - -servoMin = 150 # Min pulse length out of 4096 -servoMax = 600 # Max pulse length out of 4096 - -def setServoPulse(channel, pulse): - pulseLength = 1000000 # 1,000,000 us per second - pulseLength /= 60 # 60 Hz - print "%d us per period" % pulseLength - pulseLength /= 4096 # 12 bits of resolution - print "%d us per bit" % pulseLength - pulse *= 1000 - pulse /= pulseLength - pwm.setPWM(channel, 0, pulse) - -pwm.setPWMFreq(60) # Set frequency to 60 Hz -while (True): - # Change speed of continuous servo on channel O - pwm.setPWM(0, 0, servoMin) - time.sleep(1) - pwm.setPWM(0, 0, servoMax) - time.sleep(1) - - - diff --git a/Adafruit_TCS34725/Adafruit_TCS34725_Example.py b/Adafruit_TCS34725/Adafruit_TCS34725_Example.py deleted file mode 100644 index c55ccb21..00000000 --- a/Adafruit_TCS34725/Adafruit_TCS34725_Example.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python -from time import sleep -from Adafruit_TCS34725 import TCS34725 - -# =========================================================================== -# Example Code -# =========================================================================== - -# Initialize the TCS34725 and use default integration time and gain -# tcs34725 = TCS34725(debug=True) -tcs = TCS34725(integrationTime=0xEB, gain=0x01) -tcs.setInterrupt(False) -sleep(1) - -rgb = tcs.getRawData() -colorTemp = tcs.calculateColorTemperature(rgb) -lux = tcs.calculateLux(rgb) -print rgb -if colorTemp is None: - print 'Too dark to determine color temperature!' -else: - print "Color Temperature: %d K" % colorTemp -print "Luminosity: %d lux" % lux -tcs.setInterrupt(True) -sleep(1) -tcs.disable() diff --git a/Adafruit_VCNL4000/Adafruit_I2C.py b/Adafruit_VCNL4000/Adafruit_I2C.py deleted file mode 120000 index 77f06164..00000000 --- a/Adafruit_VCNL4000/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..ce88737c --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,24 @@ +Copyright (c) 2012-2013 Limor Fried, Kevin Townsend and Mikey Sklar for Adafruit Industries. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..261317f0 --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +from setuptools import setup, find_packages +NAME = 'Adafruit_Libraries' + +setup( + name=NAME, + version='0.x.y', + author='Adafruit', + packages=find_packages(), + url='http://www.adafruit.com/', + license='LICENSE.txt', + description='Libraries for using Adafruit Hardware on a Raspberry Pi or BeagleBone Black', + long_description=open('README.md').read(), +) \ No newline at end of file