Programming #
The NORVI GSM-AE08-V-G has a mini USB Port for serial connection with the SoC for programming. Any ESP32-supported programming IDE can be used to program the controller. Follow this Guide to programming NORVI ESP32-based controllers with the Arduino IDE.
SoC: ESP32-WROOM32
Programming Port: USB UART
Digital Inputs #
Wiring Digital Inputs #
The digital inputs of the NORVI GSM-AE08-V-G can be configured as both Sink and Source connections. The inverse of the Digital Input polarity should be supplied to the common terminal.
Programming Digital Inputs #
Reading the relevant GPIO of the ESP32 gives the value of the Digital Input. When the inputs are in the OFF state, the GPIO goes HIGH, and when the input is in the ON state, the GPIO goes LOW. Refer to the GPIO allocation table in the datasheet for the digital input GPIO.
#define INPUT1 34
void setup() {
Serial.begin(9600);
Serial.println("Device Starting");
pinMode(INPUT1, INPUT);
}
void loop() {
Serial.print(digitalRead(INPUT1));
Serial.println("");
delay(500);
}
0 – 10V Analog Input #
Wiring Analog Inputs #
Reading Analog Input #
Reading the relevant I2C address of the ADC gives the value of the Analog Input.
Programming Analog Inputs #
#include <Adafruit_ADS1X15.h>
#include <Wire.h>
Adafruit_ADS1115 ads1;
void setup() {
Serial.begin(9600);
Serial.println("Device Starting");
Wire.begin(16,17);
ads1.begin(0x48);
ads1.setGain(GAIN_ONE);
}
void loop() {
Serial.print("Analog 0 ");
Serial.println(ads1.readADC_SingleEnded(0));
delay(10);
Serial.print("Analog 1 ");
Serial.println(ads1.readADC_SingleEnded(1));
delay(10);
Serial.print("Analog 2 ");
Serial.println(ads1.readADC_SingleEnded(2));
delay(10);
Serial.print("Analog 3 ");
Serial.println(ads1.readADC_SingleEnded(3));
delay(10);
Serial.println("");
delay(500);
}
RS-485 Communication #
RS-485 Wiring #
Driver | MAX485 |
UART RX | GPIO25 |
UART TX | GPIO26 |
Flow Control | GPIO22 |
Programming RS-485 #
NORVI-GSM-AE08 series RS-485 connection uses a half-duplex mode of MAX485 transmitter with UART
Communication.
#define RXD 25
#define TXD 26
#define FC 22
void setup() {
Serial.begin(9600);
pinMode(FC, OUTPUT);
Serial1.begin(9600, SERIAL_8N1,RXD,TXD);
}
void loop() {
digitalWrite(FC, HIGH); // Make FLOW CONTROL pin HIGH
Serial1.println("RS485 01 SUCCESS"); // Send RS485 SUCCESS serially
delay(500); // Wait for transmission of data
digitalWrite(FC, LOW); // Receiving mode ON
while (Serial1.available()) { // Check if data is available
char c = Serial1.read(); // Read data from RS485
Serial.write(c); // Print data on serial monitor
}
delay(1000);
}
Built-in OLED Display #
Display driver | SSD1306 |
Communication | I2C |
Module Address | 0x3C |
Resolution | 128 x 64 |
Refer to the GPIO allocation table in the Datasheet for the I2C GPIO of the OLED Display.
Library supported by the Adafruit_SSD0306 Library.
Wire.begin (SDA, SCL) is required to initialize I2C on the correct pins.
Programming OLED Display #
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Wire.begin(16,17);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
// Address 0x3C for 128x64 Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen –
// the library initializes this with an Adafruit splash screen.
display.display(); delay(2000); // Pause for 2 seconds
}
void loop() {
}
Built-in Buttons #
Read mode | ADC (Analog to Digital Conversion) |
Analog IO | GPIO36 |
Programming Buttons #
#define buttonPin 36
int buttonState = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin,INPUT);
}
void loop() {
Serial.print("Button: ");
buttonState = analogRead(buttonPin);
delay(50);
Serial.print(analogRead(buttonPin));
Serial.print("\tAnalog: ");
delay(1000);
}
Internal RTC #
RTC Chip | DS3231 |
Backup Battery Type | CR2032 |
Interface | I2C |
I2C Address | 0x68 |
SCL Pin | GPIO17 |
SDA Pin | GPIO16 |
Programming RTC #
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
rtc.adjust(DateTime(__DATE__, __TIME__));
display.display();
delay(2);
display.clearDisplay();
display.clearDisplay();
display.setTextColor(WHITE); //display.startscrollright(0x00, 0x0F);
display.setTextSize(2);
display.setCursor(0,5);
display.print(" Clock ");
display.display();
delay(3000);
}
void loop() {
DateTime now = rtc.now();
display.clearDisplay();
display.setTextSize(2);
display.setCursor(75,0);
display.println(now.second(), DEC);
display.setTextSize(2);
display.setCursor(25,0);
display.println(":");
display.setTextSize(2);
display.setCursor(65,0);
display.println(":");
display.setTextSize(2);
display.setCursor(40,0);
display.println(now.minute(), DEC);
display.setTextSize(2);
display.setCursor(0,0);
display.println(now.hour(), DEC);
display.setTextSize(2);
display.setCursor(0,20);
display.println(now.day(), DEC);
display.setTextSize(2);
display.setCursor(25,20);
display.println("-");
display.setTextSize(2);
display.setCursor(40,20);
display.println(now.month(), DEC);
display.setTextSize(2);
display.setCursor(55,20);
display.println("-");
display.setTextSize(2);
display.setCursor(70,20);
display.println(now.year(), DEC);
display.setTextSize(2);
display.setCursor(0,40);
display.print(daysOfTheWeek[now.dayOfTheWeek()]);
display.display();
}
Micro SD Card Support #
SD CARD CS | GPIO15 |
MISO | GPIO19 |
MOSI | GPIO23 |
SCLK | GPIO18 |
Programming SD Card #
#include <SD.h>
#define PIN_SPI_CS 15 // The ESP32 pin GPIO15
File myFile;
void setup() {
Serial.begin(9600);
if (!SD.begin(PIN_SPI_CS)) {
Serial.println(F("SD CARD FAILED, OR NOT PRESENT!"));
while (1); // stop the program
}
Serial.println(F("SD CARD INITIALIZED."));
if (!SD.exists("esp32.txt")) {
Serial.println(F("esp32.txt doesn't exist. Creating esp32.txt file..."));
// create a new file by opening a new file and immediately close it
myFile = SD.open("esp32.txt", FILE_WRITE);
myFile.close();
}
// recheck if file is created or not
if (SD.exists("esp32.txt"))
Serial.println(F("esp32.txt exists on SD Card."));
else
Serial.println(F("esp32.txt doesn't exist on SD Card."));
}
void loop() {
}
Ethernet SPI – W5500 #
Transceiver | W5500 |
SCSn | GPIO5 |
MISO | GPIO19 |
MOSI | GPIO23 |
SCLK | GPIO18 |
RSTn | GPIO22 |
Programming Ethernet #
#include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
unsigned int localPort = 8888;
const char timeServer[] = "time.nist.gov";
const int NTP_PACKET_SIZE = 48;
byte packetBuffer[NTP_PACKET_SIZE];
EthernetUDP Udp;
void setup() {
Serial.begin(9600);
Ethernet.init(5); // ESP32 with Adafruit Featherwing Ethernet
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
}
else {
Udp.begin(localPort);
sendNTPpacket(timeServer);
delay(1000);
if (Udp.parsePacket()) {
Udp.read(packetBuffer, NTP_PACKET_SIZE);
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears;
Serial.print("Unix time = ");
Serial.println(epoch);
Serial.print("The UTC time is ");
Serial.print((epoch % 86400L) / 3600);
Serial.print(':');
if (((epoch % 3600) / 60) < 10) {
Serial.print('0');
}
Serial.print((epoch % 3600) / 60);
Serial.print(':');
if ((epoch % 60) < 10) {
Serial.print('0');
}
Serial.println(epoch % 60);
}
delay(3000);
Ethernet.maintain();
}
}
void loop() {
// Your loop code for Ethernet can go here if needed.
}
void sendNTPpacket(const char * address) {
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011;
packetBuffer[1] = 0;
packetBuffer[2] = 6;
packetBuffer[3] = 0xEC;
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
Udp.beginPacket(address, 123);
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
GSM Communication #
Model of GSM Modem | SIM800C |
FCC ID | UDU-SIM800C |
TAC | 86610402 |
RXD | GPIO33 |
TXD | GPIO32 |
Programming GSM Communication #
#define GSM_RX 33
#define GSM_TX 32
unsigned long int timer1 = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Hello");
Serial2.begin(9600, SERIAL_8N1, GSM_RX, GSM_TX);
timer1 = millis();
Serial2.println("AT");
while(millis()<timer1+10000){
while (Serial2.available()) {
int inByte = Serial2.read();
Serial.write(inByte);
}
}
timer1 = millis();
Serial2.println("AT+CPIN?");
while(millis()<timer1+10000){
while (Serial2.available()) {
int inByte = Serial2.read();
Serial.write(inByte);
}
}
timer1 = millis();
Serial2.println("AT+CFUN?");
while(millis()<timer1+10000){
while (Serial2.available()) {
int inByte = Serial2.read();
Serial.write(inByte);
}
}
Serial.println("AT TIMEOUT");
}
void loop() {
while (Serial.available()) {
int inByte = Serial.read();
Serial2.write(inByte);
}
while (Serial2.available()) {
int inByte = Serial2.read();
Serial.write(inByte);
}
// put your main code here, to run repeatedly:
}