sexta-feira, 1 de maio de 2020

NINA B302 e BLYNK - ETHERNET 802.3

U-BLOX NINA B302 e BLYNK - ETHERNET 802.3

O objetivo deste BLOG é demonstrar como é possível utilizar a IDE do Arduino para programar o módulo U-BLOX NINA B302 para acessar o servidor BLYNK e criar uma APP e verificar o STATUS de LED. Foi utilizado o NINA B302 BREAKOUT para o teste.
BLYNK

Junte-se à plataforma IoT mais popular para conectar seus dispositivos à nuvem, projetar aplicativos para controlá-los e gerenciar seus produtos implantados em escala! Crie sua APP rapidinho e depois porte Blynk para seu próprio servidor.

Instalando Arduino Adafruit no NINA B302


Abaixo o roteiro para você seguir:

Baixe e instale o Arduino IDE 
Inicie o Arduino IDE, vá em Preferências e adicione 

https://www.adafruit.com/package_adafruit_index.json




como "URL adicional do gerenciador de pastas"

Abra o Boards Manager no menu Tools -> Board e instale o "Adafruit nRF52 by Adafruit"

Selecione sua placa nRF5 no menu Ferramentas -> Placa

Adafruit Bluefruit nRF52 Feather





OBSERVAÇÃO: Durante a instalação, o Arduino IDE leva alguns minutos para extrair as ferramentas após o download, por favor, seja paciente.

Gravando bootloader da Adafruit


Use o gravador SEGGER JLINK para gravar o BREAKOUT com módulo NINA B302, conecte nos pinos do SWCLK (pino 7) e SWDIO (pino 9) do SEGGER JLINK nos pinos  SWDCLK e SWDIO do BREAKOUT (pinos nas laterais, próximo à antena). Não esquecer de ligar os GND do BREAKOUT no GND do SEGGER JTAG, bem como alimentar o BREAKOUT com 3.3V.





Ligue os pinos SWD DIO e CLK ...



...nestes pinos da placa BREAKOUT


Você pode também usar o ST-LINK V2



Abra J-FLASH lite e grave o bootloader da Adafruit


Mudar NRF52840
 
O mesmo se encontra em 

....\packages\adafruit\hardware\nrf52\0.19.0\bootloader\feather_nrf52840_express

Compile depois para o NINA B302
https://github.com/adafruit/Adafruit_nRF52_Bootloader

Com ele, você poderá transferir programas via DFU USB. Maiores detalhes sobre este bootloader

https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather/update-bootloader

Segundo a documentação, se você pressionar o reset, o módulo aguardará por um certo tempo se há algo sendo enviado pelo Arduino, ou seja, o programa a ser gravado via DFU.

ATENÇÃO, o bootloader usa USB para gravação do NINA 302, OU SEJA, CRIA UMA COMM VIRTUAL, TAMBÉM PARA SER A SERIAL PADRÃO DO ARDUINO

INSTALE OS DRIVERS
https://github.com/adafruit/Adafruit_Windows_Drivers

Conecte na USB + e USB - um cabo USB, AGUARDE INSTALAR OS DRIVERS


Futuramente altere arquivo variant.cpp para que as GPIOS sejam os mesmos do NINA B302, atualmente estão para o ADAFRUIT FEATHER EXPRESS.

Copie 

Criado pelo Autor

variant.h
viariant.cpp





ÓTIMA REFERENCIA PARA PINOS DO ARDUINO E PINOS (GPIOS) DO NINA B302


Consulte


ENC28J60

O módulo Ethernet ENC28J60 utiliza o novo IC controlador controlador independente Microchip ENC28J60 com uma série de recursos para lidar com a maioria dos requisitos de protocolo de rede. A placa se conecta diretamente à maioria dos microcontroladores com uma interface SPI padrão com uma velocidade de transferência de até 20MHz.

Conexão com NINA B302

static const uint8_t SS   = (10);----> CS  (ENC28J60)
static const uint8_t MOSI = PIN_SPI_MOSI; ----> SI (ENC28J60)
static const uint8_t MISO = PIN_SPI_MISO;----> SO (ENC28J60)
static const uint8_t SCK  = PIN_SPI_SCK;----> SCK      (ENC28J60)

#define PIN_SPI_MISO         (24)    //24 original   IO1
#define PIN_SPI_MOSI         (25)    //25 original   IO3
#define PIN_SPI_SCK          (26)    //26 original    IO45

// D24 .. D26 (aka SPI pins)
  32,  // D24 is P1.00 (SPI MISO)
  15,  // D25 is P0.15 (SPI MOSI)
   7,  //14,  // D10 is P0.14


Blynk

Blynk é uma plataforma com aplicativos iOS e Android para controlar   Arduino, Raspberry Pi e afins pela Internet.   Você pode criar facilmente interfaces gráficas para todos os seus   projetos simplesmente arrastando e soltando widgets

1) INSTALE O APP DO BLYNK

Instale um APP do BLYNK e crie uma conta. Crie um projeto de um  FRONT END para acesso ao NINA B302


Então um TOKEN será gerado para o seu e-mail com instruções

Auth Token : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Happy Blynking!
-
Getting Started Guide -> https://www.blynk.cc/getting-started
Documentation -> http://docs.blynk.cc/
Sketch generator -> https://examples.blynk.cc/

Latest Blynk library -> https://github.com/blynkkk/blynk-library/releases/download/v0.6.1/Blynk_Release_v0.6.1.zip
Latest Blynk server -> https://github.com/blynkkk/blynk-server/releases/
-
https://www.blynk.cc
twitter.com/blynk_app
www.facebook.com/blynkapp

COPIE AS LIBRARIES PARA O ARDUINO


1) Copie para Sketch o exemplo a seguir 

/* Comment this out to disable prints and save space */ #define USE_UIP_ETHERNET true #define BLYNK_PRINT Serial #include <UIPEthernet.h> #include <BlynkSimpleUIPEthernet.h> #define USE_LOCAL_SERVER false // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). #if USE_LOCAL_SERVER // Local Blynk Server char token[] = "XXXXXXXX"; // Fill the name of Blynk Server char server[] = "XXXXXXXX.ddns.net"; //char server[] = "****.ddns.net"; //char server[] = "192.168.2.112"; #else //Cloud Blynk Server char token[] = "******"; char server[] = "blynk-cloud.com"; #endif #define BLYNK_HARDWARE_PORT 8080 WidgetLED led1(V1); BlynkTimer timer; // V1 LED Widget is blinking void blinkLedWidget() { if (led1.getValue()) { led1.off(); Serial.println("LED on V1: off"); } else { led1.on(); Serial.println("LED on V1: on"); } } void doSomething(void) { Serial.println("============ Print Every 120s ============"); blinkLedWidget(); Serial.println("========== And Blink LED widget =========="); } void heartBeatPrint(void) { static int num = 1; if (Blynk.connected()) Serial.print(F("B")); // For Blynk OK else Serial.print(F("F")); // Failure if (num == 80) { Serial.println(); num = 1; } else if (num++ % 10 == 0) { Serial.print(F(" ")); } } void check_status() { static unsigned long checkstatus_timeout = 0; #define STATUS_CHECK_INTERVAL 60000L // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) { heartBeatPrint(); checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; } } #define BLYNK_CONNECT_TIMEOUT_MS 20000 #define USE_NON_BLOCKING_BLYNK false void setup() { // Debug console Serial.begin(115200); #if USE_NON_BLOCKING_BLYNK Blynk.config(token, server, BLYNK_HARDWARE_PORT); Blynk.connect(BLYNK_CONNECT_TIMEOUT_MS); #else //Blynk.begin(auth); // You can also specify server: Blynk.begin(token, server, BLYNK_HARDWARE_PORT); #endif if (Blynk.connected()) { Serial.print(F("Conn2Blynk: server = ")); Serial.print(server); Serial.print(F(", port = ")); Serial.println(BLYNK_HARDWARE_PORT); Serial.print(F("Token = ")); Serial.print(token); Serial.print(F(", IP = ")); Serial.println(Ethernet.localIP()); } // Every 120s, doSomething => print and blink LED (V1) on APP timer.setInterval(1000L, doSomething); } void loop() { Blynk.run(); timer.run(); check_status(); }

Coloque o TOKEN e o servidor!

//Cloud Blynk Server char token[] = "******"; 
 char server[] = "blynk-cloud.com";

Leia Atentamente 


2) COMPILE E GRAVE


3) EXECUTE



4) EXECUTANDO



5) NO SEU APP CRIE UM LED VIRTUAL



Ele irá piscar a cada 1 segundo.


Questões: suporte@smartcore.com.br

FONTES: 

THANKS TO Khoi Hoang


https://blynk.io/en/getting-started
http://docs.blynk.cc/#widgets-displays-led
https://github.com/khoih-prog/BlynkEthernet_WM
http://docs.blynk.cc/#getting-started-getting-started-with-the-blynk-app

Sobre a SMARTCORE

A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso portfólio inclui modem 2G/3G/4G/NB-IoT/Cat.M, satelital, módulos WiFi, Bluetooth, GNSS / GPS, Sigfox, LoRa, leitor de cartão, leitor QR code, mecanismo de impressão, mini-board PC, antena, pigtail, LCD, bateria, repetidor GPS e sensores.
Mais detalhes em www.smartcore.com.br