Giter Site home page Giter Site logo

adafruit-raspberry-pi-python-code's Introduction

Adafruit's Legacy Raspberry Pi Python Code Library

What happened to all the Raspberry Pi Python code!?

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 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 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!

adafruit-raspberry-pi-python-code's People

Contributors

asheeshr avatar boobsd avatar boxysean avatar corburn avatar daomry avatar davidmmiller avatar dberlin avatar driverblock avatar fernandofussuma avatar foobar2016 avatar frozenfire92 avatar gooligumelec avatar houqp avatar jwcooper avatar kenrbell avatar ladyada avatar larsks avatar marcoschwartz avatar matjaz avatar microbuilder avatar mrichardson23 avatar muenchhausen avatar paintyourdragon avatar rogg avatar sebastianludwig avatar shinncchen avatar tdicola avatar wckddev avatar wmalik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit-raspberry-pi-python-code's Issues

Driver prints emulates character into system

I found out that on my PI somthing is sending the letter 'r' into the system (like if you pressed it on the keyboard).

When checking en troubleshouting all the drivers and pins i used, I figured out it was the driver for the 16x2 display. Even when the display (and any other wire) is attached to the Pi, it keeps sending the 'r'.

Is there a workaround for this?

Adafruit_MCP230xx is missing MCP23008 defines

I believe these defines are missing from the code for MCP23008 support:

MCP23008_IODIR = 0x00
MCP23008_GPIO = 0x12    # these are not confirmed
MCP23008_GPPU = 0x0C    # these are not confirmed
MCP23008_OLAT = 0x14    # these are not confirmed

Bugs, indent problems and re returning.

MCP230xx.py file has multiple indent problems (STILL),

Adafruit_MCP230XX.output() has two returns and if the if statements are false, can't return. (referencing before assingment)

Adafruit_MCP230XX.input() returns the "value" which may be referenced before assingment.

Adafruit_MCP230XX.pullup() has a variable called "lvalue" which does nothing and the function is not working properly.

MCP230XX_GPIO class should be in a different branch. It's just a useless proxy for now.

Whole script is not compatible PEP8 standards, nor with Zen (PEP20). It designed well but coded poorly. I may commit but have no time, This is just a warning for developers. (Especially to KTOWN who committed "Fixed indents", can't you just use regex to find \t characters and replace them with four spaces?)

"Errors should never pass silently.
Unless explicitly silenced." Zen of Python.

Regards.

DHT_Driver DHT11 versus DHT22 inconsistent readings

I test DHT22 and DHT11 side-by-side (common Vdd/Gnd/Null) Data connected to pins 24 and 25.
The figures generated by DHT22 seems reliable as well as temperature in case of DHT11.
The problem is with humidity as reported by DHT11 sensor
which is circa 20% below expected/reported by DHT-22 value (for example 56% versus 38%). Cannot explain this phenomenon:-)

MCP Conveniece methods

I'd also like to suggest adding the following convenience methods- these allow using the MCP as a byte/word driver in parallel mode and are structured similiar to the Adafruit_I2C class:

def readU8(self):
    result = self.i2c.readU8(MCP23017_OLATA)
    return(result)

def readS8(self):
    result = self.i2c.readU8(MCP23017_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(MCP23017_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)

Default PI python version is 2.7 - Spaces/Tabs all need to be fixed

Currently...I am manually fixing the files I need to use, but considering that there were 6 Errors and 221 Warnings in ADAFruit_CharLCD.py alone.

All of the warnings were related to blank lines, space/tab mixings, and the always fun multiples of 4 on tabs.

Can this be resolved across all files or could new branches for everything to the different versions of Python be done?

I am sure the requirements have changed again in Python 3.

Thanks,
Jeff

Recent changes to Adafruit_I2C.py break BMP085 on RasPi

Hi,

The following changes seem to break the BMP085 when running on a Raspberry Pi. If I revert these changes it works fine.

@@ -108,8 +108,7 @@
   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)
+      result = self.bus.read_word_data(self.address, reg)
       if self.debug:
         print ("I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" %
          (self.address, result & 0xFFFF, reg))
@@ -120,10 +119,8 @@
   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)
+      result = self.bus.read_word_data(self.address, reg)
+      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))

Adafruit_PWM_Servo_Driver broken; "IOError: 13" on importing module

The PWM servo driver module is broken. It's producing this error when I import it:

Traceback (most recent call last):
  File "/home/pi/git/BodySensor/PiDispatcher/venv/bin/dispatcher_server", line 9, in <module>
    load_entry_point('dispatcher==0.0.1', 'console_scripts', 'dispatcher_server')()
  File "/home/pi/git/BodySensor/PiDispatcher/venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 519, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/pi/git/BodySensor/PiDispatcher/venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2630, in load_entry_point
    return ep.load()
  File "/home/pi/git/BodySensor/PiDispatcher/venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2310, in load
    return self.resolve()
  File "/home/pi/git/BodySensor/PiDispatcher/venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2316, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/pi/git/BodySensor/PiDispatcher/dispatcher/server.py", line 5, in <module>
    from dispatcher.Adafruit_PWM_Servo_Driver import PWM
  File "/home/pi/git/BodySensor/PiDispatcher/dispatcher/Adafruit_PWM_Servo_Driver.py", line 11, in <module>
    class PWM :
  File "/home/pi/git/BodySensor/PiDispatcher/dispatcher/Adafruit_PWM_Servo_Driver.py", line 35, in PWM
    general_call_i2c = Adafruit_I2C(0x00)
  File "/home/pi/git/BodySensor/PiDispatcher/dispatcher/Adafruit_I2C.py", line 43, in __init__
    self.bus = smbus.SMBus(busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber())
  File "/home/pi/git/BodySensor/PiDispatcher/venv/local/lib/python2.7/site-packages/smbus/smbus.py", line 119, in __init__
    self.open(bus)
  File "/home/pi/git/BodySensor/PiDispatcher/venv/local/lib/python2.7/site-packages/smbus/smbus.py", line 146, in open
    raise IOError(e.errno)
IOError: 13

Looking at the code, it's assuming that there is an i2c register at 0x00 that it can create a PWM object for. That's not the case on my system (using the latest Raspbian Wheezy circa this post, and the Adafruit 16-channel PWM microcontroller).

My valid I2C addresses are:

$ sudo i2cdetect -y 0                                                                                                                                                                      
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         

Is there some requirement that I'm missing to get this working? Or is the code making an assumption that doesn't hold on all platforms?

Running Alhanum4_test

I receive an error saying display=AlphaNum4.AlphaNum4()
AttributeError: type object has no attribute 'AlphaNum4'

Using Python 2.7 on a raspberry pi

Test script for HD44780 LCD connected to RPI via 'i2c / SPI character LCD backpack'

I have connected a HD44780 compatible LCD to a Raspberry Pi (revB) using the 'i2c / SPI character LCD backpack' from Adafruit.

Using the library, I created the following test script:

   #!/usr/bin/python

   from Adafruit_CharLCD import Adafruit_CharLCD
   from Adafruit_MCP230xx import MCP230XX_GPIO

   mcp = MCP230XX_GPIO(1, 0x20, 8)
   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")

Note: the following patch needs to be applied to Adafruit_MCP230xx.py:

diff --git a/Adafruit_MCP230xx/Adafruit_MCP230xx.py b/Adafruit_MCP230xx/Adafruit_MCP230xx.py
index 19bc372..cbad92d 100755
--- a/Adafruit_MCP230xx/Adafruit_MCP230xx.py
+++ b/Adafruit_MCP230xx/Adafruit_MCP230xx.py
@@ -185,7 +185,7 @@ class MCP230XX_GPIO(object):
     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):
         pass # do nothing
     def setup(self, pin, mode):

Adafruit_I2C does not parse the Pi Revision info properly

There is a static method in Adafruit_I2C class that reads the 'revision' info from /proc/cpuinfo.

No matter if the board is at rev 1 (first model with 256 MB) OR rev 2 (second model with 512 MB), the method will return the same value ('1').

This will cause a problem in the class initialization for board rev 2.

I suggest to change this method (getPiRevision in Adafruit_I2C) from:

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

to:

with open('/proc/cpuinfo', 'r') as f:
for line in f:
if line.startswith('Revision'):
return line.rstrip()[-1]

Using i2c library

Ok, before I start this, let my just say that I am a total NOOB, I just got my pi for Christmas, and I am still learning how to use it (but I do know how to use Arduino).

How do I use the adafruit i2c Python library? there seems to be no documentation on it.

PyPI Package

Thank you for all you work on this, is there any chance this could be broken out into individual modules, packaged, and submitted to PyPI?

As it stands today, it's impossible to redistribute modular code that relies on these libraries.

I would love to be able to do pip install Adafruit_7Segment and have it pull in the latest Adafruit_LEDBackpack and Adafruit_I2C.

DHT Python error in readme

There is an error in the Readme for the Python DHT code:

The line
print dhtreader(type, pin)

Should be
print dhtreader.read(type, pin)

ImportError : No module named Adafruit_CharLCD

When i create a new program in Desktop and try to import the Adafruit_CharLCD i get this error: ImportError : No module named Adafruit_CharLCD

but when i move the program to the folder Adafruit_CharLCD works fine.
How can i make this to work wherever i save it?

DHT Driver doesn't work

Adafruit forums are full of commentary on how the DHT Driver doesn't work (returns all zeros).

Very frustrating because it's touted in tutorials and after trying two Raspberry pis and 2 2302 sensors I can confirm that this is not user error or broken hardware-- the drivers just do not work!!

Adafruit_MCP230XX : wrong adresses for MCP23008

Hello,

The code for Adafruit_MCP230XX uses wrong adresses for MCP23008. To make it work, I had to make the following changes (addresses come from MCP23008 datasheet)

MCP23017_IODIRA = 0x00
MCP23017_IODIRB = 0x01

MCP23017_GPIOA = 0x12

MCP23017_GPIOA = 0x09
MCP23017_GPIOB = 0x13

MCP23017_GPPUA = 0x0C

MCP23017_GPPUA = 0x06
MCP23017_GPPUB = 0x0D

MCP23017_OLATA = 0x14

MCP23017_OLATA = 0x0A
MCP23017_OLATB = 0x15

order of magnetic sensor reading of LSM303

Looks like the reading of magnetic sensor is in X, Z, Y order instead of X, Y, Z. Not a big issue :-)

... Adafruit/Adafruit_LSM303.py
res.append((self.mag16(list, 0), # X
self.mag16(list, 2), # Z
self.mag16(list, 4), # Y
0.0 )) # ToDo: Calculate orientation

Adafruit_DHT will eventually crash

The manipulation of bitidx in Adafruit_DHT will eventually cause a segfault. If readDHT is called repeatedly, this line:

    bits[bitidx++] = counter;

...will eventually increment bitidx beyond the end of the bits array.

This code (and the bits array) appear to be unused except for debugging and can be safely removed.

WS2801 only glows white

I used the Adafruit_LEDpixels.py code to test my WS2801 pixel strand but the only that it does is make them all glow white. I have Occidentalis installed. Any idea on what the problem might be?

Add HMC5883L and MPU6050

I'm pretty sure that adafruit sells these sensors. The HMC is a compass and I know that it exists in another repo, and te MPU is a 3 axis gyro and accelerometer.

Adafruit_PWM_Servo_Driver on rev 2 Raspberry Pi

I have a 16 channel servo driver (https://www.adafruit.com/products/815) that I connected to my Raspberry Pi rev 2, and now I'm trying to send data over I2C to make the motor work.

I'm trying to follow the instructions at http://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/using-the-adafruit-library.

It says to clone this repo:

$ git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
$ cd Adafruit-Raspberry-Pi-Python-Code
$ cd Adafruit_PWM_Servo_Driver

It also says to change the self.i2c = Adafruit_I2C(address) line, for the rev 2 Raspberry Pi:

If you have a second revision raspberry Pi, you'll need to update the default I2C port.  In the file Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py

change
self.i2c = Adafruit_I2C(address)
to
self.i2c = Adafruit_I2C(address, bus=smbus.SMBus(1))

You also need to add import smbus to the top of the file.

When I follow these instructions and then run "sudo python Servo_Example.py", I get this error:

[pi@raspberrypi] {master} ~/adafruit/Adafruit-Raspberry-Pi-Python-Code/Adafruit_PWM_Servo_Driver$ sudo python Servo_Example.py
Traceback (most recent call last):
  File "Servo_Example.py", line 12, in <module>
    pwm = PWM(0x40, debug=True)
  File "/home/pi/adafruit/Adafruit-Raspberry-Pi-Python-Code/Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py", line 31, in __init__
    self.i2c = Adafruit_I2C(address, bus=smbus.SMBus(1))
TypeError: __init__() got an unexpected keyword argument 'bus'

It looks like the Adafruit_I2C constructor doesn't let me pass in a bus? Do you know how I can get this working on my rev 2 RPi? Thanks!

Adafruit_8x8.py - addressing error in the ColorEightByEight class, setPixel() method.

I found and fixed a problem with the setPixel() method that is fixed by adding the following code just under the line that reads "x %= 8" there. Without this patch, column 0 (x=0) is treated as column 7 (x=7). With this patch, all pixels are addressed correctly, from (0, 0) to (7, 7).

# This modification fixes the pixel addressing error
if (x == 0):
  x = 7
elif (x > 0):
  x = x - 1
# End of modification for the pixel addressing error

--> geekguy on Adafruit forums.

method: reverseByteOrder does not always work

If the low order byte is 0x00, then the method reverseByteOrder does not work.

Example: I am reading the manufacturer's code for an Adafruit MCP9808, which is 0x0400.

The sixteen bit value returned by the method readU16 is 0x0004.
Swapping the bytes should result in 0x0400.
reverseByteOrder(0x0004) returns 0x0004.

Since the reverseByteOrder method decides whether it is dealing with a 32 bit or 16 bit value by examining where the bits are, it decides that 0x0004 is a one byte value, and does not swap the bytes.
It properly swaps 0x0104 or 0xFF03, which it correctly identifies as two byte values.

The 32 bit versus 16 bit value detector is fundamentally flawed. It would also detect the 32 bit value
0x0000FFFF as a 16 bit value, and return 0xFFFF instead of the correct 0xFFFF0000.

They only solution I can recommend is to split reverseByteOrder into two methods, one for swapping 16 bit values, and one for swapping 32 bit values.

def reverseByteOrder16(self, data)
    "Reverses the byte order of a 16-bit value"
    val=((data & 0xFF) << 8) | ((data & 0xFF00) >> 8)
    return val

--- Graham / KE9H

Adafruit_DHT_Driver incorrect readings on long wires (10m) using DHT11 + possible code fix

Adafruit_DHT_Driver incorrect reading on long wires.

I had a problem reading the temperature and humidity from the DHT11 connected to the Raspberry Pi using wires of 10 meters. The temperature reading was way too small and the humidity was in the 120-150% ranges. Various DHT11 was tested all with the same problem.

I then used Saleae Logic 16 logic analyser to inspect the signals coming into the rapberry pi. The signals coming from the DHT11 was correct. Due to a very short pulse high created by the DHT11 after the 500ms high and 20ms low and timing issues in the current driver software the error occurs. The code appends a high bit (1) to the data stream and drops the last bit which causes the error. The short high pulse is 19us for the long wires and 12us for the DHT11 directly connected to the raspberry pi.
I was able to correct the problem by adding 7 usec sleep to Adafruit_DHT.c:

data[0] = data[1] = data[2] = data[3] = data[4] = 0;
// inserted to compensate for long driving lines
usleep(7);

// wait for pin to drop?
while (bcm2835_gpio_lev(pin) == 1) {
usleep(1);
}

I hope that the above information might be helpful to others experiencing the same issue. If the above solution can be tested, adjusted and verified for the DHT22 and AM2302 it might even be included in the source.

LCDPlate replaces \ char with ¥

Outputting a backslash to the display with something like this ...

message_output = "Progress : "
lcd.message(message_output)
print message_output

results in a backslash being output to the command line, but a yen symbol ¥ outputted to the display.

Is there some sort of character encoding option I'm missing ?

BMP085 Incorrect Readings

I have very little experience with programming like this. I'm really learning from folks who are brave enough to put their code up to be shared, so thank you.

I had the Adafruit I2C library working, and I've been using the BMP085 sensors to monitor temperature and pressure. I recently updated to the newest version and my BMP085 temp sensors seem to be broken (I have a TMP102 sensor running on the same bus and it is reporting normally). I've swapped out BMP085 sensors and I'm getting consistent readings across the sensors.

(Byte Order not being reversed before returning Raw Temp)

According to the data sheet, the uncompensated temperature value needs to be byte reversed before being returned out of the function. Attempting to run the code for the BMP085 without doing this gives me obviously wrong, unstable values.

Adding
raw = self.i2c.reverseByteOrder(raw)
before the if(self.debug) statement gives a stable, but obviously wrong value.

(Parentheses placed incorrectly)
in the function
def readTemperature(self)
the
X1 = ((UT - self._cal_AC6) * self._cal_AC5) >> 15
seems incorrect. I think it should read
X1 = (UT - self._cal_AC6) * (self._cal_AC5 >> 15)

This gets me results that are closer to real, but still incorrect.

(Deviation from the datasheet)
This calculation is different from the datasheet:
temp = ((B5 + 8) >> 4) / 10.0
Where did the "/10" come from? With this, the values are wildly inaccurate, but I don't understand why it is needed.

Thank you

ADS1x15 Error: "Error accessing 0x48: Check your I2C address"

I keep receiving the following error:

pi@raspberrypi ~/ADS1115 $ python ads1x15_ex_singleended.py
Error accessing 0x48: Check your I2C address
Error accessing 0x48: Check your I2C address
Traceback (most recent call last):
File "ads1x15_ex_singleended.py", line 38, in
volts = adc.readADCSingleEnded(0, gain, sps) / 1000
File "/home/pi/ADS1115/Adafruit_ADS1x15.py", line 223, in readADCSingleEnded
val = (result[0] << 8) | (result[1])
TypeError: 'int' object has no attribute 'getitem'

I read the comment in ADS1x15.py that states:

133 # Depending on if you have an old or a new Raspberry Pi, you
134 # may need to change the I2C bus. Older Pis use SMBus 0,
135 # whereas new Pis use SMBus 1. If you see an error like:
136 # 'Error accessing 0x48: Check your I2C address '
137 # change the SMBus number in the initializer below!

Although, I do not know what exactly what I am required to change.

I know it would be very difficult to diagnose my issue with only the information that I have provided, but I would greatly appreciate any help in troubleshooting this issue.

Thanks in advance for any help you may provide!

ADS1x15 mistake

Hi, there's a mistake in the register definitions in file Adafruit_ADS1x15.py.
For the ADS1015 it says in line 57:
__ADS1015_REG_CONFIG_DR_920SPS = 0x0050
In binary that's 0000 0000 0101 0000. This sets the DR to 490SPS and the COMP_MODE to window mode!
It should be
__ADS1015_REG_CONFIG_DR_920SPS = 0x0060

I have also updated the library to include most functions of both chips. I wrote a post in the forum, that hasn't receive much attention, but I think it would be great if you added my changes to the library.
http://forums.adafruit.com/viewtopic.php?f=19&t=38466

Negative Temperatures not handled - Adafruit_DHT_googledocs.ex.py

Starting at line 46:

matches = re.search("Temp =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue

I don't have an elegant fix for this, but I know this works:

valid = 0
matches = re.search("Temp =\s+([0-9.]+)", output)
if (matches):
temp = float(matches.group(1))
valid = 1
else:
matches = re.search("Temp =\s+-?", output)
if (matches):
temp = float(matches.group(1)) * -1
valid = 1

if (not valid):
time.sleep(3)
continue

Adafruit_CharLCD.py

I noticed a small issue in the Adafruit_CharLCD.py source code where there were 2 noBlink functions with both of them setting the blinking cursor to on. Instead, noBlink should have set it to off and there should have been a blink() function to turn it on. I corrected my copy of the source and you can view my diff here mcherry/portablepi@7c7acf4#Adafruit_CharLCD.py

'Adafruit_MCP230XX' object has no attribute 'OUTPUT'

After following the instructions on the adafruit website for this product I received this error when trying to run the "Adafruit_CharLCDPlate.py" script. It is a simple fix however by editing "Adafruit_MCP230XX" and adding the lines:
self.OUTPUT = 0
self.INPUT = 1

to the Adafruit_MCP230XX object's init function.

I need help with this

I installed today and got this error message.

Tracback (most recent call last):
File " Adafruit_CharLCDPlate.py", Line 14, in
class Adafruit_CharLCDPlate(Adafruit_I2C):
TypeError: Error when calling the metaclass bases
module. init() takes at most 2 arguments (3 given)

Address of I2C Bus Has Changed in V2 Board

I have been trying to get the BMP085 example to work and kept getting bus errors. I am using a Rev 2 board and the bus has changed from #0 to #1. The following change fixes the problem:

diff --git a/Adafruit_BMP085/Adafruit_BMP085_example.py b/Adafruit_BMP085/Adafruit_BMP085_example.py
index 5e0d0be..92b2758 100755
--- a/Adafruit_BMP085/Adafruit_BMP085_example.py
+++ b/Adafruit_BMP085/Adafruit_BMP085_example.py
@@ -7,8 +7,8 @@ from Adafruit_BMP085 import BMP085

===========================================================================

Initialise the BMP085 and use STANDARD mode (default value)

-# bmp = BMP085(0x77, debug=True)
-bmp = BMP085(0x77)
+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

diff --git a/Adafruit_BMP085/Adafruit_I2C.py b/Adafruit_BMP085/Adafruit_I2C.py
index dd2dfa7..0855f42 100755
--- a/Adafruit_BMP085/Adafruit_I2C.py
+++ b/Adafruit_BMP085/Adafruit_I2C.py
@@ -8,7 +8,7 @@ import smbus

class Adafruit_I2C :

  • def init(self, address, bus=smbus.SMBus(0), debug=False):
  • def init(self, address, bus=smbus.SMBus(1), debug=False):
    self.address = address
    self.bus = bus
    self.debug = debug

2s complement for 1015

In the code I see that you have taken care of negative numbers for 1115 but not for 1015. I think that both of them use 2s complement arithmetic, so should this correction be applied to 1015 as well?

BMP085 wrong pressure

Hello
I connect this sensor BMP085 to my Raspberry PI B+ and i have a wrong pressure. In my city is pressure about 1022hPa but my sensor BMP085 show me about 993hPa.

Temperature in my city is -2 and sensor show about -2,6
How i can calibrate this ? Please help me.

DHT11 driver weird results

Date / Time Temperature C Humidity %
3/3/2013 20:55:13 537.6 896

Either these results are very strange or it is 998 degree Fahrenheit in my office. It uploads to my gspreadsheet just fine and I quadruple checked the wiring. Any ideas? I used your C driver...I am going to start debugging but just in case someone knows the answer already (always check cache first) I thought I'd submit this query.

ADS1x15 python: mistakes in error messages

While searching for how to do differential sampling in continuous sampling mode (still hunting for it!) I notice that the Adafruit_ADS1x15/Adafruit_ADS1x15.py file contains many errors in the print statements for invalid sps and pga values. Often sps and pga are swapped, both in name and in the example (e.g. gives mV instead of Hz).

patch here:
https://gist.github.com/HamishB/11246772

regards,
Hamish

Adafruit_CharLCD.py - Garbled text with 2ms delay for clear() and home()

Hi--

I purchased the 16x2 LCD from your website and hooked it up as specified in your tutorial. Initially, I was having a lot of problems with the text being garbled on the screen. It seemed like there was a less than 50% chance of the text coming out correctly.

I increased the delayMicroseconds from 2000 to 3000 for the clear() and home() methods and this greatly reduced the likelihood of garbled text-- perhaps down to 1%.

According to the table in the posted doc for the LCD (http://adafruit.com/datasheets/TC1602A-01T.pdf), clear() and home() can take up to 2.16ms.

I should also mention that I've had best results always calling clear() then home() before message(). When I just call clear(), sometimes the first character is omitted. If I just call home(), things get real crazy. :)

So, you might want to increase the delayMicroseconds... there could be other users running into the same problems.

spurious incorrect readings on BMP180 pressure sensor

I'm using a BMP180 pressure sensor hooked up to a Raspberry Pi on the I2C bus. I read the data from the sensors using your BMP085 library. This works fine in general, but sometimes I get bogus values for the pressure (I did not monitor temperature). These wrong values are always smaller than the correct (within the device's accuracy) pressure value.

I'm logging the pressure data with rrdtool and this is what I get (y axis ranges from 980 to 1020):

pressure-1

The blue curve shows the values in question, a new value is fed into the RRD every 10s.

I looked into the datasheet of the BMP180 and found that after requesting a conversion (measurement) you need to wait some time before performing the readout of the data from the sensor. Depending on the sensor mode this takes about 5 to 26ms (page 12).

The code in Adafruit_BMP085.py reads:

  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.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

So, python's time.sleep() is used to make the code wait for the conversion. This seems to be a problem, since the timing is not sufficiently accurate (maybe?). If I reduce the sleep time, I always get bogus results. Increasing the sleep times by a factor of 10 seems to make it better, but does to fix it in general.

What is going on here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.