B4R Question Nextion Touch Display Serial Commutation

Klaas

Member
Licensed User
Hello,
im reaching out in order to see if others have had this problem before regadring the Nextion Series Screens.
im trying to send data from the esp32 to 7inch screen i have added my code below, i am able to recive data but unsure of sending data as i used examples from andriod itself to adapt to b4r.
sorry i dont have the sorce code.
1688482203242.png
1688482273521.png

you can see here when i use the nextion commands i send a way to list all wifi. from the code below it seems it does send as if i touch the two pins it will for ever loop but not sure if others know if the devcie needs the data to be different format.


B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

 

Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private serialnative2 As Stream
    Private astream As AsyncStreams
    Private RXD2,TXD2 As Byte 'ignore
    Private bc As ByteConverter

    Private LeDCount As Int = 60
    Public RBG_LIGHT As AdafruitNeoPixel 'RGB WITH WS2812 - OUTPUT
 
    Dim endChar As String = JoinStrings ( Array As String ( 0xff , 0xff , 0xff))
 

End Sub

 

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    astream.Initialize(serialnative2, "astream_NewData", Null)
    'example of connecting to a local network

 


    RBG_LIGHT.Initialize(LeDCount,26,RBG_LIGHT.NEO_GRB) 'change led count as import!! to show!    Rnd
    RXD2 = 4
    TXD2 = 2
    RunNative("SerialNative2", Null)
   
    Dim nodeInt As Int = wifi.Scan
    Dim nodeString As String = nodeInt
   
    GlobalStore.Put(5,nodeString)
    Log(GlobalStore.Slot5)
   
    Dim quot() As Byte = bc.HexToBytes(22)
    'Dim SSID As String = JoinStrings( Array As String("<cb0.path=cb0.path+",bc.StringFromBytes(quot),wifi.ScannedSSID(i),bc.StringFromBytes(quot),">"))
'    Dim SSID As String = JoinStrings( Array As String("t0.txt=\",bc.StringFromBytes(quot),wifi.ScannedSSID(0),"\",bc.StringFromBytes(quot)))
'    Log(SSID.GetBytes)
'    astream.Write(SSID.GetBytes)
'    Dim k() As Byte = "0xff"
'    astream.Write(k)
'    astream.Write(k)
'    astream.Write(k)
    Log("write Array")
    astream.Write("t2.txt=\""abcd""\").Write(Array As Byte(0xFF, 0xFF, 0xFF))
    astream.Write("t2.txt=""abcd""").Write(Array As Byte(0xFF, 0xFF, 0xFF))
    astream.Write("t2.txt=""abcd""").Write(Array As Byte(0xFF, 0xFF, 0xFF))
End Sub

 


#if C
void SerialNative2(B4R::Object* unused){
::Serial2.begin(9600, SERIAL_8N1, b4r_main::_rxd2, b4r_main::_txd2);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#End if

*btw i know its not written the best but i was really just testing!
any help will be super great :)

thanks!
 

Attachments

  • 1688482422374.png
    1688482422374.png
    22.4 KB · Views: 109
Last edited:

embedded

Active Member
Licensed User
Longtime User
Write a text box in Nextion Display:
Sub nextion_write_tb(textbox As String,datavalue As String)'tested working 11/06/23
    Main.astream.Write(textbox)'"t1.txt="
    Main.astream.Write(Array As Byte(34))
    Main.astream.Write(datavalue)'"1234.5"
    Main.astream.Write(Array As Byte(34,0xFF,0xFF,0xFF))
End Sub
 
Upvote 0

Klaas

Member
Licensed User
thanks! from other testing ive found out that
B4X:
astream.Write("cb0.path=cb0.path+").Write(QUOTE).Write(wifi.ScannedSSID(i)).Write(QUOTE).Write(Array As Byte(0xFF, 0xFF, 0xFF))
also works for sending!
 
Upvote 0
Top