Automated Dust Collection

gladewater2016: It is switching the relay now. It is just working backwards from what I expected. But that is fine..

That may be simply your relay working in reverse. Some are active high, others active low, and then there's the NO side and the NC side. Anyway it's a matter of changing those states in your code and you should be good to go.

For the servo part, do you have the servo working with basic servo example scripts, like sweep? Always good to use those to test your components. If that doesn't work it's wiring; if it does work it's in your code.

After making those changes please do post the latest version of your code (properly formatted, in a new message).

I have a small simple servo and a more expensive digital servo.The small servo is working with the sweep code when connected to pin 9, but the digital servo isnt working. Also neither one will work when connected to the servo pins on the adafruit board.

You might want to run an I2C scanner to confirm the device address (SB 0x40) and that the device is communicating on the I2C bus.

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

This is what I got.

I thought that I saw a solder blob on the A0 address selection jumper. Change the I2C address in the sketch to 0x41.

Make it look like this:

// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// called this way, it uses the default address 0x40 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // you can also call it with a different address you want //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41

This is what my code looks like. Should the solder blob not be there?

I know that is how your code looks. The solder blob changes the address from the default (0x40) that is in your code to 0x41. You can either change your code to what I posted (set the address to 0x41) or un-solder the address jumper and leave the coded address at 0x40. Up to you. I would just change the address in the code.

Please post the latest version of your code if you make any changes.

I changed the code to match what you said. Still doesnt work

[u]Please post the latest version of your code if you make any changes.[/u].

Does the dust collector relay operate when it should? Does the serial output show the gate positions when a tool is turned on?

/*

This script was created by Bob Clagett for I Like To Make Stuff
For more projects, check out iliketomakestuff.com

Includes Modified version of “Measuring AC Current Using ACS712”
http://henrysbench.capnfatz.com/henrys-bench/arduino-current-measurements/acs712-arduino-ac-current-tutorial/

Parts of this sketch were taken from the keypad and servo sample sketches that comes with the keypad and servo libraries.

Uses GitHub - adafruit/Adafruit-PWM-Servo-Driver-Library: Adafruit PWM Servo Driver Library
*/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You’ll have to tweak them as necessary to match the servos you
// have!

// our servo # counter
uint8_t servoCount = 6;
uint8_t servonum = 0;

const int OPEN_ALL = 100;
const int CLOSE_ALL = 99;

boolean buttonTriggered = 0;
boolean powerDetected = 0;
boolean collectorIsOn = 0;
int DC_spindown = 3000;

const int NUMBER_OF_TOOLS = 3;
const int NUMBER_OF_GATES = 6;

String tools[NUMBER_OF_TOOLS] = {“Miter Saw”,“Table Saw”,“Band Saw”}; //, “Floor Sweep”
int voltSensor[NUMBER_OF_TOOLS] = {A1,A2,A3};
long int voltBaseline[NUMBER_OF_TOOLS] = {0,0,0};

//DC right, Y, miter, bandsaw, saw Y, tablesaw, floor sweep
//Set the throw of each gate separately, if needed
int gateMinMax[NUMBER_OF_GATES][2] = {
/open, close/
{250,415},//DC right
{230,405},//Y
{230,405},//miter
{285,425},//bandsaw
{250,405},//saw y
{250,415},//floor sweep
};

//keep track of gates to be toggled ON/OFF for each tool
int gates[NUMBER_OF_TOOLS][NUMBER_OF_GATES] = {
{1,0,1,0,0,0},
{1,1,0,0,1,1},
{1,1,0,1,0,0},
};

const int dustCollectionRelayPin = 11;
const int manualSwitchPin = 12; //for button activated gate, currently NOT implemented

int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
double ampThreshold = .20;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

//button debouncing
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin

// the follow variables are long’s because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers

void setup(){
Serial.begin(9600);
pinMode(dustCollectionRelayPin,OUTPUT);
pwm.begin();
pwm.setPWMFreq(60); // Default is 1000mS

//record baseline sensor settings
//currently unused, but could be used for voltage comparison if need be.
delay(1000);
for(int i=0;i<NUMBER_OF_TOOLS;i++){
pinMode(voltSensor*,INPUT);*
voltBaseline = analogRead(voltSensor*);*
* }*

}
void loop(){
* // use later for button debouncing*
* reading = digitalRead(manualSwitchPin);*
* if (reading == HIGH && previous == LOW && millis() - time > debounce) {*
* if (state == HIGH){*
* state = LOW;*
* buttonTriggered = false;*
* } else{*
* state = HIGH;*
* buttonTriggered = true;*
* time = millis(); *
* }*
* }*
* previous = reading;*
* Serial.println("----------");*
* //loop through tools and check*
* int activeTool = 50;// a number that will never happen*
* for(int i=0;i<NUMBER_OF_TOOLS;i++){
_ if( checkForAmperageChange(i)){
activeTool = i;
exit;
}
if( i!=0){
if(checkForAmperageChange(0)){
activeTool = 0;
exit;
}
}
}
if(activeTool != 50){
// use activeTool for gate processing*
* if(collectorIsOn == false){
//manage all gate positions*
* for(int s=0;s<NUMBER_OF_GATES;s++){*
* int pos = gates[activeTool];
~~ if(pos == 1){
openGate(s);
} else {
closeGate(s);
}
}
turnOnDustCollection();
}
} else{
if(collectorIsOn == true){_
delay(DC_spindown);
_
turnOffDustCollection();
}
}
}
boolean checkForAmperageChange(int which){
Voltage = getVPP(voltSensor[which]);*
VRMS = (Voltage/2.0) 0.707;
AmpsRMS = (VRMS * 1000)/mVperAmp;~~
~~ Serial.print(tools[which]+": “);
Serial.print(AmpsRMS);
Serial.println(” Amps RMS");
if(AmpsRMS>ampThreshold){
return true;
}else{
return false;
}
}
void turnOnDustCollection(){
Serial.println(“turnOnDustCollection”);
digitalWrite(dustCollectionRelayPin,1);
collectorIsOn = true;
}
void turnOffDustCollection(){
Serial.println(“turnOffDustCollection”);
digitalWrite(dustCollectionRelayPin,0);
collectorIsOn = false;
}~~*_

float getVPP(int sensor)
{
~~ float result;~~

~~ int readValue; //value read from the sensor~~
~~ int maxValue = 0; // store max value here~~
~~ int minValue = 1024; // store min value here~~

~~ uint32_t start_time = millis();~~
~~ while((millis()-start_time) < 500) //sample for 1 Sec~~
~~ {~~
~~ readValue = analogRead(sensor);~~
~~ // see if you have a new maxValue~~
~~ if (readValue > maxValue)~~
~~ {~~
~~ /record the maximum sensor value/~~
~~ maxValue = readValue;~~
~~ }~~
~~ if (readValue < minValue)~~
~~ {~~
~~ /record the maximum sensor value/~~
~~ minValue = readValue;~~
~~ }~~
~~ }~~

~~ // Subtract min from max~~
~~ result = ((maxValue - minValue) * 5.0)/1024.0;~~

~~ return result;~~
}
void closeGate(uint8_t num){
~~ Serial.print("closeGate ");~~
~~ Serial.println(num);~~
~~ pwm.setPWM(num, 0, gateMinMax[num][1]);~~
}
void openGate(uint8_t num){
~~ Serial.print("openGate ");~~
~~ Serial.println(num);~~
~~ pwm.setPWM(num, 0, gateMinMax[num][0]);~~
~~ delay(100);~~
~~ pwm.setPWM(num, 0, gateMinMax[num][0]-5);~~
}
The monitor is showing the dust collector coming on and going off but not the gates opening

Miter Saw: 9.60 Amps RMS Table Saw: 0.02 Amps RMS Miter Saw: 9.55 Amps RMS Band Saw: 0.02 Amps RMS Miter Saw: 9.51 Amps RMS openGate 0 closeGate 1 openGate 2 closeGate 3 closeGate 4 closeGate 5 turnOnDustCollection

It is showing it is opening the gate

// called this way, it uses the default address 0x40
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

The above was what I posted to change the I2C address.

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

Your code is not the same. You have used the default constructor which uses the default address, 0x40.

Please post code in code tags. Do you look at your posts after you send them?

Im missing something. I dont see the difference.

// called this way, it uses the default address 0x40 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // you can also call it with a different address you want //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);

I couldnt figure out what you are talking about so I unsoldered the jumper. Is this right?

To set the address to the default, yes. Did it work? Did you run the I2C scanner again to see if the address changed?

Yes. I ran the scanner again, but it still doesnt work

I2C scanner. Scanning ... Found address: 65 (0x41) Found address: 112 (0x70) Done. Found 2 device(s). This is what it shows now

I ran the adafruit servo test program and none of the servos are working

Found address: 65 (0x41)

The address of the servo shield is still 0x41. It appears the the blob removal was not effective.

Until you get the address in the code to match the address of the shield it won't work.