Using RA Hardware on a Raspberry Pi / Beaglebone Black

Expansion modules and attachments
Post Reply
dcartier
Posts: 33
Joined: Thu Sep 20, 2012 2:34 am

Re: Using RA Hardware on a Raspberry Pi / Beaglebone Black

Post by dcartier »

Just as a follow up, using the RA hardware from RPI/BBB (in this case ORP module) is great. As expected, you just need to create some interface classes to allow them to be read over I2C.

Here is an example of the ORP class I created to allow the ORP module to be used. In the example I have hard coded the calibration data, but you could also pass it in. You can re-calibrate by instantiating a new object and calling readRaw() to get the unconverted value and then hard coding the value, or override the calibration datain the instances. In the example I had calibrated at 0mv (1480) and 400mv (367).

The class only depends on the Adafruit I2C library for communication.

Code: Select all

#!/usr/bin/python
from Adafruit_I2C import Adafruit_I2C

class RA_ORP(object):

    def __init__(self, address = 0x4C, busnum = 1, calibration = ( 1480, 367, 0, 400 )):
        self.i2c = Adafruit_I2C(address=address)     
        self.address = address
	self.calibration = calibration
	self.queue = []
    	self.lastRaw = 0
    	self.overCnt = 0
    	self.maxChange = 300
	self.maxOverCnt = 20
	self.queueLength = 20
	self.debug = 0


    def readRaw(self):
	return self.i2c.reverseByteOrder(self.i2c.readU16(0x00))

    def readSingle(self):
	return self.convert(self.readRaw())

    def read(self):
	value = self.readRaw()
	if self.debug: print "Raw value read:",value
        if self.lastRaw == 0 or abs(value - self.lastRaw) < self.maxChange:
                self.queue.append(value)
                self.lastRaw = value
                self.overCnt = 0
        else:
                self.overCnt += 1
                if self.overCnt > self.maxOverCnt:
                        self.overCnt = 0
                        self.queue.append(value)
                        self.lastRaw = value

        if len(self.queue) > self.queueLength:
                self.queue.pop(0)

	return self.convert(self.mean())

    def convert(self,x):
    	return (x - self.calibration[0]) * (self.calibration[3] - self.calibration[2]) // (self.calibration[1] - self.calibration[0]) + self.calibration[2]

    def mean(self):
    	n = len(self.queue)
    	if n < 1:
        	raise ValueError('mean requires at least one data point')
    	return sum(self.queue)/n
Dennis
dcartier
Posts: 33
Joined: Thu Sep 20, 2012 2:34 am

Re: Using RA Hardware on a Raspberry Pi / Beaglebone Black

Post by dcartier »

I am working on the planning for a new project that will require 2 PH expansion modules on a Raspberry Pi. I have found TCA9548A breakout boards that allow 1 to 8 multiplexing of the I2C bus, so that should take care of the address conflict between the modules. The multiplexer also allows for mixed voltage setups and does voltage translation. Yay!

What I am wondering about are pull ups on the SDA and SCL lines. I had a look at the ORP expansion schematic (there does not seem to be a PH one in the downloads), and it shows 10K pullups to the +5V line. Do all the expansion modules include their own pullups? If so that will make it a lot easier to interface to an RPI using a TCA9548A.

Last question, all the modules use their own power supply, so I expect that I can leave the +5V line on the USB interface disconnected? The RPI will be using 3.3V, so if I hookup only ground, SDA and SCL to the multiplexer I should be good?

Dennis
Post Reply