[tt]Hello, this code works fine with an arduino Uno and an SHTC3 (Temp Sensor) and Wire library.
Good temp and TH.
To run on an Attiny85 I am using the TinyWireM library and I have wrong measurements.
I tested with an internal clock at 8 Mhz or 1 Mhz.
Same wrong measurements.
Can you help me please? Have you an example ?Thank you.
Example of bas measurements :
17:42:32.538 -> Temperature: 40.20 C
17:42:32.538 -> Temperature: 104.36 F
17:42:32.538 -> Humidity: 0.00 %
[/tt]
#define I2C_Address 0x70
#define reset 0x905D
#define sleep_mode 0xB098
#define wake_mode 0x3517
#define measure_mode 0x7CA2
#include "TinyWireM.h" // A la place de Wire.h
#include <SoftwareSerial.h>
SoftwareSerial Serie(1, 4);
void setup() {
// put your setup code here, to run once:
Serie.begin(9600);
TinyWireM.begin();
// soft reset
TinyWireM.beginTransmission(I2C_Address);
TinyWireM.write((int)reset >> 8);
TinyWireM.write((int)reset & 0x00FF);
TinyWireM.endTransmission();
delay(1000);
// sleep
TinyWireM.beginTransmission(I2C_Address);
TinyWireM.write((int)sleep_mode >> 8);
TinyWireM.write((int)sleep_mode & 0x00FF);
TinyWireM.endTransmission();
delay(1000);
// wake
TinyWireM.beginTransmission(I2C_Address);
TinyWireM.write((int)wake_mode >> 8);
TinyWireM.write((int)wake_mode & 0x00FF);
TinyWireM.endTransmission();
delay(1000);
}
void loop() {
// measure_mode
TinyWireM.beginTransmission(I2C_Address);
TinyWireM.write((int)measure_mode >> 8);
TinyWireM.write((int)measure_mode & 0x00FF);
TinyWireM.endTransmission();
delay(1000);
TinyWireM.requestFrom(I2C_Address,5);
int temp1 = TinyWireM.read();
int temp2 = TinyWireM.read();
int check1 = TinyWireM.read(); // Do not care. Just a place holder
int hum1 = TinyWireM.read();
int hum2 = TinyWireM.read();
//int check2 = TinyWireM.read();
float temp = (temp1 << 8) | (temp2 << 0);
float humidity = (hum1 << 8) | (hum2 << 0);
//Convert data to Celsius
temp = -45 + 175 * ((float)temp/65535); //2^16 = 65535
float fahrenheit = temp * (9.0/5) + 32.0;
//Convert humidity to percent
humidity = 100 * (humidity/65535);
Serie.print("Temperature: ");
Serie.print(temp);
Serie.print(" C \n");
Serie.print("Temperature: ");
Serie.print(fahrenheit);
Serie.print(" F \n");
Serie.print("Humidity: ");
Serie.print(humidity);
Serie.print(" % \n");
Serie.print(" \n");
delay(1000);
}
[tt]
Extrait from TinyWireM.cpp [/tt]
/*
TinyWireM.cpp - a wrapper class for TWI/I2C Master library for the ATtiny on Arduino
1/21/2011 BroHogan - brohoganx10 at gmail dot com
Thanks for your help.
If I understood your answer correctly, I am using an attiny85 on a test bench connected to a SHTC3.
I load the tiny program via an arduino Uno in Arduino as ISP setting.
This attiny85 works fine as I have done OK tests with DHT11.
But for the case of SHTC3, I don't have Pull Up resistors on SDA and SCL.
If necessary, these resistors have what values please and are they connected between SDA / SCL and 5V.
Thank you for your answers.