#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Public Wire As WireMaster
Private wireerror As Byte = 0
Private deviceaddress As Byte
Private ctemp As Byte
End Sub
Private Sub AppStart
Serial1.Initialize(9600)
Wire.Initialize
Scanning
End Sub
Private Sub Scanning
Private bc As ByteConverter
Dim b(1) As Byte
Dim devices As Int
Log("Scanning started...")
devices = 0
For i = 0 To 127
deviceaddress = i
RunNative("icwirebegintransmisson", deviceaddress)
RunNative("icwireendtransmisson", Null)
b(0) = deviceaddress
If wireerror = 0 Then
Log("I2C device found at address: 0x", bc.HexFromBytes(b), " (", deviceaddress, ")")
devices = devices + 1
End If
If wireerror = 4 Then
Log("I2C device unknown at address: 0x", bc.HexFromBytes(b), " (", deviceaddress, ")")
End If
Next
If (devices = 0) Then
Log("No I2C devices.")
End If
Log("Scanning completed.")
'------------------------------------------------------------------------------------------
'get the temperature for SHT with inline C *****WORKS *********** !!!!!!
RunNative("sht", Null)
Log (ctemp)
' ---------------------------------------------------------------------------------------
Wire.WriteTo(0x45, Array As Byte(0x2c,0x06))
DelayMicroseconds(500)
'Dim c() As Byte =Wire.RequestFrom(0x45,6)
' Log (c(0))
' Log (c(1))
' Log (c(2))
End Sub
#if C
#include <Wire.h>
void icwirebegintransmisson (B4R::Object* o) {
Wire.beginTransmission(b4r_main::_deviceaddress);
}
void icwireendtransmisson (B4R::Object* o) {
b4r_main::_wireerror = Wire.endTransmission();
}
void sht (B4R::Object* o) {
unsigned int data[6];
Wire.beginTransmission(0x45);
Wire.write(0x2C);
Wire.write(0x06);
Wire.endTransmission();
delay(500);
Wire.requestFrom(0x45, 6);
// Read 6 bytes of data
// cTemp msb, cTemp lsb, cTemp crc, humidity msb, humidity lsb, humidity crc
if (Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
b4r_main::_ctemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
}
#End if