Analogreadings with UEXT and python, I2C or SPI?

Started by fushfush, April 14, 2014, 12:03:04 PM

Previous topic - Next topic

fushfush

Hey guys!

I want to measure a lot of analog devices like temperature, hall effect, and light LDR's, with my A20.
How do i do that? From scratch i know i have to use the UEXT port with some sort of a chip that use I2C or SPI.
Like these:
http://www.adafruit.com/product/732 
Or this:
https://www.adafruit.com/products/856
Can someone tell what this is about or give me links to how they are used?

What do i need to do this under debian with python? Is it possible to read 10+ analog-readings?

Thanks!

dave-at-axon

I am using the MCP3428, actually 2 of them on my Android based A20. They work very will with the I2C bus and I have nice stable 16 ADC readings.

I also have a plug in module that can add an additional 4 MCP3428 devices which gives me a total of 20 channels.

fushfush

What did you do to make them work?
That python library did you use and will it work under debian??
is it possible that you will share this plug in module?

blejku

Python library for handling I2c is SMBUS under linux.
There are many examples on the web how it works.
There are no problems with the A / D, D / A, and other systems.
A20 is from what I remember 3 I2C bus system so you can "theoretically" could connect hundreds at a time, depends on the addressing.
If you want I'll send you an example for MCP 3221 A/D

Regards

herter

Hello,

@blejku: I'm interesting in this A/D who can be good for my application, can you send an example?
Indeed, I have not try to use I2C on my A20 yet.
Thanks a lot.
Regards

blejku

# I2c Przetwornik 12bit A/D MCP 3221
# Blejku

#
import smbus
import time
import datetime

#SMBus Olimex UEXT1 = 2
#SMBus Olimex UEXT2 = 1
#Raspberry smbus = 1

bus = smbus.SMBus(1)

#I2C addres

# tylko adres 0x4d dla tego ukladu jest mozliwy

address = 0x4d


def get_val():

   bus = smbus.SMBus(1)

   data = bus.read_i2c_block_data(address, 1,2)
   val = (data[0] << 8) + data[1]
   print val
   time.sleep(1)

while 1 == 1:
   get_val()

herter

Hello,

Thank you for your example, but I meet some trouble on the communication.
I installed the i2c utilities (smbus and i2c-tools) and I monitor my twi1-sda and twi1-sck signals on a scope.
I have this error:
[Errno70] Communication error on send
So where is the issue?
To visualize the signals, the chip must be plugged?
yet, when I launch i2cdetect -y 1 I see all the devices plugged and signals on the scope.

blejku

after calling "i2cdetect-y 1" corresponds to the system to address 0x4d?
Is the bus is working properly?
On the bus can be located also other systems, which are in the A20 but I think you know.
So let's start with that.

I do not understand a question of chip need to be connected.
How is your connection diagram layout?

if so, may be something wrong with encoding a file with copy / paste from the browser.
But I do not think he has just copied the code back and it`s work on Raspberry PI currently, but it was written on the A20 and also worked there.
Thus, the variable "bus"


Sorry to write off the delay.

herter

Hello,

Sorry for my lack of explanations.
In fact, I try to write on i2c bus, like this code example:
http://www.raspberry-projects.com/pi/programming-in-python/i2c-programming-in-python/using-the-i2c-interface-2
and I try to read 2 bytes with the function which you are used.
I haven't plugged my chip yet, but, first of all, I want to visualize my signals SDA and SCL on a scope. However, I saw nothing, but my signals are pulled-up.
So when I called i2cdetect -y 1, and don't have the 0x4d adress, that is normal.
Usually, with a basic µC, I can visualize  what I send on SDA and SCL on a scope without device plugged.
According to the error above, I wonder if it's because it not detect the chip.
Thank for your reply.


blejku

A20 should send a signal to the bus without a problem. No checks or something before it physically exists or not. So it was a little strange.

And if you have it plugged into the appropriate bus? A20 are three i2c buses

Regards

herter

Hello,

It's ok I communicate with the chip and so I can see her address at 0x4d when I do the i2cdetect -y 1 command.
Thanks blejku,
regards.