NPK Sensor that display results in OLED screen, has wifi connection and visualize the results in Thingspeak

Hello! My name is Camila and I am an engineering student.
I am carrying out a project that involves the use of a NPK sensor (pH and conductivity), an Arduino One R3 board, a Wifi module, an Oled screen and a Raspberry pi zero 2 W processor.
The objective of this project is to measure the two sensor variables, being reflected on the screen and on the Thingspeak platform, through the Wifi module.
However, I am not an expert, so I have not been able to figure out how to connect the wifi module to send the data to Thingspeak.
I ask you please if someone can help me solve the problem.
Next, I copy the code that I am using and a photo of the circuit.

#include <SoftwareSerial.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
#define OLED_RESET -1     // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define RE 8
#define DE 7
#define DI 3
#define RO 2

// Inicializamos variables
const byte inquiry_frame[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x04, 0x08 };

byte values[19];
SoftwareSerial mod(2, 3);

// SoftwareSerial esp8266(11,13);  //Rx ==> Pin 13; TX ==> Pin 11 

void setup() {
  //esp8266.begin (4800);
  Serial.begin(4800);
  mod.begin(4800);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);
  //Serial.println("ESP8266 Setup test - use AT coomands");

  // Inicializar la pantalla OLED con I2C address 0x3C (128x64)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  delay(500);  // Pausa breve para permitir que el display se inicialice

  // Limpiar el display para asegurarse de que no haya contenido previo
  display.clearDisplay();

  // Configurar posición, tamaño y color del texto
  display.setTextSize(1);
  display.setTextColor(WHITE);

  // Calcular la posición en x para centrar horizontalmente el texto "RubiscoLab"
  String rubiscoText = "RubiscoLab";
  int xPositionRubisco = (128 - (rubiscoText.length() * 6)) / 2; 
  display.setCursor(xPositionRubisco, 10);  // Ajuste la posición vertical para el espacio entre líneas
  display.println(rubiscoText);

  // Calcular la posición en x para centrar horizontalmente el texto "Biotechnology"
  String biotechText = "Biotechnology";
  int xPositionBiotech = (128 - (biotechText.length() * 6)) / 2;
  display.setCursor(xPositionBiotech, 20);  // Ajuste la posición vertical para el espacio entre líneas
  display.println(biotechText);

  // Configurar posición para "Inicializando" y mostrarlo un poco más abajo
  display.setCursor(25, 45);  // Ajustado a una posición vertical más baja
  display.print("Inicializando");

  // Actualizar el display para mostrar los cambios
  display.display();

  // Pausa de 3 segundos antes de continuar
  delay(3000);
}

void loop() {

  float val1, val2;
  val1 = ph();
  delay(250);
  val2 = ce();
  delay(250);

  if (false) {
  Serial.print("pH: ");
  Serial.print(val1);
  Serial.println();
  Serial.print("CE: ");
  Serial.print(val2);
  Serial.println(" mS/cm");
  Serial.println();
  }
  delay(1000);
  

  display.clearDisplay();

  display.setTextSize(2);
  
  // Mostrar el valor de pH
  display.setCursor(0, 10); // Ajuste vertical para centrar
  display.print("pH: ");
  display.print(val1);
 
  // Mostrar el valor de CE
  display.setCursor(0, 40); // Ajuste vertical para centrar
  display.print("CE: ");
  display.print(val2);
  display.setTextSize(1);
  display.print(" mS/cm");

  display.display();

}

float ph() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);

  if (mod.write(inquiry_frame, sizeof(inquiry_frame)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 19; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i], HEX);
    }
    Serial.println();
  }

  return (float(values[9] << 8 | values[10])) / 10.00;
}

float ce() {
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);

  if (mod.write(inquiry_frame, sizeof(inquiry_frame)) == 8) {
    digitalWrite(DE, LOW);
    digitalWrite(RE, LOW);
    for (byte i = 0; i < 19; i++) {
      //Serial.print(mod.read(),HEX);
      values[i] = mod.read();
      //Serial.print(values[i], HEX);
    }
    Serial.println();
  }

  return (float(values[7] << 8 | values[8])) / 1000.00;
}


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.