Forum Controllers/PLC

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

Lora with Industrial Shield ESP32 19R PLC?

Avatar
Ghazi Drira

the code examples shared on the official website with the code for the Arduino PLC or the PLC 14 are not executable. 

Pin reset? Pin  Chip Select?

Pourriez-vous nous fournir un exemple de code fonctionnel pour l'automatisme Industrial Shield ESP32 19R avec le module LoRa RN2483 (en langage C ou microPython) ?


#include

#include

#include

#include "HardwareSerialPicMkesp.h"


HardwareSerialPIC sériePIC = HardwareSerialPIC();

Adafruit_MCP23X17 mcp;


void setup() {

    // Débit en bauds pour le port série

    Série.begin(57600);

    retard (100);


    Serial.println("Initialiser mcp");

    mcp.begin_I2C();


    Serial.println(" Réinitialiser le module LoRa (actif LOW)");

    mcp.pinMode(3, SORTIE);

    retard (100);

    mcp.digitalWrite(3, FAIBLE);

    retard (100);

    mcp.digitalWrite(3, ÉLEVÉ);


    Serial.println("Démarrer le module LoRa");

    sériePIC.begin(120, 17);

Serial.println(serialPIC.available());

    // Vider le port

    while(serialPIC.available()) {

        Serial.print((char)serialPIC.read());

        retard(10);

    }

    Serial.println("okkkkkk");

}


boucle vide() {

    if (Série.disponible()) {

        octet rx = Serial.read();

        sériePIC.write(rx);

        

    }


    si (serialPIC.available()) {

        Serial.print((char)serialPIC.read());

    }

}

Avatar
Discard
1 Answer
0
Best Answer

Here is a code for an ESP32 + LORA PLC, I hope you find it useful.

/*
*  Board: ESP32 Dev Module

* To set the frequency:
* sys get ver // Check that there is communication requesting the module firmware version
* radio set freq 915000000 // United States
* radio set freq 868000000 // Europa
* radio set freq 433000000 // Asia
* radio get freq // Check that the correct frequency has been configured

*  To receive:
*  mac pause
*  radio rx 0
*
*  To send:
*  mac pause
*  radio tx ABC

*/

#include
#include

// Click 1
#define SPIUART_CLICK_1 SC16IS752_CHANNEL_A

#define CS 12
#define BAUD 57600      // Defaults to the RN2483A module. If that doesn't work, try other speeds: 9600, 38400, 115200, etc.

Adafruit_MCP23008 mcp;
SC16IS752 spiuart = SC16IS752(SC16IS750_PROTOCOL_SPI, CS);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {

  Serial.begin(115200UL);
  delay(1000);

  setupMCP();

  spiuart.begin(BAUD, BAUD);
  if (spiuart.ping() != 1) {
    Serial.println("Expansor SC16IS752 no found");
    while (1);
  } else {
    Serial.println("Expansor SC16IS752 found");
  }

  Serial.println("Start serial communication");

  while (!spiuart.available(SPIUART_CLICK_1));
  while (spiuart.available(SPIUART_CLICK_1)) {
    Serial.print((char)spiuart.read(SPIUART_CLICK_1));
    delay(10);
  }

  delay(1000);

  spiuart.flush(SPIUART_CLICK_1);
  Serial.println("Sending mac pause");
  const char* command = "mac pause\r\n";
  for (int i = 0; i     spiuart.write(SPIUART_CLICK_1, command[i]);
  }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
  if (Serial.available()) {
    byte a = Serial.read();
    spiuart.write(SPIUART_CLICK_1, a);
  }
  while (spiuart.available(SPIUART_CLICK_1)) {
    Serial.print((char)spiuart.read(SPIUART_CLICK_1));
  }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setupMCP()
{
  Serial.println("Init MCP23008...");
  mcp.begin(3);           // MCP: 0x23
  mcp.pinMode(6, OUTPUT); // RST: GP6
  delay(1000);
  mcp.digitalWrite(6, LOW);
  delay(1000);
  mcp.digitalWrite(6, HIGH);
  Serial.println("OK");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Avatar
Discard