Best Answer delbiorobi, 05 November 2012 - 10:42 AM
I2CDevice.CreateWriteTransaction(new byte[] { 0x01, 0x60 })
try this.
Yes, it works!
Thank you very much NooM. Go to the full post
  | ||||||||||||||
I2C & temperature sensor TCN75A
Started by delbiorobi, Nov 03 2012 10:44 PM
Best Answer delbiorobi, 05 November 2012 - 10:42 AM
Yes, it works! Thank you very much NooM. Go to the full post
9 replies to this topic
#1Posted 03 November 2012 - 10:44 PM
Hi,
i'm trying to use emperature sensor TCN75A with Netduino Plus using I2C. I use this board: http://www.microbot....con-TCN75A.html My code is: using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace NetduinoPlus_Temp_01 { public class Program { public static void Main() { Byte[] rx = new Byte[2]; I2CDevice.Configuration config = new I2CDevice.Configuration(0x48, 400); I2CDevice sensore = new I2CDevice(config); I2CDevice.I2CTransaction[] settings = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { 0x01 }), I2CDevice.CreateWriteTransaction(new byte[] { 0x60 }), }; I2CDevice.I2CTransaction[] rd = new I2CDevice.I2CTransaction[] { I2CDevice.CreateReadTransaction(rx) }; sensore.Execute(settings, 250); while (true) { sensore.Execute(rd, 500); Debug.Print(rx[0].ToString() + rx[1].ToString()); Thread.Sleep(2000); } } } } I think (hope) my code is correct, but debug print is always 00. Or my I2C implementation is incorrect, or TNC75A is not supported by I2C .Net Micro Framework. Any suggestion? #2Posted 03 November 2012 - 11:14 PM
did you use pull-up resistors on your wiring?
also: you send 0x00, than read 2 bytes.
use my class in attachment.
do something like:
Write(new byte[] { 0x00 } );
than in your loop:
byte[] tmp = new byte[2];
Read(tmp);
than convert the data to something readable (it return 12 bit, split to 2x8 bit (2 bytes..).
also you can only gather data once every 240msec, so sleep this ammount.
//edit: this depends on your selected resolution! 9bit is 32msec
your device address seems to be ok (when you connected all 3 address pins to gnd!)
Attached Files
#3Posted 04 November 2012 - 04:15 PM
Thank you Noom,
the problem was pull-up resistors; i was convinced that they were integrated into the temperature sensor board, but it's not: now i can read temperature output. I'm trying your class, very useful, because i'll use 3 or 4 sensor with I2C.
#4Posted 04 November 2012 - 09:24 PM
It seems that
I2CDevice.I2CTransaction[] settings = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new Byte[1] { 0x01 }), I2CDevice.CreateWriteTransaction(new Byte[1] { 0x60 }) };is unable to write the registers of TCN75A. 0x01 point to config register, and 0x60 change the temperature resolution, but output value is not affected to these changes. Someone else uses it and has the same problem? using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace NetduinoPlus_Temp_01 { public class Program { public static void Main() { Byte[] rx = new Byte[2]; int tempreg = 0; float temperature = 0; I2CDevice.Configuration config = new I2CDevice.Configuration(0x48, 400); I2CDevice sensore = new I2CDevice(config); I2CDevice.I2CTransaction[] settings = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new Byte[1] { 0x01 }), I2CDevice.CreateWriteTransaction(new Byte[1] { 0x60 }) }; I2CDevice.I2CTransaction[] rd = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new Byte[1] { 0x00 }), I2CDevice.CreateReadTransaction(rx) }; sensore.Execute(settings, 500); while (true) { sensore.Execute(rd, 500); tempreg = rx[0]; tempreg = tempreg << 8; tempreg += rx[1]; tempreg = tempreg >> 4; temperature = (float)tempreg / 16; Debug.Print("Temperatura attuale: " + temperature.ToString() + "°C"); Thread.Sleep(2000); } } } } #5Posted 05 November 2012 - 02:16 AM
I2CDevice.CreateWriteTransaction(new byte[] { 0x01, 0x60 })
try this.
#6Posted 05 November 2012 - 10:42 AM Best Answer
Yes, it works! Thank you very much NooM. Attached Files#7Posted 20 December 2012 - 11:09 PM
I'm having the same issues with my TC74 sensor. I'm new to the C# world. Could you post your entire VisualStudio solution? So I could learn from it? Thanks. #8Posted 21 December 2012 - 10:51 PM
Never mind. I got it working with the TC74. #9Posted 18 March 2013 - 07:18 AM
namespace TCN75A example{ public class Program { private static Byte[] rxbuffer = new Byte[2]; private static I2CDevice tempSensor; private static int tempReg = 0; private static float tempValue = 0; public static void Main() { tempSensor = new I2CDevice(new I2CDevice.Configuration(0x48, 400)); I2CDevice.I2CTransaction[] settings = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new Byte[] { 0x01, 0x60 }), }; tempSensor.Execute(settings, 500); TimerCallback tempDelegate = new TimerCallback(tempRead); Timer tmrTemperature = new Timer(tempDelegate, null, 0, 60000); public static void tempRead(Object currentTime) { I2CDevice.I2CTransaction[] rd = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new Byte[] { 0x00 }), I2CDevice.CreateReadTransaction(rxbuffer) }; tempSensor.Execute(rd, 500); tempReg = rxbuffer[0]; tempReg = tempReg << 8; tempReg += rxbuffer[1]; tempReg = tempReg >> 4; tempValue = (float)tempReg / 16; } } } } #10Posted 01 December 2013 - 05:35 PM Hi, i know that this is an pretty old thread but i would like to use this sensor as well. My wiring: Vcc - 5V Gnd -> Gnd SDA -> A4 SCL -> A5
Can anybody explain my how to wire the PullUp Resistores as mentioned in the third post?
One more question, In the code the address is set to 0x48, is this the default adress of the sensor, or how to set a address. Thanks in advance Peter 0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||