IOIO UART help

KZ3

New Member
Licensed User
Can somebody help me figure this out. I have an Edittext box "txtSend" and I want to be able to type in a number and it get sent out by UART. This code right now will send 83 and I can view it in another edittext box. I would like to be able to type in a number and send it in place of the 83. Sorry, very new at this and I can't figure it out. This is running IOIOLib 1.7. I tried other code using 1.8 and I can't figure that out either. Thanks

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim YOYO As IOIO
   Dim LED As DigitalOutput
   Dim LED2 As DigitalOutput
   Dim timer1, timer2, As Timer

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim BLED As ToggleButton
   Dim ConLED As ToggleButton
   Dim label1 As Label
   Dim Serial1 As Serial
   Dim BTadmin As BluetoothAdmin
   Dim conn1=0 As Int
   Dim label1, label2 As Label
   Dim togglebutton1 As ToggleButton
   Dim trouble As Exception
   Dim comments As StringBuilder
   Dim conn_attemps As Int
   Dim uart1 As Uart
   Dim outstrm As OutputStream
   Dim instrm As InputStream
   Dim numdiag As NumberDialog
    Dim togglebutton2,ToggleButton3 As ToggleButton
   Dim mtserial As Uart
   Dim Edittext1 As EditText
   
   Dim txtSend As EditText
   
   
End Sub

Sub ToggleButton2_CheckedChange(Checked As Boolean)
   'test uart
   If YOYO.IsInitialized Then
   If YOYO.State="CONNECTED" Then
   If Checked Then
   
   


'uart order is is rx,spec,tx,spec,baud,pariy,stop
mtserial=YOYO.OpenUart(12,mtserial.IP_FLOATING,13,mtserial.OP_NORMAL,9600,mtserial.PARITY_NONE,mtserial.STOPBIT_ONE)

Dim out As OutputStream
Dim In As InputStream

Dim bufferin(8), bufferout(8) As Byte
Dim temp As String
    
out=mtserial.OutputStream
In=mtserial.InputStream
    
'send 83 and read result
bufferin(0)=83 'S
out.WriteBytes(bufferin,0,1)
In.ReadBytes(bufferout,0,1)

temp="result="&Bit.AND(bufferout(0),0xFF)
Edittext1.Text=temp
mtserial.Close
End If
End If
End If
End Sub
 

kolbe

Active Member
Licensed User
If I understand correctly the IOIO is working, you can send data and receive data (83 in the code), but you can't figure out how capture a keypress, etc.

A quick search reveals the following thread. I think this should get you going in the write direction. Erel has also written a Bluetooth chat program. You might be able to glean some "how to" from that example, if that is the direction you are going in.
 
Upvote 0

KZ3

New Member
Licensed User
Thanks! The IOIO is working great. I am just looking for a way to type in a number on my phone in a edittext box and it will send that number by UART. So, If I type in 20 into the edittext box the example code below would read

bufferin(0)=20.

The number 20 would be sent out and received by IOIO and displayed in another edittext box when connecting the TX and RX lines.

From reading the post it sounds like I have to have a separate activity to capture a keyboard event? Then relate that number as an Int to get sent out? I see other examples where people are writing in text and then it is getting displayed on a computer screen. I have tried to relate the code but It always comes back an error.

Basically i would like to do something like this.

Dim sendnum AS Int

Keyboard press 20, Keyboard result=sendnum

Thanks again for any help

Sendnum=20

bufferin (0) = sendnum
 
Upvote 0

KZ3

New Member
Licensed User
I added this to the code and now the result shows 2. It doesn't matter what I enter into the edittext box. Can someone please help me. I just need to know how to capture a number that's entered into a edittext box and be able to send it out by UART.

B4X:
Sub ToggleButton3_CheckedChange(Checked As Boolean)
   'test uart
   If YOYO.IsInitialized Then
   If YOYO.State="CONNECTED" Then
   If Checked Then
   
   


'uart order is is rx,spec,tx,spec,baud,pariy,stop
mtserial=YOYO.OpenUart(28,mtserial.IP_FLOATING,27,mtserial.OP_NORMAL,9600,mtserial.PARITY_NONE,mtserial.STOPBIT_ONE)

Dim out As OutputStream
Dim In As InputStream

Dim bufferin(8), bufferout(8) As Byte
Dim temp As String
  
out=mtserial.OutputStream
In=mtserial.InputStream
    
'send 83 and read results

Dim numval As String

numval=txtSend.INPUT_TYPE_NUMBERS


         
bufferin(0)= numval
out.WriteBytes(bufferin,0,1)
In.ReadBytes(bufferout,0,1)

temp="result="&Bit.AND(bufferout(0),0xFF)
Edittext1.Text=temp
mtserial.Close
End If
End If
End If
End Sub
 
Upvote 0
Top