B4R Question Display SSD1306 Connected esp8266 01

Cesar_Morisco

Active Member
Hello everyone Everything
Good.
I need guidance on the SSD1306 display connected to esp8266 01
Is there a way to use it?
Here thanks
SSD1306:
Sub Process_Globals
    Public Serial1 As Serial
    Public Wifi As ESP8266WiFi
    Public esp As ESP8266
    Public eeprom As EEPROM
    Private const MAGIC_EEPROM As Byte = 213
    Private sr As B4RSerializator
    Private bc As ByteConverter
    Private bc As ByteConverter
    Private ssd As AdafruitSSD1306
    Private ESPin As D1Pins
End Sub
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    ssd.InitializeI2C(ESPin.D4,0x3C)            'initialise SSD1306 0x78
    ssd.ClearDisplay
    ssd.GFX.SetCursor(0, 0)
    ssd.GFX.ConfigureText(2, ssd.WHITE, False)
    ssd.GFX.DrawText("Wifi ...").DrawText(CRLF).DrawText(CRLF)
    ssd.Display
    
    WiFiServer.Start
    ConnectToNetwork(0)
End Sub
Public Sub SaveNetworkDetails(Data() As Byte)'Gravar Eeprom
    Log("Salvando dados de Rede")
    Log("Comprimento de Dados : ", Data.Length)
    Log("Memoria=", AvailableRAM)
    Log("Tamanho :",StackBufferUsage)
    eeprom.WriteBytes(Array As Byte(MAGIC_EEPROM,Data.Length), 0)
    eeprom.WriteBytes(Data, 2)
End Sub

Public Sub ConnectToNetwork(tag As Byte)
    Wifi.Disconnect
 If GetStoredData = 1 Then
          Dim SSID As String = bc.StringFromBytes(GStore1.slot0) 'ignore
        Dim Password As String = bc.StringFromBytes(GStore1.slot1) 'ignore" '
        Log("Tentando se Conectar a: ", SSID, " Senha: ", Password)
        If Wifi.Connect2(SSID,Password) Then
            Log("Conectado com Sucesso : ", GStore1.slot0)
            Log("IP Local: ", Wifi.LocalIp)
            
            ssd.ClearDisplay
            ssd.GFX.SetCursor(2,0)
            ssd.GFX.ConfigureText(1,ssd.WHITE,False)
            ssd.GFX.DrawText("IP:")
            ssd.GFX.DrawText(Wifi.LocalIp)
            ssd.Display
            
            StopAP
       Else
            Log("WIFI Falha Ao Se Conectar - Iniciar WifiServer ")
            Log("Automatico Reset Em 5 M")
            CallSubPlus("ConnectToNetwork",60*1000,0) 'tente conectar novamente após 1 minuto
      End If
    Else
        Log("Dados Da Rede Não Encontrados .")
        WiFiServer.Start
    End If
End Sub

Public Sub GetStoredDataLength As Byte'Ler Eemprom
    Dim header() As Byte = eeprom.ReadBytes(0, 2)
    If header(0) = MAGIC_EEPROM  Then
        Return header(1)
    End If
    Return 0
End Sub

Sub    GetStoredData As Byte'Ler Objetos Eeeprom
    Dim length As Byte = GetStoredDataLength   
    Log("Parâmetros do Wifi Salvo na Eeprom  =",length)
    If length > 0 Then
        Dim ObjectsBuffer(8) As Object
        Dim Data() As Byte = eeprom.ReadBytes(2, length)
        Dim Objects() As Object = sr.ConvertBytesToArray(Data, ObjectsBuffer)
        If Objects.Length <> 0 Then
          For i = 0 To 7
          GStore1.Put(i,Objects(i))
          Next
          Return 1
        Else
          Return 0
        End If   
    Else
        Return 0   
    End If         
End Sub

Public Sub ClearStoredDataLength'Apagar Eeeprom
    Dim header() As Byte = eeprom.ReadBytes(0, 2)
    If header(0) = MAGIC_EEPROM Then
        header(1) = 0
        eeprom.WriteBytes(header,0)   
        Log("Eeprom Apagada")
    End If
    GStore1.Slot0(" ")
    GStore1.Slot1(" ")
    Delay(100)
    esp.restart
End Sub

public Sub StopAP
    Log("Stop AP")
    RunNative("stopAP", Null)
End Sub
#if C
  #include <ESP8266WiFi.h>
  void stopAP (B4R::Object* u) {
  WiFi.softAPdisconnect(1);
  }
#end if
 

Attachments

  • PCB.JPG
    26.8 KB · Views: 105
Cookies are required to use this site. You must accept them to continue using the site. Learn more…