From c1f1e506536502db7debb2a1118ec12f7b0f7499 Mon Sep 17 00:00:00 2001 From: Ethan Bissett Date: Sun, 31 Mar 2013 16:38:16 -0400 Subject: [PATCH 01/29] Fix potentially broken symlinks in CharLCDPlate. --- Adafruit_CharLCDPlate/Adafruit_I2C.py | 2 +- Adafruit_CharLCDPlate/Adafruit_MCP230xx.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_CharLCDPlate/Adafruit_I2C.py b/Adafruit_CharLCDPlate/Adafruit_I2C.py index f5fcefeb..77f06164 120000 --- a/Adafruit_CharLCDPlate/Adafruit_I2C.py +++ b/Adafruit_CharLCDPlate/Adafruit_I2C.py @@ -1 +1 @@ -../../Adafruit-Raspberry-Pi-Python-Code/Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file +../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 index 4e89f685..3df8faef 120000 --- a/Adafruit_CharLCDPlate/Adafruit_MCP230xx.py +++ b/Adafruit_CharLCDPlate/Adafruit_MCP230xx.py @@ -1 +1 @@ -../../Adafruit-Raspberry-Pi-Python-Code/Adafruit_MCP230xx/Adafruit_MCP230xx.py \ No newline at end of file +../Adafruit_MCP230xx/Adafruit_MCP230xx.py \ No newline at end of file From 36306a71af9d44f8f5e32bee980523dfd01efe42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matja=C5=BE=20Lipu=C5=A1?= Date: Sat, 6 Apr 2013 20:39:37 +0300 Subject: [PATCH 02/29] =?UTF-8?q?fixed=C2=A0open=5Fby=5Fkey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py b/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py index c13d3033..9c9f6318 100755 --- a/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py +++ b/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py @@ -32,7 +32,7 @@ try: worksheet = gc.open(spreadsheet).sheet1 # Alternatively, open a spreadsheet using the spreadsheet's key - # worksheet = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE') + # worksheet = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE').sheet1 except: print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet sys.exit() From e28539734dfbd6965395f0f0478ecad44ca0eaea Mon Sep 17 00:00:00 2001 From: Ken Bell Date: Thu, 2 May 2013 21:09:51 -0700 Subject: [PATCH 03/29] Update Adafruit_CharLCDPlate.py Setting read/write on wrong bit in GPIOB. Bit 7 from display is in bit 1 of GPIOB. Need to set/clear correct bit in IODIRB. --- Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py index 06b9300c..02fd782d 100644 --- a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py +++ b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py @@ -82,7 +82,7 @@ def __init__(self, busnum=-1, addr=0x20, debug=False): # I2C is relatively slow. MCP output port states are cached # so we don't need to constantly poll-and-change bit states. - self.porta, self.portb, self.ddrb = 0, 0, 0b00010000 + self.porta, self.portb, self.ddrb = 0, 0, 0b00000010 # Set MCP23017 IOCON register to Bank 0 with sequential operation. # If chip is already set for Bank 0, this will just write to OLATB, @@ -187,7 +187,7 @@ def write(self, value, char_mode=False): """ Send command/data to LCD """ # If pin D7 is in input state, poll LCD busy flag until clear. - if self.ddrb & 0b00010000: + if self.ddrb & 0b00000010: lo = (self.portb & 0b00000001) | 0b01000000 hi = lo | 0b00100000 # E=1 (strobe) self.i2c.bus.write_byte_data( @@ -204,7 +204,7 @@ def write(self, value, char_mode=False): self.portb = lo # Polling complete, change D7 pin to output - self.ddrb &= 0b11101111 + self.ddrb &= 0b11111101 self.i2c.bus.write_byte_data(self.i2c.address, self.MCP23017_IODIRB, self.ddrb) @@ -249,7 +249,7 @@ def write(self, value, char_mode=False): # If a poll-worthy instruction was issued, reconfigure D7 # pin as input to indicate need for polling on next call. if (not char_mode) and (value in self.pollables): - self.ddrb |= 0b00010000 + self.ddrb |= 0b00000010 self.i2c.bus.write_byte_data(self.i2c.address, self.MCP23017_IODIRB, self.ddrb) From 28de85223893075ccd8f5cbd852506ec5f5f5769 Mon Sep 17 00:00:00 2001 From: Jason Travis Date: Fri, 17 May 2013 12:55:49 -0700 Subject: [PATCH 04/29] Update Adafruit_I2C to use new-style classes --- Adafruit_I2C/Adafruit_I2C.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 3423461d..6902a9d0 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -6,7 +6,7 @@ # Adafruit_I2C Class # =========================================================================== -class Adafruit_I2C : +class Adafruit_I2C(object): @staticmethod def getPiRevision(): From dbb04b63f8b596402b568b7d75c475550dd51019 Mon Sep 17 00:00:00 2001 From: shinncchen Date: Sat, 28 Dec 2013 16:39:31 -0600 Subject: [PATCH 05/29] Update Adafruit_VCNL4000.py add a function to read ambient light from VCNL4000 sensor --- Adafruit_VCNL4000/Adafruit_VCNL4000.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Adafruit_VCNL4000/Adafruit_VCNL4000.py b/Adafruit_VCNL4000/Adafruit_VCNL4000.py index 4ebc3a20..4d307536 100755 --- a/Adafruit_VCNL4000/Adafruit_VCNL4000.py +++ b/Adafruit_VCNL4000/Adafruit_VCNL4000.py @@ -51,4 +51,11 @@ def read_proximity(self): return self.i2c.readU16(VCNL4000_PROXIMITYDATA) time.sleep(0.001) - + # Read data from ambient sensor + def read_ambient(self): + self.i2c.write8(VCNL4000_COMMAND, VCNL4000_MEASUREAMBIENT) + while True: + result = self.i2c.readU8(VCNL4000_COMMAND) + if (result and VCNL4000_AMBIENTREADY): + return self.i2c.readU16(VCNL4000_AMBIENTDATA) + time.sleep(0.001) From de1893823e396dd0f630dc8317717ecba8de03aa Mon Sep 17 00:00:00 2001 From: Fernando Fussuma Date: Sat, 11 Jan 2014 00:30:43 -0200 Subject: [PATCH 06/29] Fixed missing blink method and comments change --- Adafruit_CharLCD/Adafruit_CharLCD.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Adafruit_CharLCD/Adafruit_CharLCD.py b/Adafruit_CharLCD/Adafruit_CharLCD.py index 22060c94..af6749ea 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD.py @@ -94,7 +94,6 @@ def begin(self, cols, lines): if (lines > 1): self.numlines = lines self.displayfunction |= self.LCD_2LINE - self.currline = 0 def home(self): @@ -134,30 +133,30 @@ def display(self): def noCursor(self): - """ Turns the underline cursor on/off """ + """ Turns the underline cursor off """ self.displaycontrol &= ~self.LCD_CURSORON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def cursor(self): - """ Cursor On """ + """ Turns the underline cursor on """ self.displaycontrol |= self.LCD_CURSORON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def noBlink(self): - """ Turn on and off the blinking cursor """ + """ Turn the blinking cursor off """ self.displaycontrol &= ~self.LCD_BLINKON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - def noBlink(self): - """ Turn on and off the blinking cursor """ + def blink(self): + """ Turn the blinking cursor on """ - self.displaycontrol &= ~self.LCD_BLINKON + self.displaycontrol |= self.LCD_BLINKON self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) From 2bb6dc18897c52f3cc7c373f53a2596dfc4ff4d0 Mon Sep 17 00:00:00 2001 From: shinncchen Date: Tue, 14 Jan 2014 10:38:12 -0600 Subject: [PATCH 07/29] Update mcp3008.py 1) It allows readadc() to be imported and used as a function without the print log on other python file 2) The GPIO is cleanup if there is a KeyboardInterrupt --- Adafruit_MCP3008/mcp3008.py | 56 +++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/Adafruit_MCP3008/mcp3008.py b/Adafruit_MCP3008/mcp3008.py index a1678a7b..73dcd7dd 100644 --- a/Adafruit_MCP3008/mcp3008.py +++ b/Adafruit_MCP3008/mcp3008.py @@ -68,27 +68,35 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin): adcout /= 2 # first bit is 'null' so drop it return adcout -# change these as desired -SPICLK = 18 -SPIMOSI = 17 -SPIMISO = 21 -SPICS = 22 - -# set up the SPI interface pins -GPIO.setup(SPIMOSI, GPIO.OUT) -GPIO.setup(SPIMISO, GPIO.IN) -GPIO.setup(SPICLK, GPIO.OUT) -GPIO.setup(SPICS, GPIO.OUT) - -# 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 "|" +if __name__=='__main__': + + try: + # change these as desired + SPICLK = 18 + SPIMISO = 21 + SPIMOSI = 17 + SPICS = 22 + + # set up the SPI interface pins + GPIO.setup(SPICLK, GPIO.OUT) + GPIO.setup(SPIMISO, GPIO.IN) + GPIO.setup(SPIMOSI, 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 "|" + + except KeyboardInterrupt: + pass + + GPIO.cleanup() From eec11162bfed377eb07a80442798d2769e97a771 Mon Sep 17 00:00:00 2001 From: David Miller Date: Sun, 20 Apr 2014 21:46:01 +0000 Subject: [PATCH 08/29] added file .gitignore --- .gitignore | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .gitignore 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/ From 35c23798afa2b15116c96dac023dd7704c2f460c Mon Sep 17 00:00:00 2001 From: Sean McIntyre Date: Wed, 14 May 2014 20:25:38 +0000 Subject: [PATCH 09/29] Added bargraph library and example for Adafruit product 1721 --- Adafruit_LEDBackpack/Adafruit_Bargraph.py | 55 ++++++++++++++++++++ Adafruit_LEDBackpack/Adafruit_LEDBackpack.py | 10 +++- Adafruit_LEDBackpack/ex_bargraph.py | 19 +++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 Adafruit_LEDBackpack/Adafruit_Bargraph.py create mode 100644 Adafruit_LEDBackpack/ex_bargraph.py diff --git a/Adafruit_LEDBackpack/Adafruit_Bargraph.py b/Adafruit_LEDBackpack/Adafruit_Bargraph.py new file mode 100644 index 00000000..b2cc09d1 --- /dev/null +++ b/Adafruit_LEDBackpack/Adafruit_Bargraph.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +import time +import datetime +from Adafruit_LEDBackpack import LEDBackpack + +# =========================================================================== +# Bargraph Display +# =========================================================================== + +# This class is meant to be used with the four-character, seven segment +# displays available from Adafruit + +class Bargraph: + disp = None + + LED_OFF = 0 + LED_RED = 1 + LED_GREEN = 2 + LED_YELLOW = 3 + + # Constructor + def __init__(self, address=0x70, debug=False): + self.debug = debug + + if self.debug: + print "Initializing a new instance of LEDBackpack at 0x%02X" % address + self.disp = LEDBackpack(address=address, debug=debug) + + def setLed(self, bar, color): + if bar > 24: + return + if color > 3: + return + + if bar < 12: + c = bar / 4 + else: + c = (bar - 12) / 4 + + a = bar % 4; + if bar >= 12: + a += 4; + + if self.debug: + print "Ano = %d Cath %d" % (a, c) + + bufRow = self.disp.getBufferRow(c) & ~((1 << a) | (1 << (a+8))) # turn off the LED + + if color == self.LED_RED: + self.disp.setBufferRow(c, bufRow | (1 << a)) + elif color == self.LED_YELLOW: + self.disp.setBufferRow(c, bufRow | (1 << a) | (1 << (a+8))) + elif color == self.LED_GREEN: + self.disp.setBufferRow(c, bufRow | 1 << (a+8)) diff --git a/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py b/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py index a0c58295..5318cb81 100644 --- a/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py +++ b/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py @@ -27,8 +27,8 @@ class LEDBackpack: 0x0000, 0x0000, 0x0000, 0x0000 ] # Constructor - def __init__(self, address=0x70, debug=False): - self.i2c = Adafruit_I2C(address) + def __init__(self, address=0x70, debug=False, bus=-1): + self.i2c = Adafruit_I2C(address, bus) self.address = address self.debug = debug @@ -64,6 +64,12 @@ def setBufferRow(self, row, value, update=True): if (update): self.writeDisplay() # Update the display + def getBufferRow(self, row): + "Returns a single 16-bit entry in the 8*16-bit buffer" + if (row > 7): + return + return self.__buffer[row] + def getBuffer(self): "Returns a copy of the raw buffer contents" bufferCopy = copy(self.__buffer) diff --git a/Adafruit_LEDBackpack/ex_bargraph.py b/Adafruit_LEDBackpack/ex_bargraph.py new file mode 100644 index 00000000..1fa0a31e --- /dev/null +++ b/Adafruit_LEDBackpack/ex_bargraph.py @@ -0,0 +1,19 @@ +#!/usr/bin/python + +import time +import datetime +from Adafruit_Bargraph import Bargraph + +# =========================================================================== +# Scroll through colors example +# =========================================================================== +bargraph = Bargraph(address=0x70) + +print "Press CTRL+C to exit" + +while(True): + for color in range(1, 4): + for i in range(24): + print i + bargraph.setLed(i, color) + time.sleep(0.05) From 1bb8f6de2bfa6fe6264db7dfc9bbfe7961c9182c Mon Sep 17 00:00:00 2001 From: Sean McIntyre Date: Wed, 14 May 2014 20:27:46 +0000 Subject: [PATCH 10/29] updated comments --- Adafruit_LEDBackpack/Adafruit_Bargraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_LEDBackpack/Adafruit_Bargraph.py b/Adafruit_LEDBackpack/Adafruit_Bargraph.py index b2cc09d1..804991fa 100644 --- a/Adafruit_LEDBackpack/Adafruit_Bargraph.py +++ b/Adafruit_LEDBackpack/Adafruit_Bargraph.py @@ -8,7 +8,7 @@ # Bargraph Display # =========================================================================== -# This class is meant to be used with the four-character, seven segment +# This class is meant to be used with the 24-LED bicolor bargraph # displays available from Adafruit class Bargraph: From c07439a34fc820ee74f9ee3b47f172922cdab73d Mon Sep 17 00:00:00 2001 From: Sean McIntyre Date: Wed, 14 May 2014 20:29:13 +0000 Subject: [PATCH 11/29] removed bus changes --- Adafruit_LEDBackpack/Adafruit_LEDBackpack.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py b/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py index 5318cb81..b2a20065 100644 --- a/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py +++ b/Adafruit_LEDBackpack/Adafruit_LEDBackpack.py @@ -27,8 +27,8 @@ class LEDBackpack: 0x0000, 0x0000, 0x0000, 0x0000 ] # Constructor - def __init__(self, address=0x70, debug=False, bus=-1): - self.i2c = Adafruit_I2C(address, bus) + def __init__(self, address=0x70, debug=False): + self.i2c = Adafruit_I2C(address) self.address = address self.debug = debug From 7d2ef0ac3d583a2fe4eb2c0f0033395618c532af Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Thu, 15 May 2014 21:02:31 -0400 Subject: [PATCH 12/29] prevent segfault caused by bitidx++ This patch modifies Adafruit_DHT_Driver/Adafruit_DHT.c so that the code that increments `bitidx` without bound is protected by #ifdef DEBUG. This prevents this code from generating a segfault if readDHT is called several times (which will ultimately cause bitidx to increment beyond the end of the bits array). Resolves github issue #78. --- Adafruit_DHT_Driver/Adafruit_DHT.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adafruit_DHT_Driver/Adafruit_DHT.c b/Adafruit_DHT_Driver/Adafruit_DHT.c index 9d1746be..a35cf10d 100644 --- a/Adafruit_DHT_Driver/Adafruit_DHT.c +++ b/Adafruit_DHT_Driver/Adafruit_DHT.c @@ -105,7 +105,9 @@ int readDHT(int type, int pin) { } laststate = bcm2835_gpio_lev(pin); if (counter == 1000) break; +#ifdef DEBUG bits[bitidx++] = counter; +#endif if ((i>3) && (i%2 == 0)) { // shove each bit into the storage bytes From fc3dd6c4a2cc6856a4a8858cafb1b90103cb76fb Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Mon, 9 Jun 2014 16:47:01 -0700 Subject: [PATCH 13/29] Mark Adafruit_DHT_Driver code as deprecated and point at new Adafruit_Python_DHT library. --- Adafruit_DHT_Driver/DEPRECATED.txt | 5 +++++ Adafruit_DHT_Driver_Python/DEPRECATED.txt | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 Adafruit_DHT_Driver/DEPRECATED.txt create mode 100644 Adafruit_DHT_Driver_Python/DEPRECATED.txt diff --git a/Adafruit_DHT_Driver/DEPRECATED.txt b/Adafruit_DHT_Driver/DEPRECATED.txt new file mode 100644 index 00000000..41c4538a --- /dev/null +++ b/Adafruit_DHT_Driver/DEPRECATED.txt @@ -0,0 +1,5 @@ +This Adafruit_DHT_Driver code is deprecated and has been superseded by the Python library +at https://github.com/adafruit/Adafruit_Python_DHT You can see the new library's C code +for interfacing with the DHT sensors on either a Raspberry Pi or Beaglebone Black in the +source/Raspberry_Pi or source/Beaglebone_Black directory of the new library. See more +details on installing and using the library in the learning guide at: https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/overview diff --git a/Adafruit_DHT_Driver_Python/DEPRECATED.txt b/Adafruit_DHT_Driver_Python/DEPRECATED.txt new file mode 100644 index 00000000..96dd74ec --- /dev/null +++ b/Adafruit_DHT_Driver_Python/DEPRECATED.txt @@ -0,0 +1,5 @@ +This Adafruit_DHT_Driver_Python code is deprecated and has been superseded by the Python +library at https://github.com/adafruit/Adafruit_Python_DHT You can see the new library's C +code for interfacing with the DHT sensors on either a Raspberry Pi or Beaglebone Black in the +source/Raspberry_Pi or source/Beaglebone_Black directory of the new library. See more details +on installing and using the library in the learning guide at: https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/overview From fa0a792f17fafe08925bbb78426862bab81600dd Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Thu, 19 Jun 2014 12:03:42 -0700 Subject: [PATCH 14/29] Add deprecation note to BMP085 code with pointer to new BMP085/180 sensor library. --- Adafruit_BMP085/DEPRECATED.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Adafruit_BMP085/DEPRECATED.txt diff --git a/Adafruit_BMP085/DEPRECATED.txt b/Adafruit_BMP085/DEPRECATED.txt new file mode 100644 index 00000000..4e7dadf4 --- /dev/null +++ b/Adafruit_BMP085/DEPRECATED.txt @@ -0,0 +1,5 @@ +This BMP085 sensor library has been deprecated in favor of a new version that supports both the Raspberry Pi and Beaglebone Black. + +You can find the new library with installation instructions at this github repository: https://github.com/adafruit/Adafruit_Python_BMP + +You can also find a tutorial on using this library at: https://learn.adafruit.com/using-the-bmp085-with-raspberry-pi/using-the-adafruit-bmp-python-library From b6bd43dfbe0830dbb2884c92f6921469d3271593 Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Thu, 19 Jun 2014 12:23:08 -0700 Subject: [PATCH 15/29] Fix getPiRevision to check for revision value 0002 or 0003 as rev 1 boards. --- Adafruit_I2C/Adafruit_I2C.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 0c4a7d98..7140efba 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -13,11 +13,12 @@ def getPiRevision(): "Gets the version number of the Raspberry Pi board" # Courtesy quick2wire-python-api # https://github.com/quick2wire/quick2wire-python-api + # Updated revision info from: http://elinux.org/RPi_HardwareHistory#Board_Revision_History 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 + return 1 if line.rstrip()[-1] in ['2','3'] else 2 except: return 0 From d9c0bbb9e582df2d313a1b1538c8b5d41f7cc37a Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Thu, 19 Jun 2014 12:27:48 -0700 Subject: [PATCH 16/29] Fix bug with readS16 not returning signed results, and add optional explicit endian parameter to 16 bit reads. --- Adafruit_I2C/Adafruit_I2C.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 7140efba..0e718baa 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -115,20 +115,25 @@ def readS8(self, reg): except IOError, err: return self.errMsg() - def readU16(self, reg): + def readU16(self, reg, little_endian=True): "Reads an unsigned 16-bit value from the I2C device" try: result = self.bus.read_word_data(self.address,reg) + # Swap bytes if using big endian because read_word_data assumes little + # endian on ARM (little endian) systems. + if not little_endian: + result = ((result << 8) & 0xFF00) + (result >> 8) 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: return self.errMsg() - def readS16(self, reg): + def readS16(self, reg, little_endian=True): "Reads a signed 16-bit value from the I2C device" try: - result = self.bus.read_word_data(self.address,reg) + result = self.readU16(self.address,reg,little_endian) + if result > 32767: result -= 65536 if (self.debug): print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) return result From cfd736dd325f05492b1d54564a9ccdd71b82272a Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Thu, 19 Jun 2014 12:30:51 -0700 Subject: [PATCH 17/29] Remove debug log from readS16 to prevent double logging. --- Adafruit_I2C/Adafruit_I2C.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 0e718baa..9dd75c82 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -134,8 +134,6 @@ def readS16(self, reg, little_endian=True): try: result = self.readU16(self.address,reg,little_endian) if result > 32767: result -= 65536 - 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: return self.errMsg() From 0924803b4005f39bcec8ec98818a6b92e0b0ccf0 Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Thu, 19 Jun 2014 12:47:38 -0700 Subject: [PATCH 18/29] Fix bug in calling readU16 from readS16. --- Adafruit_I2C/Adafruit_I2C.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 9dd75c82..b1c88a59 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -132,7 +132,7 @@ def readU16(self, reg, little_endian=True): def readS16(self, reg, little_endian=True): "Reads a signed 16-bit value from the I2C device" try: - result = self.readU16(self.address,reg,little_endian) + result = self.readU16(reg,little_endian) if result > 32767: result -= 65536 return result except IOError, err: From 4d92bf17cfc620a492801fa41bb712addcc599d2 Mon Sep 17 00:00:00 2001 From: Sebastian Ludwig Date: Thu, 19 Jun 2014 23:23:13 +0200 Subject: [PATCH 19/29] Fixed: PWM servo driver did not reset properly during initialization. --- Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py index 76ab5137..686059fd 100644 --- a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py +++ b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py @@ -32,7 +32,7 @@ def __init__(self, address=0x40, debug=False): self.debug = debug if (self.debug): print "Reseting PCA9685" - self.i2c.write8(self.__MODE1, 0x00) + self.i2c.bus.write_byte(0x00, 0x06) def setPWMFreq(self, freq): "Sets the PWM frequency" From 47a75a2fa69301a269beb80fc5a563b1a2db9876 Mon Sep 17 00:00:00 2001 From: Sebastian Ludwig Date: Thu, 19 Jun 2014 23:27:39 +0200 Subject: [PATCH 20/29] Passing debug flag from PWM to Adafruit_I2C. --- Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py index 686059fd..bfe9b64a 100644 --- a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py +++ b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py @@ -28,6 +28,7 @@ class PWM : def __init__(self, address=0x40, debug=False): self.i2c = Adafruit_I2C(address) + self.i2c.debug = debug self.address = address self.debug = debug if (self.debug): From 0780adbd87a165905572630b0730f357dec15bee Mon Sep 17 00:00:00 2001 From: Sebastian Ludwig Date: Fri, 20 Jun 2014 00:34:08 +0200 Subject: [PATCH 21/29] Addition to fix in 4d92bf1: ending sleep of PCA9685 in PWM servo driver initialization. --- Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py index bfe9b64a..73427baa 100644 --- a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py +++ b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py @@ -25,6 +25,7 @@ class PWM : __ALLLED_ON_H = 0xFB __ALLLED_OFF_L = 0xFC __ALLLED_OFF_H = 0xFD + __SLEEP = 0x10 def __init__(self, address=0x40, debug=False): self.i2c = Adafruit_I2C(address) @@ -34,6 +35,10 @@ def __init__(self, address=0x40, debug=False): if (self.debug): print "Reseting PCA9685" self.i2c.bus.write_byte(0x00, 0x06) + mode1 = self.i2c.readU8(self.__MODE1) + mode1 = mode1 & ~self.__SLEEP # wake up (reset sleep) + self.i2c.write8(self.__MODE1, mode1) + time.sleep(0.005) # wait for oscillator def setPWMFreq(self, freq): "Sets the PWM frequency" From e7ce458ad930dad07e69336210b5188c8b0c7cd4 Mon Sep 17 00:00:00 2001 From: Sebastian Ludwig Date: Sat, 21 Jun 2014 11:20:59 +0200 Subject: [PATCH 22/29] Extended fix in 4d92bf1 to work if more than one PCA9685 is connected. In the old version any subsequent board initialization reset all previously initialized boards. --- Adafruit_I2C/Adafruit_I2C.py | 14 ++++-- .../Adafruit_PWM_Servo_Driver.py | 43 +++++++++++++------ 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 0c4a7d98..6c826166 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -25,15 +25,14 @@ def getPiRevision(): def getPiI2CBusNumber(): # Gets the I2C bus number /dev/i2c# return 1 if Adafruit_I2C.getPiRevision() > 1 else 0 - + def __init__(self, address, busnum=-1, debug=False): self.address = address # By default, the correct I2C bus is auto-detected using /proc/cpuinfo # 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.bus = smbus.SMBus( - busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber()) + self.bus = smbus.SMBus(busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber()) self.debug = debug def reverseByteOrder(self, data): @@ -69,6 +68,15 @@ def write16(self, reg, value): except IOError, err: return self.errMsg() + def writeRaw8(self, value): + "Writes an 8-bit value on the bus" + try: + self.bus.write_byte(self.address, value) + if self.debug: + print "I2C: Wrote 0x%02X" % value + except IOError, err: + return self.errMsg() + def writeList(self, reg, list): "Writes an array of bytes using I2C format" try: diff --git a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py index 73427baa..35c993ca 100644 --- a/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py +++ b/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py @@ -9,23 +9,35 @@ # ============================================================================ class PWM : - i2c = None - # Registers/etc. + __MODE1 = 0x00 + __MODE2 = 0x01 __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 + __ALL_LED_ON_L = 0xFA + __ALL_LED_ON_H = 0xFB + __ALL_LED_OFF_L = 0xFC + __ALL_LED_OFF_H = 0xFD + + # Bits + __RESTART = 0x80 __SLEEP = 0x10 + __ALLCALL = 0x01 + __INVRT = 0x10 + __OUTDRV = 0x04 + + general_call_i2c = Adafruit_I2C(0x00) + + @classmethod + def softwareReset(cls): + "Sends a software reset (SWRST) command to all the servo drivers on the bus" + cls.general_call_i2c.writeRaw8(0x06) # SWRST def __init__(self, address=0x40, debug=False): self.i2c = Adafruit_I2C(address) @@ -33,8 +45,12 @@ def __init__(self, address=0x40, debug=False): self.address = address self.debug = debug if (self.debug): - print "Reseting PCA9685" - self.i2c.bus.write_byte(0x00, 0x06) + print "Reseting PCA9685 MODE1 (without SLEEP) and MODE2" + self.setAllPWM(0, 0) + self.i2c.write8(self.__MODE2, self.__OUTDRV) + self.i2c.write8(self.__MODE1, self.__ALLCALL) + time.sleep(0.005) # wait for oscillator + mode1 = self.i2c.readU8(self.__MODE1) mode1 = mode1 & ~self.__SLEEP # wake up (reset sleep) self.i2c.write8(self.__MODE1, mode1) @@ -68,6 +84,9 @@ def setPWM(self, channel, on, off): self.i2c.write8(self.__LED0_OFF_L+4*channel, off & 0xFF) self.i2c.write8(self.__LED0_OFF_H+4*channel, off >> 8) - - - + def setAllPWM(self, on, off): + "Sets a all PWM channels" + self.i2c.write8(self.__ALL_LED_ON_L, on & 0xFF) + self.i2c.write8(self.__ALL_LED_ON_H, on >> 8) + self.i2c.write8(self.__ALL_LED_OFF_L, off & 0xFF) + self.i2c.write8(self.__ALL_LED_OFF_H, off >> 8) From 79ae33a1023a041e35d924b9fdbcf548e5af4880 Mon Sep 17 00:00:00 2001 From: Asheesh Date: Mon, 14 Jul 2014 17:40:00 +0530 Subject: [PATCH 23/29] The gain value was missing the last two digits. Similar to other settings, the gain is 4 digits long. --- Adafruit_ADS1x15/ads1x15_ex_singleended.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_ADS1x15/ads1x15_ex_singleended.py b/Adafruit_ADS1x15/ads1x15_ex_singleended.py index 383927fa..2c4dee43 100644 --- a/Adafruit_ADS1x15/ads1x15_ex_singleended.py +++ b/Adafruit_ADS1x15/ads1x15_ex_singleended.py @@ -13,7 +13,7 @@ def signal_handler(signal, frame): ADS1115 = 0x01 # 16-bit ADC # Select the gain -# gain = 61 # +/- 6.144V +# gain = 6144 # +/- 6.144V gain = 4096 # +/- 4.096V # gain = 2048 # +/- 2.048V # gain = 1024 # +/- 1.024V From 349fbb27f7fa8bb2f816b0733e3b40b8a9eb8365 Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Mon, 14 Jul 2014 21:23:18 +0000 Subject: [PATCH 24/29] Resolve #65 by adding optional backlight parameter which defaults on to init function. --- Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py index 06b9300c..1e85c94b 100644 --- a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py +++ b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py @@ -76,7 +76,7 @@ class Adafruit_CharLCDPlate(Adafruit_I2C): # ---------------------------------------------------------------------- # Constructor - def __init__(self, busnum=-1, addr=0x20, debug=False): + def __init__(self, busnum=-1, addr=0x20, debug=False, backlight=ON): self.i2c = Adafruit_I2C(addr, busnum, debug) @@ -84,6 +84,11 @@ def __init__(self, busnum=-1, addr=0x20, debug=False): # so we don't need to constantly poll-and-change bit states. self.porta, self.portb, self.ddrb = 0, 0, 0b00010000 + # Set initial backlight color. + c = ~backlight + self.porta = (self.porta & 0b00111111) | ((c & 0b011) << 6) + self.portb = (self.portb & 0b11111110) | ((c & 0b100) >> 2) + # Set MCP23017 IOCON register to Bank 0 with sequential operation. # If chip is already set for Bank 0, this will just write to OLATB, # which won't seriously bother anything on the plate right now @@ -116,8 +121,8 @@ def __init__(self, busnum=-1, addr=0x20, debug=False): 0b00000000, # INTCAPB self.porta, # GPIOA self.portb, # GPIOB - self.porta, # OLATA 0 on all outputs; side effect of - self.portb ]) # OLATB turning on R+G+B backlight LEDs. + self.porta, # OLATA + self.portb ]) # OLATB # Switch to Bank 1 and disable sequential operation. # From this point forward, the register addresses do NOT match From 24fd2f449ab13e3fe0130fc3b206d73a9c108dee Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Mon, 14 Jul 2014 22:39:29 +0000 Subject: [PATCH 25/29] Resolve #43 and resolve #44 by adding 20x4 LCD support and 20x4 example. --- .../Adafruit_CharLCDPlate.py | 28 +++- Adafruit_CharLCDPlate/LCDtest_20x4.py | 156 ++++++++++++++++++ 2 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 Adafruit_CharLCDPlate/LCDtest_20x4.py diff --git a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py index 1e85c94b..f3913155 100644 --- a/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py +++ b/Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py @@ -11,6 +11,7 @@ from Adafruit_I2C import Adafruit_I2C from time import sleep + class Adafruit_CharLCDPlate(Adafruit_I2C): # ---------------------------------------------------------------------- @@ -72,6 +73,13 @@ class Adafruit_CharLCDPlate(Adafruit_I2C): LCD_MOVERIGHT = 0x04 LCD_MOVELEFT = 0x00 + # Line addresses for up to 4 line displays. Maps line number to DDRAM address for line. + LINE_ADDRESSES = { 1: 0xC0, 2: 0x94, 3: 0xD4 } + + # Truncation constants for message function truncate parameter. + NO_TRUNCATE = 0 + TRUNCATE = 1 + TRUNCATE_ELLIPSIS = 2 # ---------------------------------------------------------------------- # Constructor @@ -265,6 +273,7 @@ def write(self, value, char_mode=False): def begin(self, cols, lines): self.currline = 0 self.numlines = lines + self.numcols = cols self.clear() @@ -409,13 +418,24 @@ def createChar(self, location, bitmap): self.write(self.LCD_SETDDRAMADDR) - def message(self, text): + def message(self, text, truncate=NO_TRUNCATE): """ Send string to LCD. Newline wraps to second line""" lines = str(text).split('\n') # Split at newline(s) for i, line in enumerate(lines): # For each substring... - if i > 0: # If newline(s), - self.write(0xC0) # set DDRAM address to 2nd line - self.write(line, True) # Issue substring + address = self.LINE_ADDRESSES.get(i, None) + if address is not None: # If newline(s), + self.write(address) # set DDRAM address to line + # Handle appropriate truncation if requested. + linelen = len(line) + if truncate == self.TRUNCATE and linelen > self.numcols: + # Hard truncation of line. + self.write(line[0:self.numcols], True) + elif truncate == self.TRUNCATE_ELLIPSIS and linelen > self.numcols: + # Nicer truncation with ellipses. + self.write(line[0:self.numcols-3] + '...', True) + else: + self.write(line, True) + def backlight(self, color): diff --git a/Adafruit_CharLCDPlate/LCDtest_20x4.py b/Adafruit_CharLCDPlate/LCDtest_20x4.py new file mode 100644 index 00000000..01fc8fe8 --- /dev/null +++ b/Adafruit_CharLCDPlate/LCDtest_20x4.py @@ -0,0 +1,156 @@ +#!/usr/bin/python + +#---------------------------------------------------------------- +# Author: Chris Crumpacker +# Date: May 2013 +# +# A demo of some of the built in helper functions of +# the Adafruit_CharLCDPlate.py This is 20x4 display specific. +# +# Using Adafruit_CharLCD code with the I2C and MCP230xx code aswell +#---------------------------------------------------------------- + +numcolumns = 20 +numrows = 4 + +from time import sleep +from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate + +lcd = Adafruit_CharLCDPlate() + +lcd.begin(numcolumns, numrows) + +lcd.backlight(lcd.ON) +lcd.message("LCD 20x4\nDemonstration") +sleep(2) + +while True: + #Text on each line alone. + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Line 1") + sleep(1) + + lcd.clear() + lcd.setCursor(0,1) + lcd.message("Line 2") + sleep(1) + + lcd.clear() + lcd.setCursor(0,2) + lcd.message("Line 3") + sleep(1) + + lcd.clear() + lcd.setCursor(0,3) + lcd.message("Line 4") + sleep(1) + + # Using the "\n" new line marker + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Line 1") + sleep(1) + + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Line 1\nLine 2") + sleep(1) + + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Line 1\nLine 2\nLine 3") + sleep(1) + + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Line 1\nLine 2\nLine 3\nLine 4") + sleep(1) + + # Auto line limiting by length as to not overflow the display + # This is line by line and does not to any caraige returns + lcd.clear() + lcd.setCursor(0,0) + lcd.message("This String is 33 Characters long", lcd.TRUNCATE) + sleep(2) + + lcd.clear() + lcd.setCursor(0,0) + lcd.message("This String has ellipsis", lcd.TRUNCATE_ELLIPSIS) + sleep(2) + + #Scroll text to the right + messageToPrint = "Scrolling Right" + i=0 + while i<20: + lcd.clear() + lcd.setCursor(0,0) + suffix = " " * i + lcd.message(suffix + messageToPrint, lcd.TRUNCATE) + sleep(.25) + i += 1 + + # Scroll test in from the Left + messageToPrint = "Scrolling Left" + i=20 + while i>=0: + lcd.clear() + lcd.setCursor(0,0) + suffix = " " * i + lcd.message(suffix + messageToPrint, lcd.TRUNCATE) + sleep(.25) + i -= 1 + sleep(2) + + # Printing text backwards, NOT right justified + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Right to left:") + lcd.setCursor(10,1) + lcd.rightToLeft() + lcd.message("Testing") + sleep(2) + + # Printing normally from the middle of the line + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Left to Right:") + lcd.setCursor(10,1) + lcd.message("Testing") + sleep(2) + + # Enabling the cursor and having it blink + lcd.clear() + lcd.setCursor(0,0) + lcd.cursor() + lcd.blink() + lcd.message("Cursor is blinking") + lcd.setCursor(0,1) + sleep(3) + lcd.noCursor() + lcd.noBlink() + + # Turning the backlight off and showing a simple count down + lcd.clear() + lcd.setCursor(0,0) + lcd.message("Backlight off in") + lcd.setCursor(0,3) + lcd.message("Back on in 3sec") + lcd.setCursor(17,0) #Reseting the cursor here keeps us from having to clear the screen, this over writes the previous character + lcd.message("3") + sleep(1) + + lcd.setCursor(17,0) + lcd.message("2") + sleep(1) + + lcd.setCursor(17,0) + lcd.message("1") + sleep(1) + + lcd.backlight(lcd.OFF) + lcd.clear() + lcd.setCursor(0,0) + sleep(3) + lcd.backlight(lcd.ON) + lcd.message("Backlight on") From f8085fe38f9043f8c51717fb6d4dcbd8661c7872 Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Tue, 15 Jul 2014 00:05:55 +0000 Subject: [PATCH 26/29] Make char LCD spaces/tabs consistent and clean up to be close to pep8 compliance. --- Adafruit_CharLCD/Adafruit_CharLCD.py | 276 +++++++----------- .../Adafruit_CharLCD_IPclock_example.py | 21 +- 2 files changed, 124 insertions(+), 173 deletions(-) diff --git a/Adafruit_CharLCD/Adafruit_CharLCD.py b/Adafruit_CharLCD/Adafruit_CharLCD.py index af6749ea..a4bb9a93 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD.py @@ -8,58 +8,58 @@ from time import sleep -class Adafruit_CharLCD: + +class Adafruit_CharLCD(object): # 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 + 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 + 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 + 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 + LCD_DISPLAYMOVE = 0x08 + LCD_CURSORMOVE = 0x00 # flags for display/cursor shift - LCD_DISPLAYMOVE = 0x08 - LCD_CURSORMOVE = 0x00 - LCD_MOVERIGHT = 0x04 - LCD_MOVELEFT = 0x00 + 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 + 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 + GPIO.setwarnings(False) + self.GPIO = GPIO self.pin_rs = pin_rs self.pin_e = pin_e self.pins_db = pins_db @@ -71,190 +71,140 @@ def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None): 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.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.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 + 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 + # 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 - + if (lines > 1): + self.numlines = lines + self.displayfunction |= self.LCD_2LINE def home(self): - - self.write4bits(self.LCD_RETURNHOME) # set cursor position to zero - self.delayMicroseconds(3000) # this command takes a long time! - + 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 - + 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])) - 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 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) - + """ Turn the display on (quickly) """ + self.displaycontrol |= self.LCD_DISPLAYON + self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def noCursor(self): - """ Turns the underline cursor off """ - - self.displaycontrol &= ~self.LCD_CURSORON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - + """ Turns the underline cursor off """ + self.displaycontrol &= ~self.LCD_CURSORON + self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def cursor(self): - """ Turns the underline cursor on """ - - self.displaycontrol |= self.LCD_CURSORON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - + """ Turns the underline cursor on """ + self.displaycontrol |= self.LCD_CURSORON + self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def noBlink(self): - """ Turn the blinking cursor off """ - - self.displaycontrol &= ~self.LCD_BLINKON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - + """ Turn the blinking cursor off """ + self.displaycontrol &= ~self.LCD_BLINKON + self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) def blink(self): - """ Turn the blinking cursor on """ - - self.displaycontrol |= self.LCD_BLINKON - self.write4bits(self.LCD_DISPLAYCONTROL | self.displaycontrol) - + """ Turn the blinking cursor on """ + 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) - + """ 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); - + """ 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); - + """ 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) - + """ 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) + """ 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.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() - + self.pulseEnable() for pin in self.pins_db: self.GPIO.output(pin, False) - - for i in range(4,8): + for i in range(4, 8): if bits[i] == "1": self.GPIO.output(self.pins_db[::-1][i-4], True) - - self.pulseEnable() - + self.pulseEnable() def delayMicroseconds(self, microseconds): - seconds = microseconds / float(1000000) # divide microseconds by 1 million for seconds - sleep(seconds) - + 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 - + 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 + self.write4bits(0xC0) # next line else: - self.write4bits(ord(char),True) + 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 index d3f6958f..f1be14cd 100755 --- a/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py +++ b/Adafruit_CharLCD/Adafruit_CharLCD_IPclock_example.py @@ -1,7 +1,7 @@ #!/usr/bin/python from Adafruit_CharLCD import Adafruit_CharLCD -from subprocess import * +from subprocess import * from time import sleep, strftime from datetime import datetime @@ -9,16 +9,17 @@ cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1" -lcd.begin(16,1) +lcd.begin(16, 1) + def run_cmd(cmd): - p = Popen(cmd, shell=True, stdout=PIPE) - output = p.communicate()[0] - return output + 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) + lcd.clear() + ipaddr = run_cmd(cmd) + lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n')) + lcd.message('IP %s' % (ipaddr)) + sleep(2) From b11eda5e7253e55c36b8e264b61f666f81816d98 Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Tue, 15 Jul 2014 01:21:36 +0000 Subject: [PATCH 27/29] Resolve #30 #31 #32 by fixing MCP230xx_GPIO class parameter order and adding CharLCD with MCP230xx example. --- Adafruit_CharLCD/Adafruit_MCP230xx.py | 1 + Adafruit_CharLCD/LCD_MCP230XX_test.py | 18 ++++++++++++++++++ Adafruit_MCP230xx/Adafruit_MCP230xx.py | 6 +++--- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 120000 Adafruit_CharLCD/Adafruit_MCP230xx.py create mode 100644 Adafruit_CharLCD/LCD_MCP230XX_test.py diff --git a/Adafruit_CharLCD/Adafruit_MCP230xx.py b/Adafruit_CharLCD/Adafruit_MCP230xx.py new file mode 120000 index 00000000..3df8faef --- /dev/null +++ b/Adafruit_CharLCD/Adafruit_MCP230xx.py @@ -0,0 +1 @@ +../Adafruit_MCP230xx/Adafruit_MCP230xx.py \ No newline at end of file diff --git a/Adafruit_CharLCD/LCD_MCP230XX_test.py b/Adafruit_CharLCD/LCD_MCP230XX_test.py new file mode 100644 index 00000000..cc1e7bcd --- /dev/null +++ b/Adafruit_CharLCD/LCD_MCP230XX_test.py @@ -0,0 +1,18 @@ +#!/usr/bin/python +# Example script to show usage of MCP230xx GPIO extender to drive character LCD. + +from Adafruit_CharLCD import Adafruit_CharLCD +from Adafruit_MCP230xx import MCP230XX_GPIO + +bus = 1 # Note you need to change the bus number to 0 if running on a revision 1 Raspberry Pi. +address = 0x20 # I2C address of the MCP230xx chip. +gpio_count = 8 # Number of GPIOs exposed by the MCP230xx chip, should be 8 or 16 depending on chip. + +# Create MCP230xx GPIO adapter. +mcp = MCP230XX_GPIO(bus, address, gpio_count) + +# Create LCD, passing in MCP GPIO adapter. +lcd = Adafruit_CharLCD(pin_rs=1, pin_e=2, pins_db=[3,4,5,6], GPIO=mcp) + +lcd.clear() +lcd.message(" Adafruit 16x2\n Standard LCD") diff --git a/Adafruit_MCP230xx/Adafruit_MCP230xx.py b/Adafruit_MCP230xx/Adafruit_MCP230xx.py index b7ad9877..dc1b9c27 100755 --- a/Adafruit_MCP230xx/Adafruit_MCP230xx.py +++ b/Adafruit_MCP230xx/Adafruit_MCP230xx.py @@ -40,9 +40,9 @@ class Adafruit_MCP230XX(object): OUTPUT = 0 INPUT = 1 - def __init__(self, address, num_gpios): + def __init__(self, address, num_gpios, busnum=-1): assert num_gpios >= 0 and num_gpios <= 16, "Number of GPIOs must be between 0 and 16" - self.i2c = Adafruit_I2C(address=address) + self.i2c = Adafruit_I2C(address=address, busnum=busnum) self.address = address self.num_gpios = num_gpios @@ -162,7 +162,7 @@ class MCP230XX_GPIO(object): BCM = 0 BOARD = 0 def __init__(self, busnum, address, num_gpios): - self.chip = Adafruit_MCP230XX(busnum, address, num_gpios) + self.chip = Adafruit_MCP230XX(address, num_gpios, busnum) def setmode(self, mode): # do nothing pass From 1df4e74c30e967f029e698d868c124f98afcb8fb Mon Sep 17 00:00:00 2001 From: Wasif Malik Date: Sat, 2 Aug 2014 23:58:31 +0200 Subject: [PATCH 28/29] fix spelling mistake in ex_7segment_clock.py --- Adafruit_LEDBackpack/ex_7segment_clock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_LEDBackpack/ex_7segment_clock.py b/Adafruit_LEDBackpack/ex_7segment_clock.py index 634b6178..99f00ab1 100644 --- a/Adafruit_LEDBackpack/ex_7segment_clock.py +++ b/Adafruit_LEDBackpack/ex_7segment_clock.py @@ -23,7 +23,7 @@ # Set minutes segment.writeDigit(3, int(minute / 10)) # Tens segment.writeDigit(4, minute % 10) # Ones - # Toggle color + # Toggle colon segment.setColon(second % 2) # Toggle colon at 1Hz # Wait one second time.sleep(1) From 400ca3ecfb5123ed022b8ed2a3e7ca68b6f3f12f Mon Sep 17 00:00:00 2001 From: Joel Kuntz Date: Fri, 12 Sep 2014 07:54:20 -0300 Subject: [PATCH 29/29] Improved git clone link in README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aba2ae53..8f342a3a 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,11 @@ Adafruit's Raspberry-Pi Python Code Library BSD license, all text above and below 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 +```bash +git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git +``` + ============ Copyright (c) 2012-2013 Limor Fried, Kevin Townsend and Mikey Sklar for Adafruit Industries. All rights reserved.