onion omega2 and onion-i2c

I've been programming for a while but I'm new to Python and a true neophyte with i2c and sensor devices.

I'm using an Onion Omega adapter to connect to the sensor but can't even to get the device to respond to its Read Device Identification command.

I've trimmed the onion-i2c. python script to:

from OmegaExpansion import onionI2C
import time
import sys

print 'Starting: onionI2C module testing...'

i2c     = onionI2C.OnionI2C()

# set the verbosity
i2c.setVerbosity(1)

devAddr = 0x2a


# perform series of writes
addr     = 0x00
value    = [42, 146, 106, 2, 0, 0, 0, 0, 254]
print 'Writing to device 0x%02x, address: 0x%02x'%(devAddr, addr)
val     = i2c.writeBytes(devAddr, addr, value)
print '   writeBytes returned: ', val


addr     = 0x2a
value    = [146, 106, 2, 0, 0, 0, 0, 254]
print 'Writing to device 0x%02x, address: 0x%02x'%(devAddr, addr)
val     = i2c.writeBytes(devAddr, addr, value)
print '   writeBytes returned: ', val

addr     = 0x92
value    = [106, 2, 0, 0, 0, 0, 254]
print 'Writing to device 0x%02x, address: 0x%02x'%(devAddr, addr)
val     = i2c.writeBytes(devAddr, addr, value)
print '   writeBytes returned: ', val

print 'Done!'
 

but all I get is:

Starting: onionI2C module testing...
Writing to device 0x2a, address: 0x00
   writeBytes returned:  None
Writing to device 0x2a, address: 0x2a
   writeBytes returned:  None
Writing to device 0x2a, address: 0x92
   writeBytes returned:  None
Done!
 

Can anyone help?

 

Target Product: 
I2CCMAC115A_DLCT03C20
B

try to run i2cdetect command and it should respond with an address.

once it responds with 0x2A( no address jumper installed) please use this code.

 

from OmegaExpansion import onionI2C
import time
import sys
print 'Starting: onionI2C module testing...'
i2c     = onionI2C.OnionI2C(0)
# set the verbosity
i2c.setVerbosity(1)
command2 = [0x6A, 0x02, 0x00, 0x00, 0x00, 0x00, 0xFE]
#while True:
#print ""
#ret = raw_input('  Ready to read?')
data = i2c.writeBytes(0x2A,0x92,command2)
#print '   Read returned: ', data
print ' write bytes: ', command2
# Convert the data to 14-bits
time.sleep(0.5)
data = i2c.readBytes(0x2A, 0x55, 3)
typeOfSensor = data[0]
maxCurrent = data[1]
noOfChannel = data[2]
# Output data to screen
print "Type of Sensor : %d" %typeOfSensor
print "Maximum Current : %d A" %maxCurrent
print "No. of Channels : %d" %noOfChannel


while True:
        command1 = [0x6A, 0x01, 0x01, 0x06, 0x00, 0x00, 0x04]

        data2 = i2c.writeBytes(0x2A,0x92,command1)
        print ' write bytes: ', command1
        time.sleep(0.5)
        data1 = i2c.readBytes(0x2A, 0x55, noOfChannel * 3)
        # Convert the data
        #while True:
        for i in range(0, noOfChannel) :
                msb1 = data1[i * 3]
                #print ' msb1: ', msb1
                msb = data1[1 + i * 3]
                #print ' msb: ', msb
                lsb = data1[2 + i * 3]
                #print ' lsb: ', lsb
                #print ' i: ', i
                # Convert the data to ampere
                current = (msb1 * 65536 + msb * 256 + lsb) / 1000.0
                # Output data to screen
                print "Channel no : %d " %(i + 1)
                print "Current Value : %.3f A" %current
                time.sleep(5)
                print "\n"
                print "New Updated Current Values are: "

 

Tom Stiller's picture

I may have a problem withthe board.

i2cdetect returns:

 i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: 30 31 32 33 34 35 36 37 -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  

 

No device 0x2a

B

how you are connecting the onion omega adapter with your board.

if you have a particle photon board and want to connect it with onion omega i2c shield then you will need this adapter

https://www.controleverything.com/content/Adapters?sku=SI

because your onion omega has an I2C out port and so does the current monit board.

so you will need this SI adapter to install an I2C in port.

Thanks

 

Tom Stiller's picture

Thank you very much. I thought I only needed the Omega adapter board but I either got the wrong sensor board or just misunderstood the specs.

Thanks again.

B

Hi Tom,

if you want to use this current sensor directly with onion omega then you will need an onion omega I2C adapter ( i guess the one you have is onion omega I2C shield).

like this one.

https://www.controleverything.com/content/I2C-Master?sku=OC

this adapter will plug into the particle electron board and then you can plug onion omega into it.

so if i were you and wanted to build an onion omega  resistive current monit board I will get these two boards

1. https://www.controleverything.com/content/Current?sku=PECMAC210A_DLCT03C20

2. https://www.controleverything.com/content/I2C-Master?sku=OC

Thank You, Tom.

 

 

Tom Stiller's picture

If I understand correctly, I can use the board I have marked:

PR26-7 -- SCCMAC 210A -- DLCT03C20

but substituting adapter PR32-3 (OC ) for the one I have PR32-2 (OB), is that correct?

 

B

please, can you tell me few things? without power up the board.

 

1. can you plug the OB adapter in your board? ( the onion omega adapter will have some extra pins, don't worry about them).

2. does it fit properly? 

3. if it doesn't then please plug your onion omega in it. 

after doing this please post a picture here.

Thank You, Tom.

 

Tom Stiller's picture

Thanks for staying with this.  Yes, the OB will plug into the sensor; that's the configuration I was using at the start of this thresd.

Tech Support at ControlEverything says I have the wrong boards for what I want to do and advise exchanging them for:

https://www.controleverything.com/content/Current?sku=PECMAC210A_DLCT03C20

and https://www.controleverything.com/content/I2C-Master?sku=OC

Thanks again for all your help.

 

B

Hi all,

maybe I have a similar problem. But I am using different types of hardware. I have an Onion Omega 2, this https://shop.controleverything.com/collections/energy-monitoring/products/12-channel-on-board-ac-current-monitor-for-i2c current monitor board and https://shop.controleverything.com/collections/onion-omega/products/i2c-breakout-for-onion-omega-with-ethernet-port as the i2c connection board.

As far as I understand this combination should work. But I have a looks like problem as Tom Stiller, i get no status after writing to i2c bus and i2cdetect shows:

root@Omega2-01:~# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: 30 31 32 33 34 35 36 37 -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
 

I have tested different write options. Here are my examples:

bytes16 = [0x92, 0x6A, 0x1, 0x1, 0x6, 0x0, 0x0, 0x4]
status = I2C.write(0x2A, cur_bytes)

or:

bytes16 = [0x6A, 0x1, 0x1, 0x6, 0x0, 0x0, 0x4]
status = I2C.writeBytes(0x2A, 0x92, cur_bytes)

these are for the first 6 sensors. for the other sensors I use:

bytes612 = [0x92, 0x6A, 0x1, 0x7, 0xc, 0x0, 0x0, 0x0]
status = I2C.write(0x2A, cur_bytes)

or:
bytes612 = [0x6A, 0x1, 0x7, 0xc, 0x0, 0x0, 0x0]
status = I2C.writeBytes(0x2A, 0x92, cur_bytes)

The returned status is always None. But If I read from the I2C Bus afterwards I get, while sending the first bytes16:
rd_bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 180,181]

Note: I have a 100W lamp at sensor 6, so as far as i can interpred I get the correct value but after after my second read (after sending bytes612) I get wrong values:
rd_bytes: [0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
 

Have anybody an idea?

Thanks for your support,

Volker Helms

T

Hi Volker,

Onion has a bug on the Onion2 where I2CDetect does not work.  We as well as several members of their community have made this clear to them and they are suppose to be resolving it.  General call and i2cdetect however does not currently work.  That said I2C communciation for write and read does work.

Have you taken a look at this sample code:

https://github.com/ControlEverythingCom/Pi-Current-Monitor-Web-1/blob/master/CurrentMonitor.py

You could give it a try.  If the write or read functions fail then you will be notified in the terminal which generally happens due to bad connection to the board in one way or another.  Please let me know what you find.

Also you may need to change the smbus.SMBus(1) if that is not the correct I2C bus identifier on the Onion2.  I cannot remember off the top of my head if that is right or not.

Let us know what you find.