Dear,
i’m trying to write and read I2C sensors through the I2C port on the Fusion 4 board with API structure.
I want to use VB.net from visualstudio 2017, as i used this in the past.
I’m not a programmer, so i’m really learning.
the idea is to control a fan speed according to the temperature. I want to read and act every 5 to 10 seconds.
I use the HYT939 sensor for temperature, PCA9531 2-Channel 8-bit PWM with 8 Outputs & GPIO I2C LED Dimmer for controlling the fan ( This works, already tested it), and a 1 channel relay controller: MCP23008 I2C Controlled Mechanical DPDT Relay for controlling the power to the relais.
I have learned about the API protocol, and the meaning of checksum etc.
But now is my question how to accurate send an API command to the fusion board using VB.Net and using the NCDComponent.dll
I managed to get it but i still have question if it is correct or not.
The code: NcdComponent1.WriteBytesAPI(188, 51, 3, 64, 9, 1, 0, 238) will put the relais on.
But: Do i need to write the full API code?: 170, 7, 188, 51, 3, 64, 9, 1, 0, 238 or do i need to right only 188, 51, 3, 64, 9, 1, 0 and do i need to at the checksum or not?
With 170, 7 added i don’t get response, without it seems to work but not always. Is there already 170, 7 inserted with in the WryteBytesAPI code?
Also: When using AnyI2C i can lookup and see what the W and R values are in API Command mode (dec). But for HYT939 sensor this seems to be a bit more complex then just writing one line. Also, is there a conversion table for displaying the temperature / humidity with the values getting returned by the sensor?
This is my code for just controllig the relais on and off (And also changes some button names )
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
NcdComponent1.UsingComPort = "false"
If Button2.Text = "OFF" Then
NcdComponent1.OpenPort() : Button2.Text = "LIVE"
Button2.Text = "LIVE"
Button2.ForeColor = Color.White
Button2.BackColor = Color.Navy
**NcdComponent1.WriteBytesAPI(188, 51, 3, 64, 9, 1, 0, 238)**
Else
Button2.Text = "OFF"
Button2.ForeColor = Color.Black
Button2.BackColor = Color.Gainsboro
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
**NcdComponent1.WriteBytesAPI(188, 51, 3, 64, 10, 0, 0, 237)**
End Sub
End Class
This is one simple read of temperature and humidity with HYT939 sensor in AnyI2C with API code Dec enabled.
How do i send this in an API write command and how do i read it? Because here a value will be returned to my VB.net program.
I just need to “see” it, so that i understand the way of using the code: WriteBytesApi …
W: 170 6 188 51 2 80 128 0 113
W: 188 51 2 80 128 0
R: 85
W: 170 6 188 51 2 80 0 0 241
W: 188 51 2 80 0 0
R: 85
W: 170 5 188 51 1 81 4 244
W: 188 51 1 81 4
R: 81 185 94 145
If there are more tutorials on using API with the NCDComponent.dll command, then please let me know.
Thank you.