Pular para o conteúdo principal

Porta Grove

Este repositório apresenta como usar o Wio Terminal com o Ecossistema Grove.

Com a ajuda do Grove, você consegue fazer protótipos muito mais rápido com conexões mais simples!

Wio Terminal com Grove - Sensor TDS

Esta seção apresenta como usar o Grove - TDS Sensor com o Wio Terminal para exibir leituras de TDS em tempo real em um gráfico de linha!

Instalação das bibliotecas

  1. Instale a biblioteca LCD.

  2. Instale a biblioteca Linechart.

Código completo

Conecte o sensor Grove TDS ao pino D/A Grove do Wio Terminal, faça o upload do código e verifique os resultados!

#include"seeed_line_chart.h" //include the library
TFT_eSPI tft;

#define max_size 50 //maximum size of data
doubles data; //Initilising a doubles type to store data
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite

#define sensorPin A0 //Analog pin

int sensorValue = 0;
float tdsValue = 0;
float Voltage = 0;

void setup() {
pinMode(sensorPin, INPUT);
tft.begin();
tft.setRotation(3);
spr.createSprite(TFT_HEIGHT,TFT_WIDTH);
}

void loop() {
spr.fillSprite(TFT_WHITE);

sensorValue = analogRead(sensorPin);
Voltage = sensorValue*5/1024.0; //Convert analog reading to Voltage
tdsValue=(133.42*Voltage*Voltage*Voltage - 255.86*Voltage*Voltage + 857.39*Voltage)*0.5; //Convert voltage value to TDS value

if (data.size() == max_size) {
data.pop();//this is used to remove the first read variable
}
data.push(tdsValue); //read variables and store in data

//Settings for the line graph title
auto header = text(0, 0)
.value("TDS Reading")
.align(center)
.valign(vcenter)
.width(tft.width())
.thickness(3);

header.height(header.font_height() * 2);
header.draw(); //Header height is the twice the height of the font

//Settings for the line graph
auto content = line_chart(20, header.height()); //(x,y) where the line graph begins
content
.height(tft.height() - header.height() * 1.5) //actual height of the line chart
.width(tft.width() - content.x() * 2) //actual width of the line chart
.based_on(0.0) //Starting point of y-axis, must be a float
.show_circle(true) //drawing a cirle at each point, default is on.
.value(data) //passing through the data to line graph
.color(TFT_RED) //Setting the color for the line
.draw();

spr.pushSprite(0, 0);
delay(50);
}

Wio Terminal com Grove - Display OLED

Se você precisar de uma segunda tela para exibir com o Wio Terminal, o Grove - OLED Dispaly 0.96" será a escolha perfeita. Ele pode ser usado para exibir gráficos e dados, adicionando mais recursos interativos com o Wio Terminal.

Instalação das bibliotecas

  1. Instale as bibliotecas U8g2 a partir do Library Manager na Arduino IDE. Navegue para Sketch -> Include Library -> Manage Libraries... e pesquise e instale U8g2 no Library Manager.

Inicialização do U8g2

Inicialize o display OLED usando o I2C por software do u8g2 e use SCL para clock e SDA para dados:

U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);

Uso

  1. Chame u8g2.firstPage().

  2. Inicie um loop do-while.

  3. Dentro do corpo do loop: desenhe algo com os comandos de desenho usuais.

  4. Faça o loop enquanto u8g2.nextPage() retornar true.

Para mais informações, visite u8g2

Código completo

Conecte o Grove OLED Display 0.96" ao pino I2C Grove e verifique os resultados!

#include <U8g2lib.h>

U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);

const unsigned char WAVE[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0x00,0xFF,0x00,0x0F,0xF0,0x00,
0xFC,0x03,0xFF,0xC0,0x3F,0xFC,0x00,
0xFE,0x07,0xFF,0xE0,0x7F,0xFE,0x00,
0x1F,0xFF,0x81,0xFF,0xF8,0x1F,0xC0,
0x0F,0xFF,0x00,0xFF,0xF0,0x0F,0xC0,
0x03,0xFC,0x00,0x3F,0xC0,0x03,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xE0,0x00,0x7E,0x00,0x07,0xE0,0x00,
0xF8,0x01,0xFF,0x80,0x1F,0xF8,0x00,
0xFC,0x03,0xFF,0xC0,0x3F,0xFC,0x00,
0xFF,0x0F,0xFF,0xF0,0xFF,0xFF,0x00,
0x1F,0xFF,0x81,0xFF,0xF8,0x1F,0xC0,
0x07,0xFE,0x00,0x7F,0xE0,0x07,0xC0,
0x01,0xF8,0x00,0x1F,0x80,0x01,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF0,0x00,0xFF,0x00,0x0F,0xF0,0x00,
0xF8,0x01,0xFF,0x80,0x1F,0xF8,0x00,
0xFE,0x07,0xFF,0xE0,0x7F,0xFE,0x00,
0x3F,0xFF,0xC3,0xFF,0xFC,0x3F,0xC0,
0x0F,0xFF,0x00,0xFF,0xF0,0x0F,0xC0,
0x07,0xFE,0x00,0x7F,0xE0,0x07,0xC0,
0x00,0xF0,0x00,0x0F,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x00,0x18,0x00,0x01,0x80,0x00,
0xF0,0x00,0xFF,0x00,0x0F,0xF0,0x00,
0xFC,0x03,0xFF,0xC0,0x3F,0xFC,0x00,
0xFF,0x0F,0xFF,0xF0,0xFF,0xFF,0x00,
0x1F,0xFF,0x81,0xFF,0xF8,0x1F,0xC0,
0x0F,0xFF,0x00,0xFF,0xF0,0x0F,0xC0,
0x03,0xFC,0x00,0x3F,0xC0,0x03,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

void setup() {
u8g2.begin();
}

void loop() {
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_t0_16b_mr);
u8g2.drawXBMP(40, 0, 50, 50, WAVE);
u8g2.setCursor(20, 60);
u8g2.print("Wio Terminal");
} while (u8g2.nextPage());
}

Wio Terminal com Grove - Sensor de Temperatura

Esta seção apresenta como usar o Grove - Temperature Sensor com o Wio Terminal para exibir leituras de temperatura ambiente em tempo real.

Instalação das bibliotecas

  1. Instale a biblioteca LCD.

  2. Instale a biblioteca Linechart.

Código completo

Conecte o sensor de temperatura Grove ao pino D/A Grove do Wio Terminal, faça o upload do código e verifique os resultados!

#include"seeed_line_chart.h" //include the library
#include <math.h>

TFT_eSPI tft;

#define max_size 50 //maximum size of data
doubles data; //Initilising a doubles type to store data
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite

const int B = 4275; // B value of the thermistor
const int R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0

void setup() {
pinMode(pinTempSensor, INPUT);
tft.begin();
tft.setRotation(3);
spr.createSprite(TFT_HEIGHT,TFT_WIDTH);
}

void loop() {
spr.fillSprite(TFT_DARKCYAN);

int a = analogRead(pinTempSensor);
float R = 1023.0/a-1.0;
R = R0*R;

float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet

if (data.size() == max_size) {
data.pop();//this is used to remove the first read variable
}
data.push(temperature); //read variables and store in data

//Settings for the line graph title
auto header = text(0, 0)
.value("Temperature Reading")
.align(center)
.color(TFT_WHITE)
.valign(vcenter)
.width(tft.width())
.thickness(2);

header.height(header.font_height() * 2);
header.draw(); //Header height is the twice the height of the font

//Settings for the line graph
auto content = line_chart(20, header.height()); //(x,y) where the line graph begins
content
.height(tft.height() - header.height() * 1.5) //actual height of the line chart
.width(tft.width() - content.x() * 2) //actual width of the line chart
.based_on(0.0) //Starting point of y-axis, must be a float
.show_circle(true) //drawing a cirle at each point, default is on.
.y_role_color(TFT_WHITE)
.x_role_color(TFT_WHITE)
.value(data) //passing through the data to line graph
.color(TFT_RED) //Setting the color for the line
.draw();

spr.pushSprite(0, 0);
delay(50);
}

Wio Terminal com Grove - Sensor GPS

Esta seção apresenta como usar o Grove - GPS Sensor com o Wio Terminal para obter informações de GPS em tempo real. O próprio sensor gera dados de GPS NMEA que usaremos a biblioteca TinyGPSPlus para analisar e converter em informações legíveis.

Instalação das bibliotecas

  1. Instale a TinyGPSPlus Library.

Código completo

Conecte o Grove GPS Sensor ao pino I2C Grove (lado esquerdo) do Wio Terminal, faça o upload do código e verifique os resultados no Serial Monitor (com taxa de baud: 9600)!

#include <TinyGPS++.h>
#include <wiring_private.h>

static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device - Left side Grove connector.
// Left side Grove connector shares pins with I2C1 of 40 pin connector.
static Uart Serial3(&sercom3, PIN_WIRE_SCL, PIN_WIRE_SDA, SERCOM_RX_PAD_1, UART_TX_PAD_0);

void setup()
{
Serial.begin(115200);

Serial3.begin(GPSBaud);
pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
}

void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (Serial3.available() > 0)
if (gps.encode(Serial3.read()))
displayInfo();

if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}

void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}

Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}

Serial.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}

Serial.println();
}

void SERCOM3_0_Handler()
{
Serial3.IrqHandler();
}
void SERCOM3_1_Handler()
{
Serial3.IrqHandler();
}
void SERCOM3_2_Handler()
{
Serial3.IrqHandler();
}
void SERCOM3_3_Handler()
{
Serial3.IrqHandler();
}
Loading Comments...