diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6d764cfa --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# Python specific .gitignore +# GitHub recommended entries from https://github.com/github/gitignore + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Rope +.ropeproject + +# Django stuff: +*.log +*.pot + +# Sphinx documentation +docs/_build/ diff --git a/Adafruit_ADS1x15/Adafruit_ADS1x15.py b/Adafruit_ADS1x15/Adafruit_ADS1x15.py deleted file mode 100644 index 96a99feb..00000000 --- a/Adafruit_ADS1x15/Adafruit_ADS1x15.py +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/python - -import time -import smbus -from Adafruit_I2C import Adafruit_I2C - -# =========================================================================== -# ADS1x15 Class -# =========================================================================== - -class ADS1x15: - i2c = None - - # IC Identifiers - __IC_ADS1015 = 0x00 - __IC_ADS1115 = 0x01 - - # Pointer Register - __ADS1015_REG_POINTER_MASK = 0x03 - __ADS1015_REG_POINTER_CONVERT = 0x00 - __ADS1015_REG_POINTER_CONFIG = 0x01 - __ADS1015_REG_POINTER_LOWTHRESH = 0x02 - __ADS1015_REG_POINTER_HITHRESH = 0x03 - - # Config Register - __ADS1015_REG_CONFIG_OS_MASK = 0x8000 - __ADS1015_REG_CONFIG_OS_SINGLE = 0x8000 # Write: Set to start a single-conversion - __ADS1015_REG_CONFIG_OS_BUSY = 0x0000 # Read: Bit = 0 when conversion is in progress - __ADS1015_REG_CONFIG_OS_NOTBUSY = 0x8000 # Read: Bit = 1 when device is not performing a conversion - - __ADS1015_REG_CONFIG_MUX_MASK = 0x7000 - __ADS1015_REG_CONFIG_MUX_DIFF_0_1 = 0x0000 # Differential P = AIN0, N = AIN1 (default) - __ADS1015_REG_CONFIG_MUX_DIFF_0_3 = 0x1000 # Differential P = AIN0, N = AIN3 - __ADS1015_REG_CONFIG_MUX_DIFF_1_3 = 0x2000 # Differential P = AIN1, N = AIN3 - __ADS1015_REG_CONFIG_MUX_DIFF_2_3 = 0x3000 # Differential P = AIN2, N = AIN3 - __ADS1015_REG_CONFIG_MUX_SINGLE_0 = 0x4000 # Single-ended AIN0 - __ADS1015_REG_CONFIG_MUX_SINGLE_1 = 0x5000 # Single-ended AIN1 - __ADS1015_REG_CONFIG_MUX_SINGLE_2 = 0x6000 # Single-ended AIN2 - __ADS1015_REG_CONFIG_MUX_SINGLE_3 = 0x7000 # Single-ended AIN3 - - __ADS1015_REG_CONFIG_PGA_MASK = 0x0E00 - __ADS1015_REG_CONFIG_PGA_6_144V = 0x0000 # +/-6.144V range - __ADS1015_REG_CONFIG_PGA_4_096V = 0x0200 # +/-4.096V range - __ADS1015_REG_CONFIG_PGA_2_048V = 0x0400 # +/-2.048V range (default) - __ADS1015_REG_CONFIG_PGA_1_024V = 0x0600 # +/-1.024V range - __ADS1015_REG_CONFIG_PGA_0_512V = 0x0800 # +/-0.512V range - __ADS1015_REG_CONFIG_PGA_0_256V = 0x0A00 # +/-0.256V range - - __ADS1015_REG_CONFIG_MODE_MASK = 0x0100 - __ADS1015_REG_CONFIG_MODE_CONTIN = 0x0000 # Continuous conversion mode - __ADS1015_REG_CONFIG_MODE_SINGLE = 0x0100 # Power-down single-shot mode (default) - - __ADS1015_REG_CONFIG_DR_MASK = 0x00E0 - __ADS1015_REG_CONFIG_DR_128SPS = 0x0000 # 128 samples per second - __ADS1015_REG_CONFIG_DR_250SPS = 0x0020 # 250 samples per second - __ADS1015_REG_CONFIG_DR_490SPS = 0x0040 # 490 samples per second - __ADS1015_REG_CONFIG_DR_920SPS = 0x0050 # 920 samples per second - __ADS1015_REG_CONFIG_DR_1600SPS = 0x0080 # 1600 samples per second (default) - __ADS1015_REG_CONFIG_DR_2400SPS = 0x00A0 # 2400 samples per second - __ADS1015_REG_CONFIG_DR_3300SPS = 0x00C0 # 3300 samples per second - - __ADS1115_REG_CONFIG_DR_8SPS = 0x0000 # 8 samples per second - __ADS1115_REG_CONFIG_DR_16SPS = 0x0020 # 16 samples per second - __ADS1115_REG_CONFIG_DR_32SPS = 0x0040 # 32 samples per second - __ADS1115_REG_CONFIG_DR_64SPS = 0x0060 # 64 samples per second - __ADS1115_REG_CONFIG_DR_128SPS = 0x0080 # 128 samples per second - __ADS1115_REG_CONFIG_DR_250SPS = 0x00A0 # 250 samples per second (default) - __ADS1115_REG_CONFIG_DR_475SPS = 0x00C0 # 475 samples per second - __ADS1115_REG_CONFIG_DR_860SPS = 0x00E0 # 860 samples per second - - __ADS1015_REG_CONFIG_CMODE_MASK = 0x0010 - __ADS1015_REG_CONFIG_CMODE_TRAD = 0x0000 # Traditional comparator with hysteresis (default) - __ADS1015_REG_CONFIG_CMODE_WINDOW = 0x0010 # Window comparator - - __ADS1015_REG_CONFIG_CPOL_MASK = 0x0008 - __ADS1015_REG_CONFIG_CPOL_ACTVLOW = 0x0000 # ALERT/RDY pin is low when active (default) - __ADS1015_REG_CONFIG_CPOL_ACTVHI = 0x0008 # ALERT/RDY pin is high when active - - __ADS1015_REG_CONFIG_CLAT_MASK = 0x0004 # Determines if ALERT/RDY pin latches once asserted - __ADS1015_REG_CONFIG_CLAT_NONLAT = 0x0000 # Non-latching comparator (default) - __ADS1015_REG_CONFIG_CLAT_LATCH = 0x0004 # Latching comparator - - __ADS1015_REG_CONFIG_CQUE_MASK = 0x0003 - __ADS1015_REG_CONFIG_CQUE_1CONV = 0x0000 # Assert ALERT/RDY after one conversions - __ADS1015_REG_CONFIG_CQUE_2CONV = 0x0001 # Assert ALERT/RDY after two conversions - __ADS1015_REG_CONFIG_CQUE_4CONV = 0x0002 # Assert ALERT/RDY after four conversions - __ADS1015_REG_CONFIG_CQUE_NONE = 0x0003 # Disable the comparator and put ALERT/RDY in high state (default) - - # Constructor - def __init__(self, address=0x48, ic=__IC_ADS1015, debug=False): - # Depending on if you have an old or a new Raspberry Pi, you - # may need to change the I2C bus. Older Pis use SMBus 0, - # whereas new Pis use SMBus 1. If you see an error like: - # 'Error accessing 0x48: Check your I2C address ' - # change the SMBus number in the initializer below! - self.i2c = Adafruit_I2C(address) - self.address = address - self.debug = debug - - # Make sure the IC specified is valid - if ((ic < self.__IC_ADS1015) | (ic > self.__IC_ADS1115)): - if (self.debug): - print "ADS1x15: Invalid IC. Using the ADS1015 by default" - self.ic = __IC_ADS1015 - else: - self.ic = ic - - def readADCSingleEnded(self, channel=0): - "Gets a single-ended ADC reading from the specified channel (1 bit = 3mV)" - # Default to channel 0 with invalid channel, or return -1? - if (channel > 3): - if (self.debug): - print "ADS1x15: Invalid channel specified: %d" % channel - return -1 - - # Set default values - if (self.ic == self.__IC_ADS1015): - config = self.__ADS1015_REG_CONFIG_CQUE_NONE | \ - self.__ADS1015_REG_CONFIG_CLAT_NONLAT | \ - self.__ADS1015_REG_CONFIG_CPOL_ACTVLOW | \ - self.__ADS1015_REG_CONFIG_CMODE_TRAD | \ - self.__ADS1015_REG_CONFIG_DR_1600SPS | \ - self.__ADS1015_REG_CONFIG_MODE_SINGLE - else: - config = self.__ADS1015_REG_CONFIG_CQUE_NONE | \ - self.__ADS1015_REG_CONFIG_CLAT_NONLAT | \ - self.__ADS1015_REG_CONFIG_CPOL_ACTVLOW | \ - self.__ADS1015_REG_CONFIG_CMODE_TRAD | \ - self.__ADS1115_REG_CONFIG_DR_250SPS | \ - self.__ADS1015_REG_CONFIG_MODE_SINGLE - - # Set PGA/voltage range to max value (+/- 6.144V) - config |= self.__ADS1015_REG_CONFIG_PGA_6_144V - - if channel == 3: - config |= self.__ADS1015_REG_CONFIG_MUX_SINGLE_3 - elif channel == 2: - config |= self.__ADS1015_REG_CONFIG_MUX_SINGLE_2 - elif channel == 1: - config |= self.__ADS1015_REG_CONFIG_MUX_SINGLE_1 - else: - config |= self.__ADS1015_REG_CONFIG_MUX_SINGLE_0 - - # Set 'start single-conversion' bit - config |= self.__ADS1015_REG_CONFIG_OS_SINGLE - - # Write config register to the ADC - bytes = [(config >> 8) & 0xFF, config & 0xFF] - self.i2c.writeList(self.__ADS1015_REG_POINTER_CONFIG, bytes) - - # Wait for the ADC conversion to complete - if (self.ic == self.__IC_ADS1015): - time.sleep(0.001) - else: - time.sleep(0.008) - - # Read the conversion results - result = self.i2c.readList(self.__ADS1015_REG_POINTER_CONVERT, 2) - if (self.ic == self.__IC_ADS1015): - # Shift right 4 bits for the 12-bit ADS1015 - return ( ((result[0] << 8) | (result[1] & 0xFF)) >> 4 ) - else: - # Return 16-bit value for the ADS1115 - # (Take signed values into account as well) - val = (result[0] << 8) | (result[1]) - if val > 0x7FFF: - return val - 0xFFFF - else: - return (result[0] << 8) | (result[1]) - - def readADCDifferential01(self): - "Gets a differential ADC reading from channels 0 and 1" - - def readADCDifferential23(self): - "Gets a differential ADC reading from channels 2 and 3" - - def startSingleEndedComparator(self, channel, threshold): - "Starts the comparator in single-ended mode on the specified channel" - - def getLastConversionResults(self): - "Returns the last ADC conversion result" 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/ads1015_example.py b/Adafruit_ADS1x15/ads1015_example.py deleted file mode 100644 index 2a4d6285..00000000 --- a/Adafruit_ADS1x15/ads1015_example.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/python - -from Adafruit_ADS1x15 import ADS1x15 - -# ============================================================================ -# Example Code -# ============================================================================ -ADS1015 = 0x00 # 12-bit ADC -ADS1115 = 0x01 # 16-bit ADC - -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# ToDo: Change the value below depending on which chip you're using! -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -ADS_Current = ADS1115 - -# Initialise the ADC using the default mode (use default I2C address) -adc = ADS1x15(ic=ADS_Current) - -# Read channel 0 in single-ended mode -result = adc.readADCSingleEnded(0) -if ADS_Current == ADS1015: - # For ADS1015 at max range (+/-6.144V) 1 bit = 3mV (12-bit values) - print "Channel 0 = %.3f V" % (result * 0.003) -else: - # For ADS1115 at max range (+/-6.144V) 1-bit = 0.1875mV (16-bit values) - print "Channel 0 = %.3f V" % (result * 0.0001875) - -# Read channel 1 in single-ended mode -result = adc.readADCSingleEnded(1) -if ADS_Current == ADS1015: - # For ADS1015 at max range (+/-6.144V) 1 bit = 3mV (12-bit values) - print "Channel 1 = %.3f V" % (result * 0.003) -else: - # For ADS1115 at max range (+/-6.144V) 1-bit = 0.1875mV (16-bit values) - print "Channel 1 = %.3f V" % (result * 0.0001875) diff --git a/Adafruit_BMP085/Adafruit_BMP085.py b/Adafruit_BMP085/Adafruit_BMP085.py deleted file mode 100755 index 191be94d..00000000 --- a/Adafruit_BMP085/Adafruit_BMP085.py +++ /dev/null @@ -1,241 +0,0 @@ -#!/usr/bin/python - -import time -from Adafruit_I2C import Adafruit_I2C - -# =========================================================================== -# BMP085 Class -# =========================================================================== - -class BMP085 : - i2c = None - - # Operating Modes - __BMP085_ULTRALOWPOWER = 0 - __BMP085_STANDARD = 1 - __BMP085_HIGHRES = 2 - __BMP085_ULTRAHIGHRES = 3 - - # BMP085 Registers - __BMP085_CAL_AC1 = 0xAA # R Calibration data (16 bits) - __BMP085_CAL_AC2 = 0xAC # R Calibration data (16 bits) - __BMP085_CAL_AC3 = 0xAE # R Calibration data (16 bits) - __BMP085_CAL_AC4 = 0xB0 # R Calibration data (16 bits) - __BMP085_CAL_AC5 = 0xB2 # R Calibration data (16 bits) - __BMP085_CAL_AC6 = 0xB4 # R Calibration data (16 bits) - __BMP085_CAL_B1 = 0xB6 # R Calibration data (16 bits) - __BMP085_CAL_B2 = 0xB8 # R Calibration data (16 bits) - __BMP085_CAL_MB = 0xBA # R Calibration data (16 bits) - __BMP085_CAL_MC = 0xBC # R Calibration data (16 bits) - __BMP085_CAL_MD = 0xBE # R Calibration data (16 bits) - __BMP085_CONTROL = 0xF4 - __BMP085_TEMPDATA = 0xF6 - __BMP085_PRESSUREDATA = 0xF6 - __BMP085_READTEMPCMD = 0x2E - __BMP085_READPRESSURECMD = 0x34 - - # Private Fields - _cal_AC1 = 0 - _cal_AC2 = 0 - _cal_AC3 = 0 - _cal_AC4 = 0 - _cal_AC5 = 0 - _cal_AC6 = 0 - _cal_B1 = 0 - _cal_B2 = 0 - _cal_MB = 0 - _cal_MC = 0 - _cal_MD = 0 - - # Constructor - def __init__(self, address=0x77, mode=1, debug=False): - self.i2c = Adafruit_I2C(address) - - self.address = address - self.debug = debug - # Make sure the specified mode is in the appropriate range - if ((mode < 0) | (mode > 3)): - if (self.debug): - print "Invalid Mode: Using STANDARD by default" - self.mode = self.__BMP085_STANDARD - else: - self.mode = mode - # Read the calibration data - self.readCalibrationData() - - def readCalibrationData(self): - "Reads the calibration data from the IC" - self._cal_AC1 = self.i2c.readS16(self.__BMP085_CAL_AC1) # INT16 - self._cal_AC2 = self.i2c.readS16(self.__BMP085_CAL_AC2) # INT16 - self._cal_AC3 = self.i2c.readS16(self.__BMP085_CAL_AC3) # INT16 - self._cal_AC4 = self.i2c.readU16(self.__BMP085_CAL_AC4) # UINT16 - self._cal_AC5 = self.i2c.readU16(self.__BMP085_CAL_AC5) # UINT16 - self._cal_AC6 = self.i2c.readU16(self.__BMP085_CAL_AC6) # UINT16 - self._cal_B1 = self.i2c.readS16(self.__BMP085_CAL_B1) # INT16 - self._cal_B2 = self.i2c.readS16(self.__BMP085_CAL_B2) # INT16 - self._cal_MB = self.i2c.readS16(self.__BMP085_CAL_MB) # INT16 - self._cal_MC = self.i2c.readS16(self.__BMP085_CAL_MC) # INT16 - self._cal_MD = self.i2c.readS16(self.__BMP085_CAL_MD) # INT16 - if (self.debug): - self.showCalibrationData() - - def showCalibrationData(self): - "Displays the calibration values for debugging purposes" - print "DBG: AC1 = %6d" % (self._cal_AC1) - print "DBG: AC2 = %6d" % (self._cal_AC2) - print "DBG: AC3 = %6d" % (self._cal_AC3) - print "DBG: AC4 = %6d" % (self._cal_AC4) - print "DBG: AC5 = %6d" % (self._cal_AC5) - print "DBG: AC6 = %6d" % (self._cal_AC6) - print "DBG: B1 = %6d" % (self._cal_B1) - print "DBG: B2 = %6d" % (self._cal_B2) - print "DBG: MB = %6d" % (self._cal_MB) - print "DBG: MC = %6d" % (self._cal_MC) - print "DBG: MD = %6d" % (self._cal_MD) - - def readRawTemp(self): - "Reads the raw (uncompensated) temperature from the sensor" - self.i2c.write8(self.__BMP085_CONTROL, self.__BMP085_READTEMPCMD) - time.sleep(0.005) # Wait 5ms - raw = self.i2c.readU16(self.__BMP085_TEMPDATA) - if (self.debug): - print "DBG: Raw Temp: 0x%04X (%d)" % (raw & 0xFFFF, raw) - return raw - - def readRawPressure(self): - "Reads the raw (uncompensated) pressure level from the sensor" - self.i2c.write8(self.__BMP085_CONTROL, self.__BMP085_READPRESSURECMD + (self.mode << 6)) - if (self.mode == self.__BMP085_ULTRALOWPOWER): - time.sleep(0.005) - elif (self.mode == self.__BMP085_HIGHRES): - time.sleep(0.014) - elif (self.mode == self.__BMP085_ULTRAHIGHRES): - time.sleep(0.026) - else: - time.sleep(0.008) - msb = self.i2c.readU8(self.__BMP085_PRESSUREDATA) - lsb = self.i2c.readU8(self.__BMP085_PRESSUREDATA+1) - xlsb = self.i2c.readU8(self.__BMP085_PRESSUREDATA+2) - raw = ((msb << 16) + (lsb << 8) + xlsb) >> (8 - self.mode) - if (self.debug): - print "DBG: Raw Pressure: 0x%04X (%d)" % (raw & 0xFFFF, raw) - return raw - - def readTemperature(self): - "Gets the compensated temperature in degrees celcius" - UT = 0 - X1 = 0 - X2 = 0 - B5 = 0 - temp = 0.0 - - # Read raw temp before aligning it with the calibration values - UT = self.readRawTemp() - X1 = ((UT - self._cal_AC6) * self._cal_AC5) >> 15 - X2 = (self._cal_MC << 11) / (X1 + self._cal_MD) - B5 = X1 + X2 - temp = ((B5 + 8) >> 4) / 10.0 - if (self.debug): - print "DBG: Calibrated temperature = %f C" % temp - return temp - - def readPressure(self): - "Gets the compensated pressure in pascal" - UT = 0 - UP = 0 - B3 = 0 - B5 = 0 - B6 = 0 - X1 = 0 - X2 = 0 - X3 = 0 - p = 0 - B4 = 0 - B7 = 0 - - UT = self.readRawTemp() - UP = self.readRawPressure() - - # You can use the datasheet values to test the conversion results - # dsValues = True - dsValues = False - - if (dsValues): - UT = 27898 - UP = 23843 - self._cal_AC6 = 23153 - self._cal_AC5 = 32757 - self._cal_MC = -8711 - self._cal_MD = 2868 - self._cal_B1 = 6190 - self._cal_B2 = 4 - self._cal_AC3 = -14383 - self._cal_AC2 = -72 - self._cal_AC1 = 408 - self._cal_AC4 = 32741 - self.mode = self.__BMP085_ULTRALOWPOWER - if (self.debug): - self.showCalibrationData() - - # True Temperature Calculations - X1 = ((UT - self._cal_AC6) * self._cal_AC5) >> 15 - X2 = (self._cal_MC << 11) / (X1 + self._cal_MD) - B5 = X1 + X2 - if (self.debug): - print "DBG: X1 = %d" % (X1) - print "DBG: X2 = %d" % (X2) - print "DBG: B5 = %d" % (B5) - print "DBG: True Temperature = %.2f C" % (((B5 + 8) >> 4) / 10.0) - - # Pressure Calculations - B6 = B5 - 4000 - X1 = (self._cal_B2 * (B6 * B6) >> 12) >> 11 - X2 = (self._cal_AC2 * B6) >> 11 - X3 = X1 + X2 - B3 = (((self._cal_AC1 * 4 + X3) << self.mode) + 2) / 4 - if (self.debug): - print "DBG: B6 = %d" % (B6) - print "DBG: X1 = %d" % (X1) - print "DBG: X2 = %d" % (X2) - print "DBG: B3 = %d" % (B3) - - X1 = (self._cal_AC3 * B6) >> 13 - X2 = (self._cal_B1 * ((B6 * B6) >> 12)) >> 16 - X3 = ((X1 + X2) + 2) >> 2 - B4 = (self._cal_AC4 * (X3 + 32768)) >> 15 - B7 = (UP - B3) * (50000 >> self.mode) - if (self.debug): - print "DBG: X1 = %d" % (X1) - print "DBG: X2 = %d" % (X2) - print "DBG: B4 = %d" % (B4) - print "DBG: B7 = %d" % (B7) - - if (B7 < 0x80000000): - p = (B7 * 2) / B4 - else: - p = (B7 / B4) * 2 - - X1 = (p >> 8) * (p >> 8) - X1 = (X1 * 3038) >> 16 - X2 = (-7375 * p) >> 16 - if (self.debug): - print "DBG: p = %d" % (p) - print "DBG: X1 = %d" % (X1) - print "DBG: X2 = %d" % (X2) - - p = p + ((X1 + X2 + 3791) >> 4) - if (self.debug): - print "DBG: Pressure = %d Pa" % (p) - - return p - - def readAltitude(self, seaLevelPressure=101325): - "Calculates the altitude in meters" - altitude = 0.0 - pressure = float(self.readPressure()) - altitude = 44330.0 * (1.0 - pow(pressure / seaLevelPressure, 0.1903)) - if (self.debug): - print "DBG: Altitude = %d" % (altitude) - return altitude - - return 0 diff --git a/Adafruit_BMP085/Adafruit_BMP085_example.py b/Adafruit_BMP085/Adafruit_BMP085_example.py deleted file mode 100755 index 5e0d0bef..00000000 --- a/Adafruit_BMP085/Adafruit_BMP085_example.py +++ /dev/null @@ -1,25 +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() -pressure = bmp.readPressure() -altitude = bmp.readAltitude() - -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 100755 index dd2dfa76..00000000 --- a/Adafruit_BMP085/Adafruit_I2C.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/python - -import smbus - -# =========================================================================== -# Adafruit_I2C Base Class -# =========================================================================== - -class Adafruit_I2C : - - def __init__(self, address, bus=smbus.SMBus(0), debug=False): - self.address = address - self.bus = bus - self.debug = debug - - def reverseByteOrder(self, data): - "Reverses the byte order of an int (16-bit) or long (32-bit) value" - # Courtesy Vishal Sapre - dstr = hex(data)[2:].replace('L','') - byteCount = len(dstr[::2]) - val = 0 - for i, n in enumerate(range(byteCount)): - d = data & 0xFF - val |= (d << (8 * (byteCount - i - 1))) - data >>= 8 - return val - - def write8(self, reg, value): - "Writes an 8-bit value to the specified register/address" - try: - self.bus.write_byte_data(self.address, reg, value) - if (self.debug): - print("I2C: Wrote 0x%02X to register 0x%02X" % (value, reg)) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def writeList(self, reg, list): - "Writes an array of bytes using I2C format" - try: - self.bus.write_i2c_block_data(self.address, reg, list) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU8(self, reg): - "Read an unsigned byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS8(self, reg): - "Reads a signed byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - if (result > 127): - return result - 256 - else: - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU16(self, reg): - "Reads an unsigned 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS16(self, reg): - "Reads a signed 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - if (hibyte > 127): - hibyte -= 256 - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 diff --git a/Adafruit_CharLCD/Adafruit_CharLCD.py b/Adafruit_CharLCD/Adafruit_CharLCD.py deleted file mode 100755 index 22060c94..00000000 --- a/Adafruit_CharLCD/Adafruit_CharLCD.py +++ /dev/null @@ -1,261 +0,0 @@ -#!/usr/bin/python - -# -# based on code from lrvick and LiquidCrystal -# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py -# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp -# - -from time import sleep - -class Adafruit_CharLCD: - - # commands - LCD_CLEARDISPLAY = 0x01 - LCD_RETURNHOME = 0x02 - LCD_ENTRYMODESET = 0x04 - LCD_DISPLAYCONTROL = 0x08 - LCD_CURSORSHIFT = 0x10 - LCD_FUNCTIONSET = 0x20 - LCD_SETCGRAMADDR = 0x40 - LCD_SETDDRAMADDR = 0x80 - - # flags for display entry mode - LCD_ENTRYRIGHT = 0x00 - LCD_ENTRYLEFT = 0x02 - LCD_ENTRYSHIFTINCREMENT = 0x01 - LCD_ENTRYSHIFTDECREMENT = 0x00 - - # flags for display on/off control - LCD_DISPLAYON = 0x04 - LCD_DISPLAYOFF = 0x00 - LCD_CURSORON = 0x02 - LCD_CURSOROFF = 0x00 - LCD_BLINKON = 0x01 - LCD_BLINKOFF = 0x00 - - # flags for display/cursor shift - LCD_DISPLAYMOVE = 0x08 - LCD_CURSORMOVE = 0x00 - - # flags for display/cursor shift - LCD_DISPLAYMOVE = 0x08 - LCD_CURSORMOVE = 0x00 - LCD_MOVERIGHT = 0x04 - LCD_MOVELEFT = 0x00 - - # flags for function set - LCD_8BITMODE = 0x10 - LCD_4BITMODE = 0x00 - LCD_2LINE = 0x08 - LCD_1LINE = 0x00 - LCD_5x10DOTS = 0x04 - LCD_5x8DOTS = 0x00 - - - - def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None): - # Emulate the old behavior of using RPi.GPIO if we haven't been given - # an explicit GPIO interface to use - if not GPIO: - import RPi.GPIO as GPIO - self.GPIO = GPIO - self.pin_rs = pin_rs - self.pin_e = pin_e - self.pins_db = pins_db - - self.GPIO.setmode(GPIO.BCM) - self.GPIO.setup(self.pin_e, GPIO.OUT) - self.GPIO.setup(self.pin_rs, GPIO.OUT) - - for pin in self.pins_db: - self.GPIO.setup(pin, GPIO.OUT) - - self.write4bits(0x33) # initialization - self.write4bits(0x32) # initialization - self.write4bits(0x28) # 2 line 5x7 matrix - self.write4bits(0x0C) # turn cursor off 0x0E to enable cursor - self.write4bits(0x06) # shift cursor right - - self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF - - self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS - self.displayfunction |= self.LCD_2LINE - - """ Initialize to default text direction (for romance languages) """ - self.displaymode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) # set the entry mode - - self.clear() - - - def begin(self, cols, lines): - - if (lines > 1): - self.numlines = lines - self.displayfunction |= self.LCD_2LINE - self.currline = 0 - - - def home(self): - - self.write4bits(self.LCD_RETURNHOME) # set cursor position to zero - self.delayMicroseconds(3000) # this command takes a long time! - - - def clear(self): - - self.write4bits(self.LCD_CLEARDISPLAY) # command to clear display - self.delayMicroseconds(3000) # 3000 microsecond sleep, clearing the display takes a long time - - - def setCursor(self, col, row): - - self.row_offsets = [ 0x00, 0x40, 0x14, 0x54 ] - - if ( row > self.numlines ): - row = self.numlines - 1 # we count rows starting w/0 - - self.write4bits(self.LCD_SETDDRAMADDR | (col + self.row_offsets[row])) - - - def noDisplay(self): - """ Turn the display off (quickly) """ - - self.displaycontrol &= ~self.LCD_DISPLAYON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - - def display(self): - """ Turn the display on (quickly) """ - - self.displaycontrol |= self.LCD_DISPLAYON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - - def noCursor(self): - """ Turns the underline cursor on/off """ - - self.displaycontrol &= ~self.LCD_CURSORON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - - def cursor(self): - """ Cursor On """ - - self.displaycontrol |= self.LCD_CURSORON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - - def noBlink(self): - """ Turn on and off the blinking cursor """ - - self.displaycontrol &= ~self.LCD_BLINKON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - - def noBlink(self): - """ Turn on and off the blinking cursor """ - - self.displaycontrol &= ~self.LCD_BLINKON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - - def DisplayLeft(self): - """ These commands scroll the display without changing the RAM """ - - self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVELEFT) - - - def scrollDisplayRight(self): - """ These commands scroll the display without changing the RAM """ - - self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVERIGHT); - - - def leftToRight(self): - """ This is for text that flows Left to Right """ - - self.displaymode |= self.LCD_ENTRYLEFT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode); - - - def rightToLeft(self): - """ This is for text that flows Right to Left """ - self.displaymode &= ~self.LCD_ENTRYLEFT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) - - - def autoscroll(self): - """ This will 'right justify' text from the cursor """ - - self.displaymode |= self.LCD_ENTRYSHIFTINCREMENT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) - - - def noAutoscroll(self): - """ This will 'left justify' text from the cursor """ - - self.displaymode &= ~self.LCD_ENTRYSHIFTINCREMENT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) - - - def write4bits(self, bits, char_mode=False): - """ Send command to LCD """ - - self.delayMicroseconds(1000) # 1000 microsecond sleep - - bits=bin(bits)[2:].zfill(8) - - self.GPIO.output(self.pin_rs, char_mode) - - for pin in self.pins_db: - self.GPIO.output(pin, False) - - for i in range(4): - if bits[i] == "1": - self.GPIO.output(self.pins_db[::-1][i], True) - - self.pulseEnable() - - for pin in self.pins_db: - self.GPIO.output(pin, False) - - for i in range(4,8): - if bits[i] == "1": - self.GPIO.output(self.pins_db[::-1][i-4], True) - - self.pulseEnable() - - - def delayMicroseconds(self, microseconds): - seconds = microseconds / float(1000000) # divide microseconds by 1 million for seconds - sleep(seconds) - - - def pulseEnable(self): - self.GPIO.output(self.pin_e, False) - self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns - self.GPIO.output(self.pin_e, True) - self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns - self.GPIO.output(self.pin_e, False) - self.delayMicroseconds(1) # commands need > 37us to settle - - - def message(self, text): - """ Send string to LCD. Newline wraps to second line""" - - for char in text: - if char == '\n': - self.write4bits(0xC0) # next line - else: - self.write4bits(ord(char),True) - - -if __name__ == '__main__': - - lcd = Adafruit_CharLCD() - - lcd.clear() - lcd.message(" Adafruit 16x2\n Standard LCD") - diff --git a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py deleted file mode 100755 index d3f6958f..00000000 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ /dev/null @@ -1,24 +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_CharLCDPlate/Adafruit_CharLCDPlate.py b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py deleted file mode 100644 index 12e4cdf8..00000000 --- a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py +++ /dev/null @@ -1,303 +0,0 @@ -#!/usr/bin/pythonhttp://raspberrypi.local/editor - -# -# based on code from lrvick and LiquidCrystal -# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py -# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp -# - -from time import sleep -from Adafruit_I2C import Adafruit_I2C -from Adafruit_MCP230xx import Adafruit_MCP230XX -import smbus - - -class Adafruit_CharLCDPlate: - - OUTPUT = 0 - INPUT = 1 - - # LED colors - RED = 0x01 - GREEN = 0x02 - BLUE = 0x04 - YELLOW = 0x03 - TEAL = 0x06 - VIOLET = 0x05 - ON = 0x07 - OFF = 0x0 - - # buttons - SELECT = 0 - RIGHT = 1 - DOWN = 2 - UP = 3 - LEFT = 4 - - # commands - LCD_CLEARDISPLAY = 0x01 - LCD_RETURNHOME = 0x02 - LCD_ENTRYMODESET = 0x04 - LCD_DISPLAYCONTROL = 0x08 - LCD_CURSORSHIFT = 0x10 - LCD_FUNCTIONSET = 0x20 - LCD_SETCGRAMADDR = 0x40 - LCD_SETDDRAMADDR = 0x80 - - # flags for display entry mode - LCD_ENTRYRIGHT = 0x00 - LCD_ENTRYLEFT = 0x02 - LCD_ENTRYSHIFTINCREMENT = 0x01 - LCD_ENTRYSHIFTDECREMENT = 0x00 - - # flags for display on/off control - LCD_DISPLAYON = 0x04 - LCD_DISPLAYOFF = 0x00 - LCD_CURSORON = 0x02 - LCD_CURSOROFF = 0x00 - LCD_BLINKON = 0x01 - LCD_BLINKOFF = 0x00 - - # flags for display/cursor shift - LCD_DISPLAYMOVE = 0x08 - LCD_CURSORMOVE = 0x00 - - # flags for display/cursor shift - LCD_DISPLAYMOVE = 0x08 - LCD_CURSORMOVE = 0x00 - LCD_MOVERIGHT = 0x04 - LCD_MOVELEFT = 0x00 - - # flags for function set - LCD_8BITMODE = 0x10 - LCD_4BITMODE = 0x00 - LCD_2LINE = 0x08 - LCD_1LINE = 0x00 - LCD_5x10DOTS = 0x04 - LCD_5x8DOTS = 0x00 - - - - - def __init__(self, busnum=0, pin_rs=15, pin_e=13, pins_db=[12, 11, 10, 9], pin_rw=14): - self.pin_rs = pin_rs - self.pin_e = pin_e - self.pin_rw = pin_rw - self.pins_db = pins_db - - self.mcp = Adafruit_MCP230XX(busnum = busnum, address = 0x20, num_gpios = 16) - - self.mcp.config(self.pin_e, self.OUTPUT) - self.mcp.config(self.pin_rs, self.OUTPUT) - self.mcp.config(self.pin_rw, self.OUTPUT) - self.mcp.output(self.pin_rw, 0) - self.mcp.output(self.pin_e, 0) - - for pin in self.pins_db: - self.mcp.config(pin, self.OUTPUT) - - self.write4bits(0x33) # initialization - self.write4bits(0x32) # initialization - self.write4bits(0x28) # 2 line 5x7 matrix - self.write4bits(0x0C) # turn cursor off 0x0E to enable cursor - self.write4bits(0x06) # shift cursor right - - self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF - - self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS - self.displayfunction |= self.LCD_2LINE - - """ Initialize to default text direction (for romance languages) """ - self.displaymode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) # set the entry mode - - # turn on backlights! - self.mcp.config(6, self.mcp.OUTPUT) - self.mcp.config(7, self.mcp.OUTPUT) - self.mcp.config(8, self.mcp.OUTPUT) - self.mcp.output(6, 0) # red - self.mcp.output(7, 0) # green - self.mcp.output(8, 0) # blue - - # turn on pullups - self.mcp.pullup(self.SELECT, True) - self.mcp.pullup(self.LEFT, True) - self.mcp.pullup(self.RIGHT, True) - self.mcp.pullup(self.UP, True) - self.mcp.pullup(self.DOWN, True) - self.mcp.config(self.SELECT, self.mcp.INPUT) - self.mcp.config(self.LEFT, self.mcp.INPUT) - self.mcp.config(self.RIGHT, self.mcp.INPUT) - self.mcp.config(self.DOWN, self.mcp.INPUT) - self.mcp.config(self.UP, self.mcp.INPUT) - - def begin(self, cols, lines): - if (lines > 1): - self.numlines = lines - self.displayfunction |= self.LCD_2LINE - self.currline = 0 - self.clear() - - def home(self): - self.write4bits(self.LCD_RETURNHOME) # set cursor position to zero - self.delayMicroseconds(2000) # this command takes a long time! - - def clear(self): - self.write4bits(self.LCD_CLEARDISPLAY) # command to clear display - self.delayMicroseconds(2000) # 2000 microsecond sleep, clearing the display takes a long time - - def setCursor(self, col, row): - self.row_offsets = [ 0x00, 0x40, 0x14, 0x54 ] - if ( row > self.numlines ): - row = self.numlines - 1 # we count rows starting w/0 - self.write4bits(self.LCD_SETDDRAMADDR | (col + self.row_offsets[row])) - - def noDisplay(self): - """ Turn the display off (quickly) """ - self.displaycontrol &= ~self.LCD_DISPLAYON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - def display(self): - """ Turn the display on (quickly) """ - self.displaycontrol |= self.LCD_DISPLAYON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - def noCursor(self): - """ Turns the underline cursor on/off """ - self.displaycontrol &= ~self.LCD_CURSORON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - - def cursor(self): - """ Cursor On """ - self.displaycontrol |= self.LCD_CURSORON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - def noBlink(self): - """ Turn on and off the blinking cursor """ - self.displaycontrol &= ~self.LCD_BLINKON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - def noBlink(self): - """ Turn on and off the blinking cursor """ - self.displaycontrol &= ~self.LCD_BLINKON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - - def DisplayLeft(self): - """ These commands scroll the display without changing the RAM """ - self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVELEFT) - - def scrollDisplayRight(self): - """ These commands scroll the display without changing the RAM """ - self.write4bits(self.LCD_CURSORSHIFT | self.LCD_DISPLAYMOVE | self.LCD_MOVERIGHT); - - def leftToRight(self): - """ This is for text that flows Left to Right """ - self.displaymode |= self.LCD_ENTRYLEFT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode); - - def rightToLeft(self): - """ This is for text that flows Right to Left """ - self.displaymode &= ~self.LCD_ENTRYLEFT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) - - def autoscroll(self): - """ This will 'right justify' text from the cursor """ - self.displaymode |= self.LCD_ENTRYSHIFTINCREMENT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) - - def noAutoscroll(self): - """ This will 'left justify' text from the cursor """ - self.displaymode &= ~self.LCD_ENTRYSHIFTINCREMENT - self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) - - def write4bits(self, bits, char_mode=False): - """ Send command to LCD """ - #self.delayMicroseconds(1000) # 1000 microsecond sleep - bits=bin(bits)[2:].zfill(8) - self.mcp.output(self.pin_rs, char_mode) - - for i in range(4): - if bits[i] == "1": - self.mcp.output(self.pins_db[::-1][i], True) - else: - self.mcp.output(self.pins_db[::-1][i], False) - self.pulseEnable() - - for i in range(4,8): - if bits[i] == "1": - self.mcp.output(self.pins_db[::-1][i-4], True) - else: - self.mcp.output(self.pins_db[::-1][i-4], False) - self.pulseEnable() - - def delayMicroseconds(self, microseconds): - seconds = microseconds / 1000000 # divide microseconds by 1 million for seconds - sleep(seconds) - - def pulseEnable(self): - self.mcp.output(self.pin_e, True) - self.delayMicroseconds(1) # 1 microsecond pause - enable pulse must be > 450ns - self.mcp.output(self.pin_e, False) - #self.delayMicroseconds(1) # commands need > 37us to settle - - def message(self, text): - """ Send string to LCD. Newline wraps to second line""" - for char in text: - if char == '\n': - self.write4bits(0xC0) # next line - else: - self.write4bits(ord(char),True) - - def backlight(self, color): - self.mcp.output(6, not color & 0x01) - self.mcp.output(7, not color & 0x02) - self.mcp.output(8, not color & 0x04) - - def buttonPressed(self, buttonname): - if (buttonname > self.LEFT): - return false - - return not self.mcp.input(buttonname) - - -if __name__ == '__main__': - - lcd = Adafruit_CharLCDPlate(busnum = 0) - lcd.clear() - lcd.message("Adafruit RGB LCD\nPlate w/Keypad!") - sleep(1) - while 1: - if (lcd.buttonPressed(lcd.LEFT)): - lcd.backlight(lcd.RED) - - if (lcd.buttonPressed(lcd.UP)): - lcd.backlight(lcd.BLUE) - - if (lcd.buttonPressed(lcd.DOWN)): - lcd.backlight(lcd.GREEN) - - if (lcd.buttonPressed(lcd.RIGHT)): - lcd.backlight(lcd.VIOLET) - - if (lcd.buttonPressed(lcd.SELECT)): - lcd.backlight(lcd.ON) - - - while 1: - lcd.backlight(lcd.RED) - sleep(1) - lcd.backlight(lcd.YELLOW) - sleep(1) - lcd.backlight(lcd.GREEN) - sleep(1) - lcd.backlight(lcd.TEAL) - sleep(1) - lcd.backlight(lcd.BLUE) - sleep(1) - lcd.backlight(lcd.VIOLET) - sleep(1) - lcd.backlight(lcd.ON) - sleep(1) - lcd.backlight(lcd.OFF) - sleep(1) diff --git a/Adafruit_CharLCDPlate/Adafruit_I2C.py b/Adafruit_CharLCDPlate/Adafruit_I2C.py deleted file mode 120000 index f5fcefeb..00000000 --- a/Adafruit_CharLCDPlate/Adafruit_I2C.py +++ /dev/null @@ -1 +0,0 @@ -../../Adafruit-Raspberry-Pi-Python-Code/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 4e89f685..00000000 --- a/Adafruit_CharLCDPlate/Adafruit_MCP230xx.py +++ /dev/null @@ -1 +0,0 @@ -../../Adafruit-Raspberry-Pi-Python-Code/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 3f6177ee..00000000 --- a/Adafruit_CharLCDPlate/LCDtest.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python - -from time import sleep -from Adafruit_I2C import Adafruit_I2C -from Adafruit_MCP230xx import Adafruit_MCP230XX -from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate - -import smbus - - -# initialize the LCD plate -# use busnum = 0 for raspi version 1 (256MB) and busnum = 1 for version 2 -lcd = Adafruit_CharLCDPlate(busnum = 0) - -# clear display -lcd.clear() -# hello! -lcd.message("Adafruit RGB LCD\nPlate w/Keypad!") -sleep(1) - -# first loop, just changes the color -lcd.backlight(lcd.RED) -sleep(.5) -lcd.backlight(lcd.YELLOW) -sleep(.5) -lcd.backlight(lcd.GREEN) -sleep(.5) -lcd.backlight(lcd.TEAL) -sleep(.5) -lcd.backlight(lcd.BLUE) -sleep(.5) -lcd.backlight(lcd.VIOLET) -sleep(.5) -lcd.backlight(lcd.ON) -sleep(.5) -lcd.backlight(lcd.OFF) -sleep(.5) - -while 1: - if (lcd.buttonPressed(lcd.LEFT)): - lcd.clear() - lcd.message("Red Red Wine") - lcd.backlight(lcd.RED) - - if (lcd.buttonPressed(lcd.UP)): - lcd.clear() - lcd.message("Sita Sings \nthe blues") - lcd.backlight(lcd.BLUE) - - if (lcd.buttonPressed(lcd.DOWN)): - lcd.clear() - lcd.message("I see fields\nof green"); - lcd.backlight(lcd.GREEN) - - if (lcd.buttonPressed(lcd.RIGHT)): - lcd.clear() - lcd.message("Purple mountain\n majesties"); - lcd.backlight(lcd.VIOLET) - - if (lcd.buttonPressed(lcd.SELECT)): - lcd.clear() - lcd.backlight(lcd.ON) - - diff --git a/Adafruit_DHT_Driver/Adafruit_DHT b/Adafruit_DHT_Driver/Adafruit_DHT deleted file mode 100755 index 40f4c416..00000000 Binary files a/Adafruit_DHT_Driver/Adafruit_DHT and /dev/null differ diff --git a/Adafruit_DHT_Driver/Adafruit_DHT.c b/Adafruit_DHT_Driver/Adafruit_DHT.c deleted file mode 100644 index 9d1746be..00000000 --- a/Adafruit_DHT_Driver/Adafruit_DHT.c +++ /dev/null @@ -1,148 +0,0 @@ -// How to access GPIO registers from C-code on the Raspberry-Pi -// Example program -// 15-January-2012 -// Dom and Gert -// - - -// Access from ARM Running Linux - -#define BCM2708_PERI_BASE 0x20000000 -#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAXTIMINGS 100 - -//#define DEBUG - -#define DHT11 11 -#define DHT22 22 -#define AM2302 22 - -int readDHT(int type, int pin); - -int main(int argc, char **argv) -{ - if (!bcm2835_init()) - return 1; - - if (argc != 3) { - printf("usage: %s [11|22|2302] GPIOpin#\n", argv[0]); - printf("example: %s 2302 4 - Read from an AM2302 connected to GPIO #4\n", argv[0]); - return 2; - } - int type = 0; - if (strcmp(argv[1], "11") == 0) type = DHT11; - if (strcmp(argv[1], "22") == 0) type = DHT22; - if (strcmp(argv[1], "2302") == 0) type = AM2302; - if (type == 0) { - printf("Select 11, 22, 2302 as type!\n"); - return 3; - } - - int dhtpin = atoi(argv[2]); - - if (dhtpin <= 0) { - printf("Please select a valid GPIO pin #\n"); - return 3; - } - - - printf("Using pin #%d\n", dhtpin); - readDHT(type, dhtpin); - return 0; - -} // main - - -int bits[250], data[100]; -int bitidx = 0; - -int readDHT(int type, int pin) { - int counter = 0; - int laststate = HIGH; - int j=0; - - // Set GPIO pin to output - bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP); - - bcm2835_gpio_write(pin, HIGH); - usleep(500000); // 500 ms - bcm2835_gpio_write(pin, LOW); - usleep(20000); - - bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_INPT); - - data[0] = data[1] = data[2] = data[3] = data[4] = 0; - - // wait for pin to drop? - while (bcm2835_gpio_lev(pin) == 1) { - usleep(1); - } - - // read data! - for (int i=0; i< MAXTIMINGS; i++) { - counter = 0; - while ( bcm2835_gpio_lev(pin) == laststate) { - counter++; - //nanosleep(1); // overclocking might change this? - if (counter == 1000) - break; - } - laststate = bcm2835_gpio_lev(pin); - if (counter == 1000) break; - bits[bitidx++] = counter; - - if ((i>3) && (i%2 == 0)) { - // shove each bit into the storage bytes - data[j/8] <<= 1; - if (counter > 200) - data[j/8] |= 1; - j++; - } - } - - -#ifdef DEBUG - for (int i=3; i 200); - } -#endif - - printf("Data (%d): 0x%x 0x%x 0x%x 0x%x 0x%x\n", j, data[0], data[1], data[2], data[3], data[4]); - - if ((j >= 39) && - (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) ) { - // yay! - if (type == DHT11) - printf("Temp = %d *C, Hum = %d \%\n", data[2], data[0]); - if (type == DHT22) { - float f, h; - h = data[0] * 256 + data[1]; - h /= 10; - - f = (data[2] & 0x7F)* 256 + data[3]; - f /= 10.0; - if (data[2] & 0x80) f *= -1; - printf("Temp = %.1f *C, Hum = %.1f \%\n", f, h); - } - return 1; - } - - return 0; -} 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 c13d3033..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') -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_DHT_Driver/Makefile b/Adafruit_DHT_Driver/Makefile deleted file mode 100644 index 5a91e391..00000000 --- a/Adafruit_DHT_Driver/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CC = gcc -CFLAGS = -std=c99 -I. -lbcm2835 -DEPS = -OBJ = Adafruit_DHT.o - -%.o: %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) - -Adafruit_DHT: $(OBJ) - gcc -o $@ $^ $(CFLAGS) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py deleted file mode 100755 index d0416529..00000000 --- a/Adafruit_I2C/Adafruit_I2C.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/python - -import smbus - -# =========================================================================== -# Adafruit_I2C Base Class -# =========================================================================== - -class Adafruit_I2C : - - def getPiRevision(): - "Gets the version number of the Raspberry Pi board" - # Courtesy quick2wire-python-api - # https://github.com/quick2wire/quick2wire-python-api - try: - with open('/proc/cpuinfo','r') as f: - for line in f: - if line.startswith('Revision'): - return 1 if line.rstrip()[-1] in ['1','2'] else 2 - except: - return 0 - - def __init__(self, address, bus=smbus.SMBus(1 if getPiRevision() > 1 else 0), debug=False): - self.address = address - # By default, the correct I2C bus is auto-detected using /proc/cpuinfo - self.bus = bus - # Alternatively, you can hard-code the bus version below: - # self.bus = smbus.SMBus(0); # Force I2C0 (early 256MB Pi's) - # self.bus = smbus.SMBus(1); # Force I2C1 (512MB Pi's) - self.debug = debug - - def reverseByteOrder(self, data): - "Reverses the byte order of an int (16-bit) or long (32-bit) value" - # Courtesy Vishal Sapre - dstr = hex(data)[2:].replace('L','') - byteCount = len(dstr[::2]) - val = 0 - for i, n in enumerate(range(byteCount)): - d = data & 0xFF - val |= (d << (8 * (byteCount - i - 1))) - data >>= 8 - return val - - def write8(self, reg, value): - "Writes an 8-bit value to the specified register/address" - try: - self.bus.write_byte_data(self.address, reg, value) - if (self.debug): - print "I2C: Wrote 0x%02X to register 0x%02X" % (value, reg) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def writeList(self, reg, list): - "Writes an array of bytes using I2C format" - try: - if (self.debug): - print "I2C: Writing list to register 0x%02X:" % reg - print list - self.bus.write_i2c_block_data(self.address, reg, list) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readList(self, reg, length): - "Read a list of bytes from the I2C device" - results = [] - try: - results = self.bus.read_i2c_block_data(self.address, reg, length) - if (self.debug): - print "I2C: Device 0x%02X returned the following from reg 0x%02X" % (self.address, reg) - print results - return results - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU8(self, reg): - "Read an unsigned byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS8(self, reg): - "Reads a signed byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - if (result > 127): - return result - 256 - else: - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU16(self, reg): - "Reads an unsigned 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS16(self, reg): - "Reads a signed 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - if (hibyte > 127): - hibyte -= 256 - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 diff --git a/Adafruit_LEDBackpack/Adafruit_7Segment.py b/Adafruit_LEDBackpack/Adafruit_7Segment.py deleted file mode 100644 index f5965404..00000000 --- a/Adafruit_LEDBackpack/Adafruit_7Segment.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/python - -import time -import datetime -from Adafruit_LEDBackpack import LEDBackpack - -# =========================================================================== -# 7-Segment Display -# =========================================================================== - -# This class is meant to be used with the four-character, seven segment -# displays available from Adafruit - -class SevenSegment: - disp = None - - # Hexadecimal character lookup table (row 1 = 0..9, row 2 = A..F) - digits = [ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, \ - 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 ] - - # Constructor - def __init__(self, address=0x70, debug=False): - if (debug): - print "Initializing a new instance of LEDBackpack at 0x%02X" % address - self.disp = LEDBackpack(address=address, debug=debug) - - def writeDigitRaw(self, charNumber, value): - "Sets a digit using the raw 16-bit value" - if (charNumber > 7): - return - # Set the appropriate digit - self.disp.setBufferRow(charNumber, value) - - def writeDigit(self, charNumber, value, dot=False): - "Sets a single decimal or hexademical value (0..9 and A..F)" - if (charNumber > 7): - return - if (value > 0xF): - return - # Set the appropriate digit - self.disp.setBufferRow(charNumber, self.digits[value] | (dot << 7)) - - def setColon(self, state=True): - "Enables or disables the colon character" - # Warning: This function assumes that the colon is character '2', - # which is the case on 4 char displays, but may need to be modified - # if another display type is used - if (state): - self.disp.setBufferRow(2, 0xFFFF) - else: - self.disp.setBufferRow(2, 0) - diff --git a/Adafruit_LEDBackpack/Adafruit_8x8.py b/Adafruit_LEDBackpack/Adafruit_8x8.py deleted file mode 100644 index c9f54d1b..00000000 --- a/Adafruit_LEDBackpack/Adafruit_8x8.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/python - -import time -import datetime -from Adafruit_LEDBackpack import LEDBackpack - -# =========================================================================== -# 8x8 Pixel Display -# =========================================================================== - -class EightByEight: - disp = None - - # Constructor - def __init__(self, address=0x70, debug=False): - if (debug): - print "Initializing a new instance of LEDBackpack at 0x%02X" % address - self.disp = LEDBackpack(address=address, debug=debug) - - def writeRowRaw(self, charNumber, value): - "Sets a row of pixels using a raw 16-bit value" - if (charNumber > 7): - return - # Set the appropriate row - self.disp.setBufferRow(charNumber, value) - - def clearPixel(self, x, y): - "A wrapper function to clear pixels (purely cosmetic)" - self.setPixel(x, y, 0) - - def setPixel(self, x, y, color=1): - "Sets a single pixel" - if (x >= 8): - return - if (y >= 8): - return - x += 7 - x %= 8 - # Set the appropriate pixel - buffer = self.disp.getBuffer() - if (color): - self.disp.setBufferRow(y, buffer[y] | 1 << x) - else: - self.disp.setBufferRow(y, buffer[y] & ~(1 << x)) - - def clear(self): - "Clears the entire display" - self.disp.clear() - 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/Adafruit_LEDBackpack.py b/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py deleted file mode 100644 index a0c58295..00000000 --- a/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/python - -import time -from copy import copy -from Adafruit_I2C import Adafruit_I2C - -# ============================================================================ -# LEDBackpack Class -# ============================================================================ - -class LEDBackpack: - i2c = None - - # Registers - __HT16K33_REGISTER_DISPLAY_SETUP = 0x80 - __HT16K33_REGISTER_SYSTEM_SETUP = 0x20 - __HT16K33_REGISTER_DIMMING = 0xE0 - - # Blink rate - __HT16K33_BLINKRATE_OFF = 0x00 - __HT16K33_BLINKRATE_2HZ = 0x01 - __HT16K33_BLINKRATE_1HZ = 0x02 - __HT16K33_BLINKRATE_HALFHZ = 0x03 - - # Display buffer (8x16-bits) - __buffer = [0x0000, 0x0000, 0x0000, 0x0000, \ - 0x0000, 0x0000, 0x0000, 0x0000 ] - - # Constructor - def __init__(self, address=0x70, debug=False): - self.i2c = Adafruit_I2C(address) - self.address = address - self.debug = debug - - # Turn the oscillator on - self.i2c.write8(self.__HT16K33_REGISTER_SYSTEM_SETUP | 0x01, 0x00) - - # Turn blink off - self.setBlinkRate(self.__HT16K33_BLINKRATE_OFF) - - # Set maximum brightness - self.setBrightness(15) - - # Clear the screen - self.clear() - - def setBrightness(self, brightness): - "Sets the brightness level from 0..15" - if (brightness > 15): - brightness = 15 - self.i2c.write8(self.__HT16K33_REGISTER_DIMMING | brightness, 0x00) - - def setBlinkRate(self, blinkRate): - "Sets the blink rate" - if (blinkRate > self.__HT16K33_BLINKRATE_HALFHZ): - blinkRate = self.__HT16K33_BLINKRATE_OFF - self.i2c.write8(self.__HT16K33_REGISTER_DISPLAY_SETUP | 0x01 | (blinkRate << 1), 0x00) - - def setBufferRow(self, row, value, update=True): - "Updates a single 16-bit entry in the 8*16-bit buffer" - if (row > 7): - return # Prevent buffer overflow - self.__buffer[row] = value # value # & 0xFFFF - if (update): - self.writeDisplay() # Update the display - - def getBuffer(self): - "Returns a copy of the raw buffer contents" - bufferCopy = copy(self.__buffer) - return bufferCopy - - def writeDisplay(self): - "Updates the display memory" - bytes = [] - for item in self.__buffer: - bytes.append(item & 0xFF) - bytes.append((item >> 8) & 0xFF) - self.i2c.writeList(0x00, bytes) - - def clear(self, update=True): - "Clears the display memory" - self.__buffer = [ 0, 0, 0, 0, 0, 0, 0, 0 ] - if (update): - self.writeDisplay() - -led = LEDBackpack(0x70) - diff --git a/Adafruit_LEDBackpack/ex_7segment_clock.py b/Adafruit_LEDBackpack/ex_7segment_clock.py deleted file mode 100644 index 634b6178..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 color - segment.setColon(second % 2) # Toggle colon at 1Hz - # Wait one second - time.sleep(1) 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_LEDpixels/Adafruit_LEDpixels.py b/Adafruit_LEDpixels/Adafruit_LEDpixels.py deleted file mode 100644 index 07e1a953..00000000 --- a/Adafruit_LEDpixels/Adafruit_LEDpixels.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python - -# Test code for Adafruit LED Pixels, uses hardware SPI - -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) - for i in range(8): - if (byteout & 0x80): - GPIO.output(datapin, True) - else: - GPIO.output(clockpin, False) - byteout <<= 1 - 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)): - spidev.write(chr((pixels[i]>>16) & 0xFF)) - spidev.write(chr((pixels[i]>>8) & 0xFF)) - spidev.write(chr(pixels[i] & 0xFF)) - spidev.close() - time.sleep(0.002) - -def Color(r, g, b): - return ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) - -def setpixelcolor(pixels, n, r, g, b): - if (n >= len(pixels)): - return - pixels[n] = Color(r,g,b) - -def setpixelcolor(pixels, n, c): - if (n >= len(pixels)): - return - pixels[n] = c - -def colorwipe(pixels, c, delay): - for i in range(len(pixels)): - setpixelcolor(pixels, i, c) - writestrip(pixels) - time.sleep(delay) - -def Wheel(WheelPos): - if (WheelPos < 85): - return Color(WheelPos * 3, 255 - WheelPos * 3, 0) - elif (WheelPos < 170): - WheelPos -= 85; - return Color(255 - WheelPos * 3, 0, WheelPos * 3) - else: - WheelPos -= 170; - return Color(0, WheelPos * 3, 255 - WheelPos * 3) - -def rainbowCycle(pixels, wait): - for j in range(256): # one cycle of all 256 colors in the wheel - for i in range(len(pixels)): -# tricky math! we use each pixel as a fraction of the full 96-color wheel -# (thats the i / strip.numPixels() part) -# Then add in j which makes the colors go around per pixel -# the % 96 is to make the wheel cycle around - setpixelcolor(pixels, i, Wheel( ((i * 256 / len(pixels)) + j) % 256) ) - 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) 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_MCP230xx/Adafruit_MCP230xx.py b/Adafruit_MCP230xx/Adafruit_MCP230xx.py deleted file mode 100755 index 42565d8d..00000000 --- a/Adafruit_MCP230xx/Adafruit_MCP230xx.py +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/python - -# Copyright 2012 Daniel Berlin (with some changes by Adafruit Industries/Limor Fried) -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal MCP230XX_GPIO(1, 0xin -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is furnished to do -# so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -from Adafruit_I2C import Adafruit_I2C -import smbus -import time - -MCP23017_IODIRA = 0x00 -MCP23017_IODIRB = 0x01 -MCP23017_GPIOA = 0x12 -MCP23017_GPIOB = 0x13 -MCP23017_GPPUA = 0x0C -MCP23017_GPPUB = 0x0D -MCP23017_OLATA = 0x14 -MCP23017_OLATB = 0x15 -MCP23008_GPIOA = 0x09 -MCP23008_GPPUA = 0x06 -MCP23008_OLATA = 0x0A - -class Adafruit_MCP230XX(object): - OUTPUT = 0 - INPUT = 1 - - def __init__(self, address, num_gpios, busnum = 0): - assert num_gpios >= 0 and num_gpios <= 16, "Number of GPIOs must be between 0 and 16" - self.i2c = Adafruit_I2C(address=address, bus=smbus.SMBus(busnum)) - self.address = address - self.num_gpios = num_gpios - - # set defaults - if num_gpios <= 8: - self.i2c.write8(MCP23017_IODIRA, 0xFF) # all inputs on port A - self.direction = self.i2c.readU8(MCP23017_IODIRA) - self.i2c.write8(MCP23008_GPPUA, 0x00) - elif num_gpios > 8 and num_gpios <= 16: - self.i2c.write8(MCP23017_IODIRA, 0xFF) # all inputs on port A - self.i2c.write8(MCP23017_IODIRB, 0xFF) # all inputs on port B - self.direction = self.i2c.readU8(MCP23017_IODIRA) - self.direction |= self.i2c.readU8(MCP23017_IODIRB) << 8 - self.i2c.write8(MCP23017_GPPUA, 0x00) - self.i2c.write8(MCP23017_GPPUB, 0x00) - - def _changebit(self, bitmap, bit, value): - assert value == 1 or value == 0, "Value is %s must be 1 or 0" % value - if value == 0: - return bitmap & ~(1 << bit) - elif value == 1: - return bitmap | (1 << bit) - - def _readandchangepin(self, port, pin, value, currvalue = None): - assert pin >= 0 and pin < self.num_gpios, "Pin number %s is invalid, only 0-%s are valid" % (pin, self.num_gpios) - #assert self.direction & (1 << pin) == 0, "Pin %s not set to output" % pin - if not currvalue: - currvalue = self.i2c.readU8(port) - newvalue = self._changebit(currvalue, pin, value) - self.i2c.write8(port, newvalue) - return newvalue - - - def pullup(self, pin, value): - if self.num_gpios <= 8: - return self._readandchangepin(MCP23008_GPPUA, pin, value) - if self.num_gpios <= 16: - if (pin < 8): - return self._readandchangepin(MCP23017_GPPUA, pin, value) - else: - return self._readandchangepin(MCP23017_GPPUB, pin-8, value) - - # Set pin to either input or output mode - def config(self, pin, mode): - if self.num_gpios <= 8: - self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode) - if self.num_gpios <= 16: - if (pin < 8): - self.direction = self._readandchangepin(MCP23017_IODIRA, pin, mode) - else: - self.direction = self._readandchangepin(MCP23017_IODIRB, pin-8, mode) - - return self.direction - - def output(self, pin, value): - # assert self.direction & (1 << pin) == 0, "Pin %s not set to output" % pin - if self.num_gpios <= 8: - self.outputvalue = self._readandchangepin(MCP23008_GPIOA, pin, value, self.i2c.readU8(MCP23008_OLATA)) - if self.num_gpios <= 16: - if (pin < 8): - self.outputvalue = self._readandchangepin(MCP23017_GPIOA, pin, value, self.i2c.readU8(MCP23017_OLATA)) - else: - self.outputvalue = self._readandchangepin(MCP23017_GPIOB, pin-8, value, self.i2c.readU8(MCP23017_OLATB)) - - return self.outputvalue - - - self.outputvalue = self._readandchangepin(MCP23017_IODIRA, pin, value, self.outputvalue) - return self.outputvalue - - def input(self, pin): - assert pin >= 0 and pin < self.num_gpios, "Pin number %s is invalid, only 0-%s are valid" % (pin, self.num_gpios) - assert self.direction & (1 << pin) != 0, "Pin %s not set to input" % pin - if self.num_gpios <= 8: - value = self.i2c.readU8(MCP23008_GPIOA) - elif self.num_gpios > 8 and self.num_gpios <= 16: - value = self.i2c.readU16(MCP23017_GPIOA) - temp = value >> 8 - value <<= 8 - value |= temp - return value & (1 << pin) - - def readU8(self): - result = self.i2c.readU8(MCP23008_OLATA) - return(result) - - def readS8(self): - result = self.i2c.readU8(MCP23008_OLATA) - if (result > 127): result -= 256 - return result - - def readU16(self): - assert self.num_gpios >= 16, "16bits required" - lo = self.i2c.readU8(MCP23017_OLATA) - hi = self.i2c.readU8(MCP23017_OLATB) - return((hi << 8) | lo) - - def readS16(self): - assert self.num_gpios >= 16, "16bits required" - lo = self.i2c.readU8(MCP23017_OLATA) - hi = self.i2c.readU8(MCP23017_OLATB) - if (hi > 127): hi -= 256 - return((hi << 8) | lo) - - def write8(self, value): - self.i2c.write8(MCP23008_OLATA, value) - - def write16(self, value): - assert self.num_gpios >= 16, "16bits required" - self.i2c.write8(MCP23017_OLATA, value & 0xFF) - self.i2c.write8(MCP23017_OLATB, (value >> 8) & 0xFF) - -# RPi.GPIO compatible interface for MCP23017 and MCP23008 - -class MCP230XX_GPIO(object): - OUT = 0 - IN = 1 - BCM = 0 - BOARD = 0 - def __init__(self, busnum, address, num_gpios): - self.chip = Adafruit_MCP230XX(busnum, address, num_gpios) - def setmode(self, mode): - # do nothing - pass - def setup(self, pin, mode): - self.chip.config(pin, mode) - def input(self, pin): - return self.chip.input(pin) - def output(self, pin, value): - self.chip.output(pin, value) - def pullup(self, pin, value): - self.chip.pullup(pin, value) - - -if __name__ == '__main__': - mcp = Adafruit_MCP230XX(address = 0x20, num_gpios = 8) - - # *************************************************** - # Set num_gpios to 8 for MCP23008 or 16 for MCP23017! - # If you have a new Pi you may also need to add: - # busnum = 1 - # *************************************************** - - # Set pins 0, 1 and 2 to output (you can set pins 0..15 this way) - mcp.config(0, mcp.OUTPUT) - mcp.config(1, mcp.OUTPUT) - mcp.config(2, mcp.OUTPUT) - - # Set pin 3 to input with the pullup resistor enabled - mcp.pullup(3, 1) - # Read pin 3 and display the results - print "%d: %x" % (3, mcp.input(3) >> 3) - - # Python speed test on output 0 toggling at max speed - while (True): - mcp.output(0, 1) # Pin 0 High - mcp.output(0, 0) # Pin 0 Low diff --git a/Adafruit_MCP3008/mcp3008.py b/Adafruit_MCP3008/mcp3008.py deleted file mode 100644 index a1678a7b..00000000 --- a/Adafruit_MCP3008/mcp3008.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python - -# just some bitbang code for testing all 8 channels - -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) - GPIO.setup(datapin, GPIO.OUT) - for i in range(8): - if (byteout & 0x80): - GPIO.output(datapin, True) - else: - GPIO.output(datapin, False) - byteout <<= 1 - GPIO.output(clockpin, True) - GPIO.output(clockpin, False) - -# this function is not used, its for future reference! -def slowspiread(clockpin, datapin): - GPIO.setup(clockpin, GPIO.OUT) - GPIO.setup(datapin, GPIO.IN) - byteout = 0 - for i in range(8): - GPIO.output(clockpin, False) - GPIO.output(clockpin, True) - byteout <<= 1 - if (GPIO.input(datapin)): - byteout = byteout | 0x1 - return byteout - -# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7) -def readadc(adcnum, clockpin, mosipin, misopin, cspin): - if ((adcnum > 7) or (adcnum < 0)): - return -1 - GPIO.output(cspin, True) - - GPIO.output(clockpin, False) # start clock low - GPIO.output(cspin, False) # bring CS low - - commandout = adcnum - commandout |= 0x18 # start bit + single-ended bit - commandout <<= 3 # we only need to send 5 bits here - for i in range(5): - if (commandout & 0x80): - GPIO.output(mosipin, True) - else: - GPIO.output(mosipin, False) - commandout <<= 1 - GPIO.output(clockpin, True) - GPIO.output(clockpin, False) - - adcout = 0 - # read in one empty bit, one null bit and 10 ADC bits - for i in range(12): - GPIO.output(clockpin, True) - GPIO.output(clockpin, False) - adcout <<= 1 - if (GPIO.input(misopin)): - adcout |= 0x1 - - GPIO.output(cspin, True) - - 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) - -# 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 \t #2 \t #3 \t #4 \t #5 \t #6 \t #7\t|" -print "-----------------------------------------------------------------" -while True: - print "|", - for adcnum in range(8): - ret = readadc(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS) - print ret,"\t", - print "|" diff --git a/Adafruit_MCP4725/Adafruit_I2C.py b/Adafruit_MCP4725/Adafruit_I2C.py deleted file mode 100755 index dd2dfa76..00000000 --- a/Adafruit_MCP4725/Adafruit_I2C.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/python - -import smbus - -# =========================================================================== -# Adafruit_I2C Base Class -# =========================================================================== - -class Adafruit_I2C : - - def __init__(self, address, bus=smbus.SMBus(0), debug=False): - self.address = address - self.bus = bus - self.debug = debug - - def reverseByteOrder(self, data): - "Reverses the byte order of an int (16-bit) or long (32-bit) value" - # Courtesy Vishal Sapre - dstr = hex(data)[2:].replace('L','') - byteCount = len(dstr[::2]) - val = 0 - for i, n in enumerate(range(byteCount)): - d = data & 0xFF - val |= (d << (8 * (byteCount - i - 1))) - data >>= 8 - return val - - def write8(self, reg, value): - "Writes an 8-bit value to the specified register/address" - try: - self.bus.write_byte_data(self.address, reg, value) - if (self.debug): - print("I2C: Wrote 0x%02X to register 0x%02X" % (value, reg)) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def writeList(self, reg, list): - "Writes an array of bytes using I2C format" - try: - self.bus.write_i2c_block_data(self.address, reg, list) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU8(self, reg): - "Read an unsigned byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS8(self, reg): - "Reads a signed byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - if (result > 127): - return result - 256 - else: - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU16(self, reg): - "Reads an unsigned 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS16(self, reg): - "Reads a signed 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - if (hibyte > 127): - hibyte -= 256 - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 diff --git a/Adafruit_MCP4725/Adafruit_MCP4725.py b/Adafruit_MCP4725/Adafruit_MCP4725.py deleted file mode 100755 index 0cd66b20..00000000 --- a/Adafruit_MCP4725/Adafruit_MCP4725.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/python - -from Adafruit_I2C import Adafruit_I2C - -# ============================================================================ -# Adafruit MCP4725 12-Bit DAC -# ============================================================================ - -class MCP4725 : - i2c = None - - # Registers - __REG_WRITEDAC = 0x40 - __REG_WRITEDACEEPROM = 0x60 - - # Constructor - def __init__(self, address=0x62, debug=False): - self.i2c = Adafruit_I2C(address) - self.address = address - self.debug = debug - - def setVoltage(self, voltage, persist=False): - "Sets the output voltage to the specified value" - if (voltage > 4095): - voltage = 4095 - if (voltage < 0): - voltage = 0 - if (self.debug): - print "Setting voltage to %04d" % voltage - # Value needs to be left-shifted four bytes for the MCP4725 - bytes = [(voltage >> 4) & 0xFF, (voltage << 4) & 0xFF] - if (persist): - self.i2c.writeList(self.__REG_WRITEDACEEPROM, bytes) - else: - self.i2c.writeList(self.__REG_WRITEDAC, bytes) diff --git a/Adafruit_MCP4725/sinewave.py b/Adafruit_MCP4725/sinewave.py deleted file mode 100755 index 11928251..00000000 --- a/Adafruit_MCP4725/sinewave.py +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/python - -from Adafruit_MCP4725 import MCP4725 -import time - -# Set this value to 9, 8, 7, 6 or 5 to adjust the resolution -DAC_RESOLUTION = 9 - -# 9-Bit Lookup Table (512 values) -DACLookup_FullSine_9Bit = \ -[ 2048, 2073, 2098, 2123, 2148, 2174, 2199, 2224, - 2249, 2274, 2299, 2324, 2349, 2373, 2398, 2423, - 2448, 2472, 2497, 2521, 2546, 2570, 2594, 2618, - 2643, 2667, 2690, 2714, 2738, 2762, 2785, 2808, - 2832, 2855, 2878, 2901, 2924, 2946, 2969, 2991, - 3013, 3036, 3057, 3079, 3101, 3122, 3144, 3165, - 3186, 3207, 3227, 3248, 3268, 3288, 3308, 3328, - 3347, 3367, 3386, 3405, 3423, 3442, 3460, 3478, - 3496, 3514, 3531, 3548, 3565, 3582, 3599, 3615, - 3631, 3647, 3663, 3678, 3693, 3708, 3722, 3737, - 3751, 3765, 3778, 3792, 3805, 3817, 3830, 3842, - 3854, 3866, 3877, 3888, 3899, 3910, 3920, 3930, - 3940, 3950, 3959, 3968, 3976, 3985, 3993, 4000, - 4008, 4015, 4022, 4028, 4035, 4041, 4046, 4052, - 4057, 4061, 4066, 4070, 4074, 4077, 4081, 4084, - 4086, 4088, 4090, 4092, 4094, 4095, 4095, 4095, - 4095, 4095, 4095, 4095, 4094, 4092, 4090, 4088, - 4086, 4084, 4081, 4077, 4074, 4070, 4066, 4061, - 4057, 4052, 4046, 4041, 4035, 4028, 4022, 4015, - 4008, 4000, 3993, 3985, 3976, 3968, 3959, 3950, - 3940, 3930, 3920, 3910, 3899, 3888, 3877, 3866, - 3854, 3842, 3830, 3817, 3805, 3792, 3778, 3765, - 3751, 3737, 3722, 3708, 3693, 3678, 3663, 3647, - 3631, 3615, 3599, 3582, 3565, 3548, 3531, 3514, - 3496, 3478, 3460, 3442, 3423, 3405, 3386, 3367, - 3347, 3328, 3308, 3288, 3268, 3248, 3227, 3207, - 3186, 3165, 3144, 3122, 3101, 3079, 3057, 3036, - 3013, 2991, 2969, 2946, 2924, 2901, 2878, 2855, - 2832, 2808, 2785, 2762, 2738, 2714, 2690, 2667, - 2643, 2618, 2594, 2570, 2546, 2521, 2497, 2472, - 2448, 2423, 2398, 2373, 2349, 2324, 2299, 2274, - 2249, 2224, 2199, 2174, 2148, 2123, 2098, 2073, - 2048, 2023, 1998, 1973, 1948, 1922, 1897, 1872, - 1847, 1822, 1797, 1772, 1747, 1723, 1698, 1673, - 1648, 1624, 1599, 1575, 1550, 1526, 1502, 1478, - 1453, 1429, 1406, 1382, 1358, 1334, 1311, 1288, - 1264, 1241, 1218, 1195, 1172, 1150, 1127, 1105, - 1083, 1060, 1039, 1017, 995, 974, 952, 931, - 910, 889, 869, 848, 828, 808, 788, 768, - 749, 729, 710, 691, 673, 654, 636, 618, - 600, 582, 565, 548, 531, 514, 497, 481, - 465, 449, 433, 418, 403, 388, 374, 359, - 345, 331, 318, 304, 291, 279, 266, 254, - 242, 230, 219, 208, 197, 186, 176, 166, - 156, 146, 137, 128, 120, 111, 103, 96, - 88, 81, 74, 68, 61, 55, 50, 44, - 39, 35, 30, 26, 22, 19, 15, 12, - 10, 8, 6, 4, 2, 1, 1, 0, - 0, 0, 1, 1, 2, 4, 6, 8, - 10, 12, 15, 19, 22, 26, 30, 35, - 39, 44, 50, 55, 61, 68, 74, 81, - 88, 96, 103, 111, 120, 128, 137, 146, - 156, 166, 176, 186, 197, 208, 219, 230, - 242, 254, 266, 279, 291, 304, 318, 331, - 345, 359, 374, 388, 403, 418, 433, 449, - 465, 481, 497, 514, 531, 548, 565, 582, - 600, 618, 636, 654, 673, 691, 710, 729, - 749, 768, 788, 808, 828, 848, 869, 889, - 910, 931, 952, 974, 995, 1017, 1039, 1060, - 1083, 1105, 1127, 1150, 1172, 1195, 1218, 1241, - 1264, 1288, 1311, 1334, 1358, 1382, 1406, 1429, - 1453, 1478, 1502, 1526, 1550, 1575, 1599, 1624, - 1648, 1673, 1698, 1723, 1747, 1772, 1797, 1822, - 1847, 1872, 1897, 1922, 1948, 1973, 1998, 2023 ] - -# 8-bit Lookup Table (256 values) -DACLookup_FullSine_8Bit = \ -[ 2048, 2098, 2148, 2198, 2248, 2298, 2348, 2398, - 2447, 2496, 2545, 2594, 2642, 2690, 2737, 2784, - 2831, 2877, 2923, 2968, 3013, 3057, 3100, 3143, - 3185, 3226, 3267, 3307, 3346, 3385, 3423, 3459, - 3495, 3530, 3565, 3598, 3630, 3662, 3692, 3722, - 3750, 3777, 3804, 3829, 3853, 3876, 3898, 3919, - 3939, 3958, 3975, 3992, 4007, 4021, 4034, 4045, - 4056, 4065, 4073, 4080, 4085, 4089, 4093, 4094, - 4095, 4094, 4093, 4089, 4085, 4080, 4073, 4065, - 4056, 4045, 4034, 4021, 4007, 3992, 3975, 3958, - 3939, 3919, 3898, 3876, 3853, 3829, 3804, 3777, - 3750, 3722, 3692, 3662, 3630, 3598, 3565, 3530, - 3495, 3459, 3423, 3385, 3346, 3307, 3267, 3226, - 3185, 3143, 3100, 3057, 3013, 2968, 2923, 2877, - 2831, 2784, 2737, 2690, 2642, 2594, 2545, 2496, - 2447, 2398, 2348, 2298, 2248, 2198, 2148, 2098, - 2048, 1997, 1947, 1897, 1847, 1797, 1747, 1697, - 1648, 1599, 1550, 1501, 1453, 1405, 1358, 1311, - 1264, 1218, 1172, 1127, 1082, 1038, 995, 952, - 910, 869, 828, 788, 749, 710, 672, 636, - 600, 565, 530, 497, 465, 433, 403, 373, - 345, 318, 291, 266, 242, 219, 197, 176, - 156, 137, 120, 103, 88, 74, 61, 50, - 39, 30, 22, 15, 10, 6, 2, 1, - 0, 1, 2, 6, 10, 15, 22, 30, - 39, 50, 61, 74, 88, 103, 120, 137, - 156, 176, 197, 219, 242, 266, 291, 318, - 345, 373, 403, 433, 465, 497, 530, 565, - 600, 636, 672, 710, 749, 788, 828, 869, - 910, 952, 995, 1038, 1082, 1127, 1172, 1218, - 1264, 1311, 1358, 1405, 1453, 1501, 1550, 1599, - 1648, 1697, 1747, 1797, 1847, 1897, 1947, 1997 ] - -# 7-bit Lookup Table (128 values) -DACLookup_FullSine_7Bit = \ -[ 2048, 2148, 2248, 2348, 2447, 2545, 2642, 2737, - 2831, 2923, 3013, 3100, 3185, 3267, 3346, 3423, - 3495, 3565, 3630, 3692, 3750, 3804, 3853, 3898, - 3939, 3975, 4007, 4034, 4056, 4073, 4085, 4093, - 4095, 4093, 4085, 4073, 4056, 4034, 4007, 3975, - 3939, 3898, 3853, 3804, 3750, 3692, 3630, 3565, - 3495, 3423, 3346, 3267, 3185, 3100, 3013, 2923, - 2831, 2737, 2642, 2545, 2447, 2348, 2248, 2148, - 2048, 1947, 1847, 1747, 1648, 1550, 1453, 1358, - 1264, 1172, 1082, 995, 910, 828, 749, 672, - 600, 530, 465, 403, 345, 291, 242, 197, - 156, 120, 88, 61, 39, 22, 10, 2, - 0, 2, 10, 22, 39, 61, 88, 120, - 156, 197, 242, 291, 345, 403, 465, 530, - 600, 672, 749, 828, 910, 995, 1082, 1172, - 1264, 1358, 1453, 1550, 1648, 1747, 1847, 1947 ] - -# 6-bit Lookup Table (64 values) -DACLookup_FullSine_6Bit = \ -[ 2048, 2248, 2447, 2642, 2831, 3013, 3185, 3346, - 3495, 3630, 3750, 3853, 3939, 4007, 4056, 4085, - 4095, 4085, 4056, 4007, 3939, 3853, 3750, 3630, - 3495, 3346, 3185, 3013, 2831, 2642, 2447, 2248, - 2048, 1847, 1648, 1453, 1264, 1082, 910, 749, - 600, 465, 345, 242, 156, 88, 39, 10, - 0, 10, 39, 88, 156, 242, 345, 465, - 600, 749, 910, 1082, 1264, 1453, 1648, 1847 ] - -# 5-bit Lookup Table (32 values) -DACLookup_FullSine_5Bit = \ -[ 2048, 2447, 2831, 3185, 3495, 3750, 3939, 4056, - 4095, 4056, 3939, 3750, 3495, 3185, 2831, 2447, - 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) - -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) - diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py b/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py deleted file mode 100755 index dd2dfa76..00000000 --- a/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/python - -import smbus - -# =========================================================================== -# Adafruit_I2C Base Class -# =========================================================================== - -class Adafruit_I2C : - - def __init__(self, address, bus=smbus.SMBus(0), debug=False): - self.address = address - self.bus = bus - self.debug = debug - - def reverseByteOrder(self, data): - "Reverses the byte order of an int (16-bit) or long (32-bit) value" - # Courtesy Vishal Sapre - dstr = hex(data)[2:].replace('L','') - byteCount = len(dstr[::2]) - val = 0 - for i, n in enumerate(range(byteCount)): - d = data & 0xFF - val |= (d << (8 * (byteCount - i - 1))) - data >>= 8 - return val - - def write8(self, reg, value): - "Writes an 8-bit value to the specified register/address" - try: - self.bus.write_byte_data(self.address, reg, value) - if (self.debug): - print("I2C: Wrote 0x%02X to register 0x%02X" % (value, reg)) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def writeList(self, reg, list): - "Writes an array of bytes using I2C format" - try: - self.bus.write_i2c_block_data(self.address, reg, list) - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU8(self, reg): - "Read an unsigned byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS8(self, reg): - "Reads a signed byte from the I2C device" - try: - result = self.bus.read_byte_data(self.address, reg) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg) - if (result > 127): - return result - 256 - else: - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readU16(self, reg): - "Reads an unsigned 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 - - def readS16(self, reg): - "Reads a signed 16-bit value from the I2C device" - try: - hibyte = self.bus.read_byte_data(self.address, reg) - if (hibyte > 127): - hibyte -= 256 - result = (hibyte << 8) + self.bus.read_byte_data(self.address, reg+1) - if (self.debug): - print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) - return result - except IOError, err: - print "Error accessing 0x%02X: Check your I2C address" % self.address - return -1 diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py deleted file mode 100644 index 76ab5137..00000000 --- a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/python - -import time -import math -from Adafruit_I2C import Adafruit_I2C - -# ============================================================================ -# Adafruit PCA9685 16-Channel PWM Servo Driver -# ============================================================================ - -class PWM : - i2c = None - - # Registers/etc. - __SUBADR1 = 0x02 - __SUBADR2 = 0x03 - __SUBADR3 = 0x04 - __MODE1 = 0x00 - __PRESCALE = 0xFE - __LED0_ON_L = 0x06 - __LED0_ON_H = 0x07 - __LED0_OFF_L = 0x08 - __LED0_OFF_H = 0x09 - __ALLLED_ON_L = 0xFA - __ALLLED_ON_H = 0xFB - __ALLLED_OFF_L = 0xFC - __ALLLED_OFF_H = 0xFD - - def __init__(self, address=0x40, debug=False): - self.i2c = Adafruit_I2C(address) - self.address = address - self.debug = debug - if (self.debug): - print "Reseting PCA9685" - self.i2c.write8(self.__MODE1, 0x00) - - def setPWMFreq(self, freq): - "Sets the PWM frequency" - prescaleval = 25000000.0 # 25MHz - prescaleval /= 4096.0 # 12-bit - prescaleval /= float(freq) - prescaleval -= 1.0 - if (self.debug): - print "Setting PWM frequency to %d Hz" % freq - print "Estimated pre-scale: %d" % prescaleval - prescale = math.floor(prescaleval + 0.5) - if (self.debug): - print "Final pre-scale: %d" % prescale - - oldmode = self.i2c.readU8(self.__MODE1); - newmode = (oldmode & 0x7F) | 0x10 # sleep - self.i2c.write8(self.__MODE1, newmode) # go to sleep - self.i2c.write8(self.__PRESCALE, int(math.floor(prescale))) - self.i2c.write8(self.__MODE1, oldmode) - time.sleep(0.005) - self.i2c.write8(self.__MODE1, oldmode | 0x80) - - def setPWM(self, channel, on, off): - "Sets a single PWM channel" - self.i2c.write8(self.__LED0_ON_L+4*channel, on & 0xFF) - self.i2c.write8(self.__LED0_ON_H+4*channel, on >> 8) - self.i2c.write8(self.__LED0_OFF_L+4*channel, off & 0xFF) - self.i2c.write8(self.__LED0_OFF_H+4*channel, off >> 8) - - - - diff --git a/Adafruit_PWM_Servo_Driver/Servo_Example.py b/Adafruit_PWM_Servo_Driver/Servo_Example.py deleted file mode 100644 index 47527429..00000000 --- a/Adafruit_PWM_Servo_Driver/Servo_Example.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/python - -from Adafruit_PWM_Servo_Driver import PWM -import time - -# =========================================================================== -# Example Code -# =========================================================================== - -# Initialise the PWM device using the default address -# bmp = PWM(0x40, debug=True) -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/README.md b/README.md index 1fc20901..501b3a75 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,28 @@ -Adafruit's Raspberry-Pi Python Code Library -============ - Here is a growing collection of libraries and example python scripts - for controlling a variety of Adafruit electronics with a Raspberry Pi - - In progress! +# Adafruit's Legacy Raspberry Pi Python Code Library - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! +## What happened to all the Raspberry Pi Python code!? - Written by Limor Fried, Kevin Townsend and Mikey Sklar for Adafruit Industries. - BSD license, all text above must be included in any redistribution - - To download, we suggest logging into your Pi with Internet accessibility and typing: - git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git \ No newline at end of file +In the past this repository held all of the Raspberry Pi related Python code +that Adafruit published. For example code to talk to sensors like the BMP085, +TCS34725, and other hardware like character LCD plates. Over time we found it +difficult to manage so much code in a single repository, and couldn't easily put +the code on Python's package index for simple installation. Now we've broken out +all of the previous Python code into individual GitHub repositories, and we've +loaded all of these repositories on the [Python package index](https://pypi.python.org/pypi) +so they can be installed with `pip` (note that pip won't install example code so for most users +it's recommended to install from source). + +## Where do I find the new Raspberry Pi Python code? + +**All** of the Python libraries now support Python 3.x and a wide variety of Linux/Single Board Computers. + +This library has been deprecated in favor of our python3 Blinka library. We have replaced all of the libraries that use this repo with CircuitPython libraries that are Python3 compatible, and support a wide variety of single board/linux computers!

+

Visit https://circuitpython.org/blinka for more information

+

CircuitPython has support for almost 200 different drivers, and a as well as FT232H support for Mac/Win/Linux!

+ +## But I **need** the old code! What can I do? + +Don't worry the old Adafruit Raspberry-Pi Python code can be found in the +[legacy branch](https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/tree/legacy) of this repository. This is a snapshot of the old code before it +was refactored into individual libraries. **Note this legacy code will not be +maintained!**