Categories

WREN S2 DE SDK – Board Bring Up and Test Code

WIKI:
  • Main
  • Firmware
  • WREN S2 DE SDK – Board Bring Up and Test Code

The WREN S2 DE SDK  example code below is used for Board Bring Up and Test Input/Output Ports.

This Arduino IDE example (Settings. Board: ESP32-S2 Dev Module), basically exercises the RGB LED, Temperature Sensor, Voltage Sensor, Inputs and DC Motor Outputs.

Example UART Output
Connected to Temperature Sensor TMP102! PCB Temperature: 26.00 °C
LED Cycle Check
Motor 1 Cycle Check
Motor 2 Cycle Check
PCB Temperature: 26.12 °C
ADC Raw Value: 8191 Voltage: 30V
PCB Temperature: 26.19 °C
ADC Raw Value: 8191 Voltage: 30V
PCB Temperature: 26.19 °C
ADC Raw Value: 8191 Voltage: 30V
WREN Motor Driver 2A High
PCB Temperature: 26.19 °C
ADC Raw Value: 8191 Voltage: 30V
WREN Motor Driver 1A High
PCB Temperature: 26.25 °C
ADC Raw Value: 8191 Voltage: 30V
PCB Temperature: 26.25 °C
ADC Raw Value: 8191 Voltage: 30V

 

Requires: SparkFunTMP102.h

 

/*
  Dave Williams, DitroniX 2020
  WREN S2 DE SDK V1  
  DC Linear Motor Controller ESP32-S2 (PCA v1.15 Sept 2020)
  Simplified Board Bring Up and Test Input/Output Ports
  This code is OPEN SOURCE and may freely be used
  No Wifi Enabled
 */

/*
 Test LED Sequence
 * White - Check Temp Sensor or I2C
 * RGB Blue, Green and Red Self Test
 * Blue Long - Motor 1 Cycle Test
 * Green Long - Motor 2 Cycle Test
 * Red Heart Beat - Checking for Controller Input
 * Blue - Input Detected and Motor On
 */
 
#include <Arduino.h>
#include "time.h"

#include <Wire.h> 
#include <SparkFunTMP102.h> // Example include for TMP102

// Configure WREN GPIO

// **************** INPUTS ****************

// Define Input Ports (from External 24V Inputs)
#define WREN_IN_1A 9  //(Button 1 - DIN Pin 4 - Black)
#define WREN_IN_2A 8  //(Button 2 - DIN Pin 2 - Yellow)
#define WREN_IN_1B 10 //(Button 3 - DIN Pin 5 - Brown)
#define WREN_IN_2B 11 //(Button 4 - DIN Pin 3 - Red)

// Define ADC (12 DC - 30V DC)
#define WREN_ADC 4 

// Define Temp Alarm
#define WREN_TALM 16 

// Define Enable #Predefined.  Reference Only.
#define WREN_EN 41

// **************** OUTPUTS ****************

// Define Output Ports A (L6205 Inputs)
#define WREN_EN_A 5 // Port A
#define WREN_OUT_1A 13 //(DIN Pin 4 - Black)
#define WREN_OUT_2A 12 //(DIN Pin 2 - Yellow)

// Define Output Ports B (L6205 Inputs)
#define WREN_EN_B 4 // Port B
#define WREN_OUT_1B 7 //(DIN Pin 5 - Brown)
#define WREN_OUT_2B 6 //(DIN Pin 3 - Red)

// Define LED (RGB LED)
#define LED_Blue 1
#define LED_Green 2
#define LED_Red 3

// **************** IO ****************

// Define I2C (Expansion Port)
#define I2C_SDA 33
#define I2C_SCL 34 

// Define SPI (Expansion Port)
#define SPI_MOSI 35
#define SPI_MISO 36
#define SPI_SCK 37

// Define UART (UART Port)
#define UART_RXD 44
#define UART_TXD 43

// Define USB (USB Port) #Predefined.  Reference Only.
//#define USB_D- 19
//#define USB_D+ 20

// Define JTAG (JTAG Port) #Predefined.  Reference Only.
//#define JTAG_TMS 42
//#define JTAG_TDI 41
//#define JTAG_TDO 40
//#define JTAG_TCK 39

// **************** VARIABLES ****************

// Define DIN Input Ports (from External 24V/29V Inputs)
int WREN_IN_1A_State = 0; // DIN 4
int WREN_IN_2A_State = 0; // DIN 2
int WREN_IN_1B_State = 0; // DIN 5
int WREN_IN_2B_State = 0; // DIN 3

int WREN_Bridged_State = 0; // Special Bridged Parallel Mode
int WREN_Input_State = 0; // Special Bridged Parallel Mode

int ButtonVal_1A = 0; // 1
int ButtonVal_2A = 0; // 2
int ButtonVal_1B = 0; // 3
int ButtonVal_2B = 0; // 4 

float PCB_Temp;

// **************** SENSOR ****************
TMP102 sensor0;  // Address

// Setup 
void setup() {

// **************** INPUTS ****************

// Initialize Input Ports (from External 24V Inputs)
  pinMode (WREN_IN_1A, INPUT_PULLDOWN);
  pinMode (WREN_IN_2A, INPUT_PULLDOWN);
  pinMode (WREN_IN_1B, INPUT_PULLDOWN);
  pinMode (WREN_IN_2B, INPUT_PULLDOWN);

// Initialize ADC (24V DC)
//  pinMode (WREN_ADC, INPUT);

// Initialize Temp larm
  pinMode (WREN_TALM, INPUT);

// Initialize Enable
  pinMode (WREN_EN, INPUT_PULLUP);

// **************** OUTPUTS ****************

// Initialize Output Ports A (L6205 Inputs)
  pinMode (WREN_EN_A, OUTPUT);
  pinMode (WREN_OUT_1A, OUTPUT);
  pinMode (WREN_OUT_2A, OUTPUT);

// Initialize Output Ports B (L6205 Inputs)
  pinMode (WREN_EN_B, OUTPUT);
  pinMode (WREN_OUT_1B, OUTPUT);
  pinMode (WREN_OUT_2B, OUTPUT);

// Initialize LED (RGB LED)
  pinMode (LED_Blue, OUTPUT);
  pinMode (LED_Green, OUTPUT);
  pinMode (LED_Red, OUTPUT);

// **************** COMMS ****************

// Initialize I2C
  Wire.begin(I2C_SDA, I2C_SCL);
  
// Initialize UART:
  Serial.begin(115200, SERIAL_8N1, UART_RXD, UART_TXD);  //115200
  Serial.println("DitroniX WREN S2 DE SDK V1 Initialized");

// PCB Temperature Sensor
  if(!sensor0.begin())
  {
    // Sensor or I2C Issue
    Serial.println("Cannot connect to Temperature Sensor TMP102!");
    digitalWrite(LED_Blue, LOW);
    digitalWrite(LED_Green, LOW);
    digitalWrite(LED_Red, LOW);    
    delay(2000);
  }
  else
  {
    Serial.print("Connected to Temperature Sensor TMP102!");
     // Read PCB_Temp Sensor and Output
    PCB_Temp = sensor0.readTempC();
    Serial.print("   PCB Temperature: ");
    Serial.print(PCB_Temp, 2);
    Serial.println(" °C");
  }
  
  // Test Cycle RGB LED
  Serial.println("LED Cycle Check");   
  digitalWrite(LED_Blue, HIGH);
  digitalWrite(LED_Green, HIGH);
  digitalWrite(LED_Red, HIGH);
  
  digitalWrite(LED_Blue, LOW);   
  delay(1000);              
  digitalWrite(LED_Blue, HIGH);
  delay(250); 
  
  digitalWrite(LED_Green, LOW);   
  delay(1000);              
  digitalWrite(LED_Green, HIGH);
  delay(250); 

  digitalWrite(LED_Red, LOW);   
  delay(1000);              
  digitalWrite(LED_Red, HIGH);
  delay(250); 

  // Enable both Motor Driver Ports
  digitalWrite(WREN_EN_A, HIGH);      
  digitalWrite(WREN_EN_B, HIGH); 

   // Test Cycle Motor 1 (A)
  Serial.println("Motor 1 Cycle Check");   
  digitalWrite(LED_Blue, LOW);   
  digitalWrite(WREN_OUT_1A, HIGH);
  digitalWrite(WREN_OUT_2A, LOW);
  delay(2000);
  digitalWrite(WREN_OUT_2A, HIGH); 
  digitalWrite(WREN_OUT_1A, LOW);  
  delay(2000);
  digitalWrite(WREN_OUT_1A, LOW);  
  digitalWrite(WREN_OUT_2A, LOW);  
  digitalWrite(LED_Blue, HIGH);    

  // Test Cycle Motor 2 (B)
  Serial.println("Motor 2 Cycle Check");     
  digitalWrite(LED_Green, LOW);     
  digitalWrite(WREN_OUT_1B, HIGH);  
  digitalWrite(WREN_OUT_2B, LOW);  
  delay(2000);
  digitalWrite(WREN_OUT_2B, HIGH); 
  digitalWrite(WREN_OUT_1B, LOW);  
  delay(2000);
  digitalWrite(WREN_OUT_1B, LOW); 
  digitalWrite(WREN_OUT_2B, LOW);  
  digitalWrite(LED_Green, HIGH);  
}


// Loop
void loop() {

  // Read PCB_Temp Sensor and Output
  PCB_Temp = sensor0.readTempC();
  Serial.print("PCB Temperature: ");
  Serial.print(PCB_Temp, 2);
  Serial.println(" °C");

  // Read ADC DC Voltage Sensor and Output
  Serial.print("ADC Raw Value: ");
  Serial.print(analogRead(WREN_ADC));
  Serial.print("    Voltage: ");
  Serial.print(((analogRead(WREN_ADC) * 30 ) / 8191));
  Serial.println("V");
 
  //Read Input / Buttons
  ButtonVal_1A = digitalRead(WREN_IN_1A);   // Read the input pin 1A
  ButtonVal_2A = digitalRead(WREN_IN_2A);   // Read the input pin 2A
  ButtonVal_1B = digitalRead(WREN_IN_1B);   // Read the input pin 1B
  ButtonVal_2B = digitalRead(WREN_IN_2B);   // Read the input pin 2B

  // Basic Detection.  If any Input High then set appropriate Motor Output High
  if (ButtonVal_1A == HIGH || ButtonVal_1B == HIGH || ButtonVal_2A == HIGH || ButtonVal_2B == HIGH)  {

      // Heat Beat Blue LED
      digitalWrite(LED_Blue, LOW);    
      delay(100);    
      digitalWrite(LED_Blue, HIGH);      

      if (ButtonVal_1A == HIGH) {
        digitalWrite(WREN_OUT_1A, HIGH);  // Sets Motor Driver Output High if Input High
        Serial.println("WREN Motor Driver 1A High");
      }
      
      if (ButtonVal_2A == HIGH) {
        digitalWrite(WREN_OUT_2A, HIGH);  // Sets Motor Driver Output High if Input High
        Serial.println("WREN Motor Driver 2A High");
      }
      
      if (ButtonVal_1B == HIGH) {
        digitalWrite(WREN_OUT_1B, HIGH);  // Sets Motor Driver Output High if Input High
        Serial.println("WREN Motor Driver 1B High");
      }
            
      if (ButtonVal_2B == HIGH) {
        digitalWrite(WREN_OUT_2B, HIGH);  // Sets Motor Driver Output High if Input High
        Serial.println("WREN Motor Driver 2B High");
      }
    
  } else {
        
      // Sets All Motor Driver Outputs Low
      digitalWrite(WREN_OUT_1A, LOW);    
      digitalWrite(WREN_OUT_2A, LOW); 
      digitalWrite(WREN_OUT_1B, LOW); 
      digitalWrite(WREN_OUT_2B, LOW); 
    
      // Heat Beat Red LED
      delay(500);   
      digitalWrite(LED_Red, LOW);    
      delay(1000);    
      digitalWrite(LED_Red, HIGH);  
  }
  
}

 

Leave a Reply