Hi everyone, I just got my BBB and I wanted to get temp/humidity so I got a HIH6130. I have a good amount of experience with OOP and HDLs, so I can read code and I also understand the low level stuff working directly with bits, however I have zero experience with I2C and I have no idea how to use it.
I read a lot of other simple I2C programs, one example being http://beagleboard.org/Support/BoneScript/demo_bmp085/
I modified the code to match the address of the HIH6130 and the two functions given by the kernel driver (https://www.kernel.org/doc/Documentation/hwmon/hih6130)
`
var b = require(‘bonescript’);
var iic = ‘/sys/class/i2c-adapter/i2c-1/’;
//Sensor Locations on the BeagleBone Black
var temperature = ‘/sys/bus/i2c/drivers/hih6130/1-0027/temp1_input’;
var humidity = ‘/sys/bus/i2c/drivers/hih6130/1-0027/humidity1_input’;
// We will initialize the driver for the BMP085 sensor located at I2C location 0x77
b.writeTextFile(iic + ‘new_device’, ‘hih6130 0x27’);
// Opens,reads, and prints humidity and temperature
b.readTextFile(humidity, printHumidity);
b.readTextFile(temperature, printTemperature);
// Prints humidity
function printHumidity(x) {
console.log("humidity: “, x.data/100 + " %”);
}
// Prints Temperature
function printTemperature(x) {
// ‘\xB0’ is the degree symbol in hexademical
console.log("Temperature: “, x.data/10 + ‘\xB0’ + " Celcius”);
x.data /= 10;
x.data *= 1.8;
x.data += 32;
console.log("or: “, x.data + ‘\xB0’ + " Fahrenheit”);
}
`
I didn’t really care about the math behind the information so I left it alone. When the above code is run I get NaN for everything. I’m assuming because it is literally trying to read the “temp1_input” and just dump that to the screen. However…
`
root@beaglebone:/sys/class/i2c-adapter/i2c-1/1-0027# cat temp1_input
cat: temp1_input: Invalid argument
`
nothing is there.
According to the datasheet (http://www.phanderson.com/arduino/I2CCommunications.pdf) It says the device is sleeping and needs to be sent a “measurement request” command in the form of [6bit address][0].
My main problem is I’m not sure how to send data directly to the bus. I was thinking about using the i2cset command, but that doesn’t seem right as it sets a specific address of memory on a specific device. According to the datasheet I’m not trying to send it data other then the address + a ‘0’ but the other i2c tools don’t seem to be any more help.
Last, here’s an i2c dump of the device.
`
root@beaglebone:/sys/class/i2c-adapter/i2c-1# i2cdump 1 0x27
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1, address 0x27, mode byte
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e ^^^^^^^^^^^^^^^^
10: 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e ^^^^^^^^^^^^^^^^
20: 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 5e 17 57 57 57 57 ^^^^^^^^^^^?WWWW
30: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
40: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
50: 57 57 57 57 57 57 57 17 57 57 57 57 57 57 57 57 WWWWWWW?WWWWWWWW
60: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
70: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
80: 57 57 57 17 57 57 57 57 57 57 57 57 57 57 57 57 WWW?WWWWWWWWWWWW
90: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
a0: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 17 WWWWWWWWWWWWWWW?
b0: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
c0: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
d0: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
e0: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
f0: 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 WWWWWWWWWWWWWWWW
`
I wouldn’t call it “garbage data” per se, however it isn’t very useful.
If anyone has experience with the HIH6130 or really any pointers on how to send specific bytes directly to the I2C bus would be great.
Thanks a lot!