I'm trying to send hex values from my computer to the arduino, and having the arduino save those vales.
This data is being sent with the code below:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim config_values As Byte() = {&HAA, &HFF}
_serialPort.Write(config_values, 0, 2)
_serialPort.Close()
End Sub
On the Arduino I am reading the serial port as such:
byte Register_Values[2];
byte Register_value_in;
void loop() {
while (Serial.available() >= 2) {
for (int i = 0; i < 2; i++) {
Register_value_in = Serial.read();
Register_Values[i] = Register_value_in;
}
}
Serial.print("Reg 0");
Serial.println(Register_Values[0]);
Serial.print("Reg 1");
Serial.println(Register_Values[1]);
When I add an if statement checking for the hex value the if statement will be ran, so the data is being sent correctly, but for some reason it looks like the data isn't being saved into the array.
Serial data is usually ASCII char, not byte, so '0' is the same as 48. Also, HEX values might use ABCDEF or abcdef, which don't automatically correspond to the byte value directly after '9'.
as an output in the serial window. To me that is saying that the data is being received and read correctly, but for some reason it isn't being saved into the array.
Robin2:
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
...R
Except from what I can tell the data is being received correctly, it just isn't being saved into the array for some reason. The main thing being I'm not using start and end markers in the current design, which I wouldn't think make it not work.
Is not the issue. If I put all my code inside the if statement, it works just fine. For some reason the data just got rewritten once the if statement ended. Luckily I can put all my code inside the if statement, and have it work for me.
qwerty77:
Is not the issue. If I put all my code inside the if statement, it works just fine. For some reason the data just got rewritten once the if statement ended. Luckily I can put all my code inside the if statement, and have it work for me.