Shop OBEX P1 Docs P2 Docs Learn Events
I2C code and the MCP9600 amplifer from Sparkfun — Parallax Forums

I2C code and the MCP9600 amplifer from Sparkfun

I am trying to build a temperature gauge for my wood burner, using a propmini and the above amplifer and a Type K thermocouple.

I have used in the past PropBasic for various projects, but am having trouble figuring out the I2C commands in Propbasic. Does anyone have working source code for I2C in propbasic that would not mind sharing?

Thank you....

Comments

  • JonnyMacJonnyMac Posts: 8,974
    edited 2024-03-19 14:48

    I never really used PropBasic (beyond some experiments) because Spin is so elegant. If you'll consider Spin, I have dozens of files that that use I2C. At its heart, I2C only has a few commands: start, write, read, and stop. From that you can build interfaces to various devices. I've attached a demo that uses an I2C LCD. You'll see that the demo uses an object for the LCD which uses the bare-bones I2C object. You could mimic this architecture by creating an object for the MCP9600 that uses the base I2C object. Your temperature gauge app would use the MCP9600 object.

  • dennodenno Posts: 222

    Perhaps, someone smarter then me, lots are smarter then me, that has used I2C in Propbasic can help. Here is what I have. Using Propbasic and the Propmini, I have written code to run Sparkfun's HMC6352 compass module using the I2C commands in Propbasic. Works beautifully, variable compass heading as I rotate the breadboard.

    Now removing the HMC6352, and plugging in Sparkfun's MCP9600 with Type K thermocouple attached to it, with the same pinouts, 3.3 volt, ground, SDA, and SCK. Still using I2C, applying power, I now get a constant readout on the screen of 65536, which as everyone knows is 2*16th power or 1111111111111111. Any thoughts?

    Aren't all I2C devices operating under the same code format. So, I have one I2C device works perfect and the other does not. Am I missing something?

    Thanks to all for your reading time and possible help...DenO

  • AribaAriba Posts: 2,685

    @denno said:
    ...

    Aren't all I2C devices operating under the same code format. So, I have one I2C device works perfect and the other does not. Am I missing something?

    They use the same protocol and hardware to access the registers inside a I2C device. But different Devices have different addresses and different registers.
    The compass has the I2C address $42 and $43, while the Thermocouple Amplifier has addresses $C0..$CF depending on the connection of the ADDRESS pin.
    So the MCP9600 just does not respond to the wrong address.

    If you have written the code to run the HMC6352, you should know how it works and what you need to change to match the address and registers you can find in the datasheet of the MCP9600.

  • Hi
    We might have a better idea if we saw both sets of code.
    Dave

  • JonnyMacJonnyMac Posts: 8,974

    I now get a constant readout on the screen of 65536, which as everyone knows is 2*16th power or 1111111111111111. Any thoughts?

    As Andy pointed out, those devices have different slave IDs; When you read from the bus that doesn't have the slave ID you're looking for, you'll get all 1s because there is nothing to pull the SDA line low to write a 0.

  • dennodenno Posts: 222
    edited 2024-03-18 20:18

    Thank you Ariba, I knew I was doing something wrong. I have looked over the 50 pages of the PDF for the MCP9600 and could not find the addresses you referred to. If you don't mind me asking, where did you find the addresses. With the HMC6354 the addresses are WRITE $42, READ $43 and GET HEADING $41. With the MCP9600, Is $CF for READ, $CO for WRITE...address for the GET TEMPERATURE? Thank you again...Truth be told, the PDF is a hard read...for me....
    DEnO

  • JonnyMacJonnyMac Posts: 8,974
    edited 2024-03-18 18:35

    When you have a new I2C part, look through the documentation for the communications section which usually provides nice details on the I2C transactions. In the MCP9600 docs you'll find this:

    Here they're calling it the command byte. In older docs it might be called the slave ID.

    In my I2C projects I tend to do something like this:

    MCP9600_WR      CON     %1100_000_0
    MCP9600_RD      CON     %1100_000_1
    

    Bit 0 of the slave id is the write (0) / read (1) bit. By creating these constants I find the code is easier to follow.

  • AribaAriba Posts: 2,685

    Also the Table and Notes on page 8 are important.
    If you connect the ADDR pin to Ground, you get the addresses $C0 for write and $C1 for read.
    But this ADDR pin is an analog input that lets you set 8 different addresses depending on the voltage you apply.

    Andy

  • dennodenno Posts: 222

    Thank you all for your expertise. I was able to get the propmini to communicate with the MCP9600 using the READ and WRITE addresses above. I also was able to do the same using a BS2sx. I am using a TYPE K thermocouple, as recommended, and in both situations above, propmini and the BS2sx, after converting C degrees to F degrees, using the standard formula, the MCP9600 reads 168 degrees F high. In other words, the actual burner surface was at 268 degrees, and the MCP9600 was reading 436 degrees. I put the thermocouple on top of my woodburner, and using a IR heat gun to take accurate readings. So, I have to figure what is going on there next. Thanks again to all...

Sign In or Register to comment.