sexta-feira, 12 de junho de 2020

NINA B302 COM WIFI - ARDUINO - NINA W102 - AT COMMANDS

U-BLOX NINA B302 e WIFI - ARDUINO - AT COMMANDS

O objetivo deste BLOG é mostrar um exemplo em ARDUINO que permite o NINA B302 se transformar num webserver WIFI, utilizando o W102 (COMANDOS AT) COMO COPROCESSOR WIFI 802.11.


Utilize a programação clássica com Sockets do Arduino! Compilei a última versão dos comandos AT disponível. Alguns pequenos bugs revolvidos!


COPROCESSOR PARA O NINA B302


MONTAGEM

Adquirimos então os seguintes componentes



Montado ficou assim



O esquema elétrico é este



Algumas características do Kit

-Botão de RESET;
-Botão de Modo BOOTLOADER (W102);
-Plugável no PROTOBOARD;
-Acesso às várias GPIOS;

Pequena 


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




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



Aqui você encontra variant.cpp e variant.h e boards.txt
Ligue os pino do NINA B302 no NINA W102

 

BREAKOUT B3

BREAKOUT W102

TXD

IO23

TXD

IO22
RXD

IO22

RXD

IO23
GND
GND



INSTALE LIB AT WEBSERVER - EXEMPLOS QUE USAM AT COMMANDS (ESPRESSIF)


Thanks to Khoi Hoang to help to port AT to NINA B302



Compile o programo AdvancedWebServer e pressione o botão para gravar.

Ao aparecer a mensagem "Upgrading target on COM...", pressione imediatamente o botão de reset do módulo NINA B302



Como podem observar, o programa será transferido!

Abra a serial



Abra o IP com seu BROWSER preferido


Veja o código, nem um comando AT visível, abstração total, veja o que ocorre em background


/**************************************************************************************************************************** AdvancedWebServer.ino - Simple Arduino web server sample for ESP8266 AT-command shield For ESP8266 AT-command running shields ESP8266_AT_WebServer is a library for the ESP8266 AT-command shields to run WebServer Forked and modified from ESP8266 https://github.com/esp8266/Arduino/releases Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_AT_WebServer Licensed under MIT license Version: 1.0.6 Copyright (c) 2015, Majenko Technologies All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Majenko Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Version Modified By Date Comments ------- ----------- ---------- ----------- Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 12/02/2020 Initial coding for Arduino Mega, Teensy, etc 1.0.1 K Hoang 17/02/2020 Add support to server's lambda function calls 1.0.2 K Hoang 22/02/2020 Add support to SAMD (DUE, ZERO, MKR, NANO_33_IOT, M0, Mo Pro, AdaFruit, etc) boards 1.0.3 K Hoang 03/03/2020 Add support to STM32 (STM32,F0,F1, F2, F3, F4, F7, etc) boards 1.0.4 K Hoang 19/03/2020 Fix bug. Sync with ESP8266WebServer library of core v2.6.3 1.0.5 K Hoang 17/04/2020 Add support to SAMD51 and SAM DUE boards 1.0.6 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B30_ublox, etc. *****************************************************************************************************************************/ #define DEBUG_ESP8266_AT_WEBSERVER_PORT Serial #if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \ || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD21E18A__) || defined(__SAMD51__) || defined(__SAMD51J20A__) || defined(__SAMD51J19A__) \ || defined(__SAMD51G19A__) || defined(__SAMD21G18A__) ) #if defined(ESP8266_AT_USE_SAMD) #undef ESP8266_AT_USE_SAMD #endif #define ESP8266_AT_USE_SAMD true #endif #if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) #if defined(ESP8266_AT_USE_NRF528XX) #undef ESP8266_AT_USE_NRF528XX #endif #define ESP8266_AT_USE_NRF528XX true #endif #if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) #if defined(ESP8266_AT_USE_SAM_DUE) #undef ESP8266_AT_USE_SAM_DUE #endif #define ESP8266_AT_USE_SAM_DUE true #endif #if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) ) #if defined(ESP8266_AT_USE_STM32) #undef ESP8266_AT_USE_STM32 #endif #define ESP8266_AT_USE_STM32 true #endif #ifdef CORE_TEENSY // For Teensy 4.0 #define EspSerial Serial2 //Serial2, Pin RX2 : 7, TX2 : 8 #if defined(__IMXRT1062__) #define BOARD_TYPE "TEENSY 4.0" #elif ( defined(__MKL26Z64__) || defined(ARDUINO_ARCH_AVR) ) #define BOARD_TYPE "TEENSY LC or 2.0" #else #define BOARD_TYPE "TEENSY 3.X" #endif #elif defined(ESP8266_AT_USE_SAMD) // For SAMD #define EspSerial Serial1 #if defined(ARDUINO_SAMD_ZERO) #define BOARD_TYPE "SAMD Zero" #elif defined(ARDUINO_SAMD_MKR1000) #define BOARD_TYPE "SAMD MKR1000" #elif defined(ARDUINO_SAMD_MKRWIFI1010) #define BOARD_TYPE "SAMD MKRWIFI1010" #elif defined(ARDUINO_SAMD_NANO_33_IOT) #define BOARD_TYPE "SAMD NANO_33_IOT" #elif defined(ARDUINO_SAMD_MKRFox1200) #define BOARD_TYPE "SAMD MKRFox1200" #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) #define BOARD_TYPE "SAMD MKRWAN13X0" #elif defined(ARDUINO_SAMD_MKRGSM1400) #define BOARD_TYPE "SAMD MKRGSM1400" #elif defined(ARDUINO_SAMD_MKRNB1500) #define BOARD_TYPE "SAMD MKRNB1500" #elif defined(ARDUINO_SAMD_MKRVIDOR4000) #define BOARD_TYPE "SAMD MKRVIDOR4000" #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) #define BOARD_TYPE "SAMD ADAFRUIT_ITSYBITSY_M4_EXPRESS" #elif defined(__SAMD21E18A__) #define BOARD_TYPE "SAMD21E18A" #elif defined(__SAMD21G18A__) #define BOARD_TYPE "SAMD21G18A" #elif defined(__SAMD51G19A__) #define BOARD_TYPE "SAMD51G19A" #elif defined(__SAMD51J19A__) #define BOARD_TYPE "SAMD51J19A" #elif defined(__SAMD51J20A__) #define BOARD_TYPE "SAMD51J20A" #elif defined(__SAM3X8E__) #define BOARD_TYPE "SAM3X8E" #elif defined(__CPU_ARC__) #define BOARD_TYPE "CPU_ARC" #elif defined(__SAMD51__) #define BOARD_TYPE "SAMD51" #else #define BOARD_TYPE "SAMD Unknown" #endif #elif (ESP8266_AT_USE_NRF528XX) #if defined(NRF52840_FEATHER) #define BOARD_TYPE "NRF52840_FEATHER" #elif defined(NRF52832_FEATHER) #define BOARD_TYPE "NRF52832_FEATHER" #elif defined(NRF52840_FEATHER_SENSE) #define BOARD_TYPE "NRF52840_FEATHER_SENSE" #elif defined(NRF52840_ITSYBITSY) #define BOARD_TYPE "NRF52840_ITSYBITSY" #elif defined(NRF52840_CIRCUITPLAY) #define BOARD_TYPE "NRF52840_CIRCUITPLAY" #elif defined(NRF52840_CLUE) #define BOARD_TYPE "NRF52840_CLUE" #elif defined(NRF52840_METRO) #define BOARD_TYPE "NRF52840_METRO" #elif defined(NRF52840_PCA10056) #define BOARD_TYPE "NRF52840_PCA10056" #elif defined(NINA_B302_ublox) #define BOARD_TYPE "NINA_B302_ublox" #elif defined(NINA_B112_ublox) #define BOARD_TYPE "NINA_B112_ublox" #elif defined(PARTICLE_XENON) #define BOARD_TYPE "PARTICLE_XENON" #elif defined(ARDUINO_NRF52_ADAFRUIT) #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" #else #define BOARD_TYPE "nRF52 Unknown" #endif #define EspSerial Serial1 #elif defined(ESP8266_AT_USE_SAM_DUE) // For SAM DUE #define EspSerial Serial1 #define BOARD_TYPE "SAM DUE" #elif defined(ESP8266_AT_USE_STM32) // For STM32 #define EspSerial Serial1 #if defined(STM32F0) #define BOARD_TYPE "STM32F0" #elif defined(STM32F1) #define BOARD_TYPE "STM32F1" #elif defined(STM32F2) #define BOARD_TYPE "STM32F2" #elif defined(STM32F3) #define BOARD_TYPE "STM32F3" #elif defined(STM32F4) #define BOARD_TYPE "STM32F4" #elif defined(STM32F7) #define BOARD_TYPE "STM32F7" #else #warning STM32 unknown board selected #define BOARD_TYPE "STM32 Unknown" #endif #else // For Mega #define EspSerial Serial3 #define BOARD_TYPE "AVR Mega" #endif #include <ESP8266_AT_WebServer.h> char ssid[] = "Andreia Oi Miguel 2.4G"; // your network SSID (name) char pass[] = "xxxxxxxx"; // your network password //char ssid[] = "****"; // your network SSID (name) //char pass[] = "****"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status int reqCount = 0; // number of requests received ESP8266_AT_WebServer server(80); const int led = 13; void handleRoot() { digitalWrite(led, 1); char temp[400]; int sec = millis() / 1000; int min = sec / 60; int hr = min / 60; snprintf(temp, 400, "<html>\ <head>\ <meta http-equiv='refresh' content='5'/>\ <title>ESP8266 Demo</title>\ <style>\ body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\ </style>\ </head>\ <body>\ <h1>Hello from ESP8266!</h1>\ <p>Uptime: %02d:%02d:%02d</p>\ <img src=\"/test.svg\" />\ </body>\ </html>", hr, min % 60, sec % 60); server.send(200, "text/html", temp); digitalWrite(led, 0); } void handleNotFound() { digitalWrite(led, 1); String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET) ? "GET" : "POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i = 0; i < server.args(); i++) { message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; } server.send(404, "text/plain", message); digitalWrite(led, 0); } void drawGraph() { String out; out.reserve(3000); char temp[70]; out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n"; out += "<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n"; out += "<g stroke=\"black\">\n"; int y = rand() % 130; for (int x = 10; x < 300; x += 10) { int y2 = rand() % 130; sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x, 140 - y, x + 10, 140 - y2); out += temp; y = y2; } out += "</g>\n</svg>\n"; server.send(200, "image/svg+xml", out); } void setup(void) { pinMode(led, OUTPUT); digitalWrite(led, 0); Serial.begin(115200); while (!Serial); Serial.println("\nStarting AdvancedServer on " + String(BOARD_TYPE)); // initialize serial for ESP module EspSerial.begin(115200); // initialize ESP module WiFi.init(&EspSerial); Serial.println(F("WiFi shield init done")); // check for the presence of the shield if (WiFi.status() == WL_NO_SHIELD) { Serial.println(F("WiFi shield not present")); // don't continue while (true); } // attempt to connect to WiFi network while ( status != WL_CONNECTED) { Serial.print(F("Connecting to WPA SSID: ")); Serial.println(ssid); // Connect to WPA/WPA2 network status = WiFi.begin(ssid, pass); } server.on("/", handleRoot); server.on("/test.svg", drawGraph); server.on("/inline", []() { server.send(200, "text/plain", "this works as well"); }); server.onNotFound(handleNotFound); server.begin(); Serial.print(F("HTTP server started @ ")); Serial.println(WiFi.localIP()); } void loop(void) { server.handleClient(); }

THANKS TO Khoi Hoang

Dúvidas:


suporte@smartcore.com.br

Referências:

https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
https://www.u-blox.com/en/docs/UBX-17056481
https://www.u-blox.com/sites/default/files/NINA-B3_DataSheet_%28UBX-17052099%29.pdf


Sobre a SMARTCORE

A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso portifó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

Nenhum comentário:

Postar um comentário