April 26, 2024, 02:14:00 AM

change address mod-tc-mk2

Started by pyrolysium, February 11, 2014, 03:14:43 PM

Previous topic - Next topic

pyrolysium

First post here.
I've eight mod-tc-mk2 modules that eventually will share a i2c bus.
So I have to change the standard addresses to unique ones. So far no luck

Changing the jumper on the board don't seems to change the address to the promised value of 0xf0

import smbus
import time

def main():
    bus = smbus.SMBus(1)
    Addr = 0x48 # I2C address of MOD-TC-MK2
    PutNewAddr = 0xB0 # command to put in the new address
    Naddr = 0x51 # new address
   
    bus.write_byte_data(Addr, PutNewAddr, Naddr)
    time.sleep(0.5)
    print " ready"

if __name__ == "__main__":
   main()

Whatever I do I get errno 5 or errno 22

Does anybody a a suggestion or better working python code?

On the bright side i managed yesterday to read out the temperature from the thermocouple


Lurch

What version of the firmware do you have?
In version 3 the define is:

   #define SET_ADDRESS   0xF0

NOT 0xB0

pyrolysium

#2
That don't seem to be the solution!
oeps  :-[ that seems the solution it changes the address despite the error.
Pyhton get stranger and stranger!

    bus = smbus.SMBus(1)
    Addr = 0x23 # I2C address of MOD-TC-MK2
    PutNewAddr = 0xf0 # command to put in the new address
    Naddr = 0x51 # new address
   
line 22    bus.write_byte_data(Addr, PutNewAddr, Naddr)


the error still exist

Traceback (most recent call last):
  File "/home/pi/Desktop/re-addressmod-tc-mk2.py", line 27, in <module>
    main()
  File "/home/pi/Desktop/re-addressmod-tc-mk2.py", line 22, in main
    bus.write_byte_data(Addr, PutNewAddr, Naddr)
IOError: [Errno 5] Input/output error

changing Addr to 0xA0 as address of the mod-tc.mk2 gives
IOError: [Errno 22] invalid argument on line 22


Lurch

The user guides for MOD-IO, MOD-IO2 ans MOD-TC-MK2 seem to be pretty flaky.  The values don't match what's in the code.  I think Olimex needs to look at this.  You could try sending an eMail to support@olimex.com
They may not see this forum entry.

pyrolysium

#4
It worked, the error didn't go away but the new addresses where accepted.

this is the code I used in the end, it gives an IOerror but flashes the address

import smbus
import time

def main():

    bus = smbus.SMBus(1)
    Addr = 0x23 # I2C address of MOD-TC-MK2
    PutNewAddr = 0xf0 # command to put in the new address changed from 0xb0 to 0xf0 in firmware 3
    Naddr = 0x58 # new address
   
    bus.write_byte_data(Addr, PutNewAddr, Naddr)
    time.sleep(0.5)
    print " ready"

if __name__ == "__main__":
   main()

It's for the control of the demonstration furnace Pyrolysium is building, http://pyrolysium.org/category/demonstration-furnace/

Lurch

Glad to hear that it is working.
I'm guessing that the error is due to a timing problem - i.e. the command takes longer than your delay of 0.5. 
Flash erasing and writing can take some time.
You may have to use time.sleep(1) or so to get rid of the error - it means you are trying to read or write before the device is ready.

pyrolysium

#6
Looks more like a baud-rate and /or bit-stretching problem
when I set the baud-rate on the Raspberry-Pi under the 75.000
the error disappears.

sudo rmmod i2c_bcm2708
sudo modprobe i2c_bcm2708 baudrate=750000


No baudrate isn't the problem, further study revealed
The raspberry is not patient enough with the mod-tc-mk2 with version 3 firmware
I work around the temperature measurement by catching the error and throwing away the result.

        try:
            result=bus.read_i2c_block_data(ADDR, GetTemp, 4)
        except IOError:
            print("something went wrong, maybe the next time a proper result will be available")
 
It's for the control of the demonstration furnace Pyrolysium is building, http://pyrolysium.org/category/demonstration-furnace/

BAStumm

Compare notes?

I am working on a similar application (temperature/wattage control of IR heaters). I too am using a Raspberry Pi as the i2c master and several mod-tc-mk2 units to control the heaters. Using the analog on the mod-tc to get wattage readings, the tc for temperature and a GPIO to pulse the SSRs.

My system is mostly working but am still interested in comparing with your findings. Did you customize the v3 firmware for your project or use as-is? I customized for my purposes. So far it works quite well but I did have to slow the buad rate of the RPi and also disable clock stretching on the mod-tc-mk2 in the v3 firmware.