B4R Question How to realize a 'software serial port' ?

amorosik

Expert
Licensed User
I have a Heltec Wifi Kit 32 card I would like to use some pins of the board to get additional uart compared to the hardware serial ports supplied as standard
How do I get a uart from a pair of i / o pins?
Only tx/rx, no handshake hardware pin
 

thetahsk

Active Member
Licensed User
Longtime User
I have a Heltec Wifi Kit 32 card I would like to use some pins of the board to get additional uart compared to the hardware serial ports supplied as standard
How do I get a uart from a pair of i / o pins?
Only tx/rx, no handshake hardware pin
use the rSoftwareSerial lib
or the rWire Lib
 
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
In B4R there are no SoftwareSerial that works with Esp32.

The Esp32 have 3 hardware serial that you can use with the pins you want.
So you only have trouble if you need more than 3 serial ports.
( This is actually not true :) , one of the serial ports are used for programming and log)

B4X:
private Sub Process_Globals
    Private SerialNative As Stream
    Private astream As AsyncStreams
End Sub

public Sub Initialize
    RunNative("SerialNative2", Null)
    astream.Initialize(SerialNative, "aStream_newdata","aStream_Error")
    astream.MaxBufferSize=1000
    astream.WaitForMoreDataDelay=200
End Sub

private Sub aStream_NewData (Buffer() As Byte)
    Log(Buffer)
End Sub

Public Sub Send(Data() as byte)
    astream.Write(Data)
End Sub

#if C
void SerialNative2(B4R::Object* unused)
{
::Serial2.begin(9600, SERIAL_8N1, 19, 18);;//<--use pin 19/18 as RX/TX
b4r_modgps::_serialnative->wrappedStream = &::Serial2;
}
#End If

My code is in a module called modGPS, so change b4r_modgps in C code to the module you use. (must be lower case)
 
Upvote 0
Top