Hi Erel!
Thank You for posting the thread and pointing the way. I rooted and added the missing xml's. Now my tablet recognizes arduino.
Next problem is that when I load this code to the arduino:
static int counter = 0;
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.print("Tick #");
Serial.print(counter++, DEC);
Serial.print("\n");
if (Serial.peek() != -1) {
Serial.print("Read: ");
do {
Serial.print((char) Serial.read());
} while (Serial.peek() != -1);
Serial.print("\n");
}
delay(1000);
}
I get the communication ie B4A app reads the ticks from arduino and receives the returned 1 or 0 sent from app.
But when I load this to arduino:
int SerialValue = 0;
void setup(){
pinMode(7, OUTPUT);
Serial.begin(115200);
}
void loop(){
SerialValue = Serial.read();
if(SerialValue == 1){
digitalWrite(7, HIGH);
}
if(SerialValue == 0){
digitalWrite(7, LOW);
}
}
I don't get any change in pin state. Arduino receives a message since the rx light is blinking. the above code works ok with this VB.Net:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
s.Close()
s.PortName = "com12" 'will need to change to your port number
s.BaudRate = 115200
s.DataBits = 8
s.Parity = Parity.None
s.StopBits = StopBits.One
s.Handshake = Handshake.None
s.Encoding = System.Text.Encoding.UTF8 'very important!
s.Open()
s.RtsEnable = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "On" Then
s.Write(Chr(1))
Button1.Text = "Off"
Else
s.Write(Chr(0))
Button1.Text = "On"
End If
End Sub
but not with this B4A which is your example, apart of 0ne button and label:
Sub Astreams_NewData (Buffer() As Byte)
Log("NewData")
Log(BytesToString(Buffer, 0, Buffer.Length, "UTF-8"))
Label2.text =BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
End Sub
Sub btnClose_Click
astreams.Close
Label1.text = "port closed"
Label2.text = "Label2"
End Sub
Sub btnSend_Click
astreams.Write("1".GetBytes("UTF-8"))
End Sub
Sub AStreams_Error
Log("Error: " & LastException)
astreams.Close
End Sub
Sub Astreams_Terminated
Log("Terminated")
astreams.Close
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Off_Click
astreams.Write("0".GetBytes("UTF-8"))
End Sub
I'm somewhat clueless, hope that you or anyone else can point out what I'm missing here
Rgds,
Tapio