#WioTerminal – connecting to Wifi πŸ“Ά, online information in TFT πŸ“Ί @code and @PlatformIO_Org

Hi !

I just migrated a sample Wio Terminal project from Arduino IDE to PlatformIO Labs in Visual Studio Code, and I think is a good idea to chat write it.

10 Wio Terminal connected to Wifi

The app will connect the device to a Wireless network and it will display the connect process progress on the device screen.

Working demo here, in this tweet

The full source code is available here.

Let’s start with a couple of notes.

  • The main.cpp uses several includes to connect to Wifi, to read the Wifi credentials, and to work with the TFT.
#include <Arduino.h>
#include <rpcWiFi.h>
#include <SPI.h>

#include "config.h"

#include "EB_Wifi.h"
// Display text + img on TFT
#include "EB_TFT.h"
  • <EB_Wifi.h> and <EB_Wifi.cpp> files contains several functions to work with the WiFi adapter and to process IP Addresses.
  • <EB_Tft.h> and <EB_Tftcpp> files contains several functions to display text in the TFT, in specific rows.
  • The connect to Wifi process is defined in the connectWifi() function. This process will attempt to connect to the Wireless networkd defined in the config.h file, and it will display the number of attempts and seconds working in the TFT and also on the serial output.
void connectWiFi()
{
  int startWifiTime = millis();
  int connectAttemps = 0;
  Serial.print("Connecting to Wifi ...");
  tftPrintLine(tft_row1, "Connecting to Wifi ...", "");
  tftPrintLine(tft_row2, "SSID:", SSID);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();

  while (WiFi.status() != WL_CONNECTED)
  {
    int secondsWaiting = (millis() - startWifiTime) / 1000;
    tftPrintLine(tft_row4, "Seconds waiting: ", String(secondsWaiting));
    tftPrintLine(tft_row5, "Connection attemps: ", String(connectAttemps));
    Serial.println("Connecting to WiFi..");
    Serial.print("Seconds waiting : ");
    Serial.println(secondsWaiting);
    WiFi.begin(SSID, PASSWORD);
    delay(500);
    connectAttemps++;
  }

  // Clean screen to show results
  tftInit();

  Serial.println("Connected!");
  Serial.println(WiFi.localIP());
  tftPrintLine(tft_row3, "Connected to ", SSID);
  tftPrintLine(tft_row4, "IP: ", ip2Str(WiFi.localIP()));
}
  • The Main App will open the Serial port, init the TFT (defined in the EB_Tft.h), and connect to the Wireless network.
void setup()
{
  Serial.begin(9600);

  while (!Serial)
    ; // Wait for Serial to be ready

  // init TFT
  tftFirstSetup();

  // connect to Wifi
  connectWiFi();

  delay(2000);
}
  • Final note will be around the [platformio.ini] file. The dependencies are the same that we define and added in my previous post.
[env:seeed_wio_terminal]
platform = atmelsam
board = seeed_wio_terminal
framework = arduino
lib_deps = 
	seeed-studio/Seeed Arduino rpcWiFi @ 1.0.5
	seeed-studio/Seeed Arduino FS @ 2.1.1
	seeed-studio/Seeed Arduino SFUD @ 2.0.2
	seeed-studio/Seeed Arduino rpcUnified @ 2.1.3
	seeed-studio/Seeed_Arduino_mbedtls @ 3.0.1

And that’s it ! A cool connected app running in our Wio Terminal !

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


References

Advertisement

1 comment

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: