0

using feather esp32 and serial plotter
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

using feather esp32 and serial plotter

by Pcor on Tue Mar 09, 2021 7:48 pm

This is the code I am using to try and test my shift registers. When I run this nothing appears in my serial plotter or serial monitor. I am using a feather esp32. any help or ideas would be appreciated.

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>

const int LATCH = A5;

//Pins Feather ESP32
const byte powerGates1 = 15;
const byte powerGates2 = 33;

//Pins ItsyBitsy
//const byte powerGates1 = 10;
//const byte powerGates2 = 11;

void setup ()
{
 
  SPI.begin();
  SPI.beginTransaction(SPISettings(3000000, MSBFIRST, SPI_MODE2)); //3Mhz
  //Reading 24 bits (all sensors) at 1Mhz should take about 24 microseconds,
  //reading 24 bits (all sensors) at 3Mhz should take about 8us
 
  Serial.begin (115200);
  Serial.println ("Begin switch test.");
  pinMode (LATCH, OUTPUT);
  digitalWrite (LATCH, HIGH);

  pinMode (powerGates1, OUTPUT);
  digitalWrite(powerGates1, LOW);
  pinMode (powerGates2, OUTPUT);
  digitalWrite(powerGates2, LOW);
 
}  // end of setup

byte switchBank1;
byte oldSwitchBank1;
byte switchBank2;
byte oldSwitchBank2;
byte switchBank3;
byte oldSwitchBank3;
byte switchBank4;
byte oldSwitchBank4;
byte switchBank5;
byte oldSwitchBank5;
byte switchBank6;
byte oldSwitchBank6;

void loop ()
{
  digitalWrite(powerGates1, HIGH);
  digitalWrite(powerGates2, HIGH);
  delayMicroseconds(75); //first 24 gates only need 15us while gates closer to the end need ~40us-75us
 
 
  digitalWrite (LATCH, LOW);    // pulse the parallel load latch
  delayMicroseconds(3);
  digitalWrite (LATCH, HIGH);

  delayMicroseconds(3);
 
  digitalWrite(powerGates1, LOW);
  digitalWrite(powerGates2, LOW);

  switchBank1 = SPI.transfer (0); //8
  switchBank2 = SPI.transfer (0); //16
  switchBank3 = SPI.transfer (0); //24
  switchBank4 = SPI.transfer (0); //32
  switchBank5 = SPI.transfer (0); //40
  switchBank6 = SPI.transfer (0); //48 
 
 
  byte mask = 1;
  int sensor = 1;
  for (int i = 1; i <= 8; i++)
  {
    if ((switchBank1 & mask) != (oldSwitchBank1 & mask))
      {
      Serial.print ("Switch ");
      Serial.print (sensor);
      Serial.print (" ");
      Serial.println ((switchBank1 & mask) ? "ir triggered" : "none");
      }  // end of bit has changed
    mask <<= 1;
    sensor++;
  }  // end of for each bit
  mask = 1;
  sensor = 9;
  for (int i = 1; i <= 8; i++)
  {
    if ((switchBank2 & mask) != (oldSwitchBank2 & mask))
      {
      Serial.print ("Switch ");
      Serial.print (sensor);
      Serial.print (" ");
      Serial.println ((switchBank2 & mask) ? "ir triggered" : "none");
     
      }  // end of bit has changed
    mask <<= 1;
    sensor++;
  }  // end of for each bit
  mask = 1;
  sensor = 17;
  for (int i = 1; i <= 8; i++)
  {
    if ((switchBank3 & mask) != (oldSwitchBank3 & mask))
    {
      Serial.print ("Switch ");
      Serial.print (sensor);
      Serial.print (" ");
      Serial.println ((switchBank3 & mask) ? "ir triggered" : "none");
    }  // end of bit has changed
    mask <<= 1;
    sensor++; 
  }  // end of for each bit
  mask = 1;
  sensor = 25;
  for (int i = 1; i <= 8; i++)
  {
    if ((switchBank4 & mask) != (oldSwitchBank4 & mask))
    {
      Serial.print ("Switch ");
      Serial.print (sensor);
      Serial.print (" ");
      Serial.println ((switchBank4 & mask) ? "ir triggered" : "none");
    }  // end of bit has changed
    mask <<= 1;
    sensor++;
  }  // end of for each bit
  mask = 1;
  sensor = 33;
  for (int i = 1; i <= 8; i++)
  {
    if ((switchBank5 & mask) != (oldSwitchBank5 & mask))
    {
      Serial.print ("Switch ");
      Serial.print (sensor);
      Serial.print (" ");
      Serial.println ((switchBank5 & mask) ? "ir triggered" : "none");
    }  // end of bit has changed
    mask <<= 1;
    sensor++;
  }  // end of for each bit
  mask = 1;
  sensor = 41;
  for (int i = 1; i <= 8; i++)
  {
    if ((switchBank6 & mask) != (oldSwitchBank6 & mask))
    {
      Serial.print ("Switch ");
      Serial.print (sensor);
      Serial.print (" ");
      Serial.println ((switchBank6 & mask) ? "ir triggered" : "none");
    }  // end of bit has changed
    mask <<= 1; 
    sensor++;
  }  // end of for each bit

  oldSwitchBank1 = switchBank1;
  oldSwitchBank2 = switchBank2;
  oldSwitchBank3 = switchBank3;
  oldSwitchBank4 = switchBank4;
  oldSwitchBank5 = switchBank5;
  oldSwitchBank6 = switchBank6;

  delay (20);   // must be greater than 7.5ms (see notes at top of code)
}  // end of loop

Pcor
 
Posts: 6
Joined: Mon Mar 08, 2021 12:08 pm

Re: using feather esp32 and serial plotter

by mikeysklar on Wed Mar 10, 2021 6:45 pm

The ESP32 is a fast processor. I would add a delay(100) in your setup before initializing anything. Also make sure your serial monitor in the Arduino app is set to 115200.

mikeysklar
 
Posts: 5020
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.