by acentw » Tue Jun 05, 2012 7:17 am
by acentw
Tue Jun 05, 2012 7:17 am
eydi wrote:Request vb sample code for Module RM-G144 ??????
(not usage C++ sample code )
Hi, eydi
I modify the sample code on the RoBoard RM-G144 page
(
http://www.roboard.com/G144.html) as following:
It is VB.NET (not Visual Basic 6.0) code
- Code: Select all
' To read ADXL345
Imports System.Threading.Thread
Imports RoBoIO_DotNet.RoBoIO ' import the RoBoIO .Net Warper
Module ADXL345
Sub wait_ms(ByVal t As Integer)
Sleep(t)
End Sub
Sub Main()
Dim i2c_address As Byte
Dim buf(10) As Byte
Dim X_data As Integer
Dim Y_data As Integer
Dim Z_data As Integer
i2c_address = &H53
' first set the correct RoBoard version
roboio_SetRBVer(RB_100)
'roboio_SetRBVer(RB_110) ' if your RoBoard is RB-110
'roboio_SetRBVer(RB_050) ' if your RoBoard is RB-050
'roboio_SetRBVer(RB_100RD)' if your RoBoard is RB-100RD
If (i2c_Init(I2CMODE_AUTO, 400000) = False) Then ' init I2C lib to 400Kbps
Console.WriteLine("ERROR: fail to init I2C lib (" & roboio_GetErrMsg() & ")!")
GoTo I2C_END
End If
'Setting ADXL345
buf(0) = &H2D 'Pwoer_Control register
buf(1) = &H28 'link and measure mode
i2c_Send(i2c_address, buf, 2)
wait_ms(100)
buf(0) = &H31 'Data_Format register
buf(1) = &H8 'Full_Resolution
i2c_Send(i2c_address, buf, 2)
wait_ms(100)
buf(0) = &H38 'FIFO_Control register
buf(1) = &H0 'bypass mode
i2c_Send(i2c_address, buf, 2)
wait_ms(100)
'Send "READ" Command
i2c_SensorRead(i2c_address, &H32, buf, 6)
'buf(0) = X LSB
'buf(1) = X MSB
'buf(2) = Y LSB
'buf(3) = Y MSB
'buf(4) = Z LSB
'buf(5) = Z MSB
If ((buf(1) / 128) > 0) Then
X_data = &HFFFF0000 + buf(1) * 256 + buf(0)
Else
X_data = buf(1) * 256 + buf(0)
End If
If ((buf(3) / 128) > 0) Then
Y_data = &HFFFF0000 + buf(3) * 256 + buf(2)
Else
Y_data = buf(3) * 256 + buf(2)
End If
If ((buf(5) / 128) > 0) Then
Z_data = &HFFFF0000 + buf(5) * 256 + buf(4)
Else
Z_data = buf(5) * 256 + buf(4)
End If
Console.WriteLine("Acc of X-axis : " & X_data)
Console.WriteLine("Acc of Y-axis : " & Y_data)
Console.WriteLine("Acc of Z-axis : " & Z_data)
i2c_Close() 'close I2C lib
I2C_END:
End Sub
End Module
eydi wrote:Request vb sample code for Module RM-G144 ??????
(not usage C++ sample code )
Hi, eydi
I modify the sample code on the RoBoard RM-G144 page
(
http://www.roboard.com/G144.html) as following:
It is VB.NET (not Visual Basic 6.0) code
- Code: Select all
' To read ADXL345
Imports System.Threading.Thread
Imports RoBoIO_DotNet.RoBoIO ' import the RoBoIO .Net Warper
Module ADXL345
Sub wait_ms(ByVal t As Integer)
Sleep(t)
End Sub
Sub Main()
Dim i2c_address As Byte
Dim buf(10) As Byte
Dim X_data As Integer
Dim Y_data As Integer
Dim Z_data As Integer
i2c_address = &H53
' first set the correct RoBoard version
roboio_SetRBVer(RB_100)
'roboio_SetRBVer(RB_110) ' if your RoBoard is RB-110
'roboio_SetRBVer(RB_050) ' if your RoBoard is RB-050
'roboio_SetRBVer(RB_100RD)' if your RoBoard is RB-100RD
If (i2c_Init(I2CMODE_AUTO, 400000) = False) Then ' init I2C lib to 400Kbps
Console.WriteLine("ERROR: fail to init I2C lib (" & roboio_GetErrMsg() & ")!")
GoTo I2C_END
End If
'Setting ADXL345
buf(0) = &H2D 'Pwoer_Control register
buf(1) = &H28 'link and measure mode
i2c_Send(i2c_address, buf, 2)
wait_ms(100)
buf(0) = &H31 'Data_Format register
buf(1) = &H8 'Full_Resolution
i2c_Send(i2c_address, buf, 2)
wait_ms(100)
buf(0) = &H38 'FIFO_Control register
buf(1) = &H0 'bypass mode
i2c_Send(i2c_address, buf, 2)
wait_ms(100)
'Send "READ" Command
i2c_SensorRead(i2c_address, &H32, buf, 6)
'buf(0) = X LSB
'buf(1) = X MSB
'buf(2) = Y LSB
'buf(3) = Y MSB
'buf(4) = Z LSB
'buf(5) = Z MSB
If ((buf(1) / 128) > 0) Then
X_data = &HFFFF0000 + buf(1) * 256 + buf(0)
Else
X_data = buf(1) * 256 + buf(0)
End If
If ((buf(3) / 128) > 0) Then
Y_data = &HFFFF0000 + buf(3) * 256 + buf(2)
Else
Y_data = buf(3) * 256 + buf(2)
End If
If ((buf(5) / 128) > 0) Then
Z_data = &HFFFF0000 + buf(5) * 256 + buf(4)
Else
Z_data = buf(5) * 256 + buf(4)
End If
Console.WriteLine("Acc of X-axis : " & X_data)
Console.WriteLine("Acc of Y-axis : " & Y_data)
Console.WriteLine("Acc of Z-axis : " & Z_data)
i2c_Close() 'close I2C lib
I2C_END:
End Sub
End Module