Restructure logic and test

This commit is contained in:
Skylar Grant 2024-08-18 12:31:29 -04:00
parent 09b524d35b
commit 170cbb7792
4 changed files with 80 additions and 107 deletions

View File

@ -41,16 +41,16 @@ This project seeks to replace the OEM control panel on a Lennox Winslow PS40 pel
# GPIO # GPIO
Three GPIO pins are used along with a common ground to control three relays, supplying 120VAC power to the igniter and combustion blower when appropriate, and supplying power to the auger motor in pulses. Two more GPIO pins are used to detect open/closed status of a temperature-controlled snap switch and a vacuum switch. Another temperature-controlled snap switch is used to supply power to the convection motor when the pellet stove has reached a suitable temperature. A final temperature-controlled snap switch us used to interrupt the circuit for the auger motor to shut the stove off when an over-temperature condition is met. I will be utilizing a OneWire DS18B20 temperature sensor to detect the temperature of air exiting the stove vents. Three GPIO pins are used along with a common ground to control three relays, supplying 120VAC power to the igniter and combustion blower when appropriate, and supplying power to the auger motor in pulses. Two more GPIO pins are used to detect open/closed status of a temperature-controlled snap switch and a vacuum switch. Another temperature-controlled snap switch is used to supply power to the convection motor when the pellet stove has reached a suitable temperature. A final temperature-controlled snap switch us used to interrupt the circuit for the auger motor to shut the stove off when an over-temperature condition is met. I will be utilizing a OneWire DS18B20 temperature sensor to detect the temperature of air exiting the stove vents.
| Pi Pin | Function | Direction | Wire Color | | Board Pin | BCM Pin | Function | Direction | Wire Color |
| ------:| -------- | --------- | ---------- | | ------:| -------- | -------- | --------- | ---------- |
7 | Auger Relay | Out | Blue 7 | 4 | Auger Relay | Out | Blue
13 | Igniter Relay | Out | Blue/White 13 | 27 | Igniter Relay | Out | Blue/White
15 | Combustion Blower Relay | Out | Orange 15 | 22 | Exhaust Relay | Out | Orange
16 | Proof of Fire Switch | In | Orange/White 16 | 23 | Proof of Fire Switch | In | Orange/White
18 | OneWire Temp Sensor | In | Brown ~~18~~ | ~~24~~ | ~~OneWire Temp Sensor~~ | ~~In~~ | ~~Brown~~
22 | Vacuum Switch | In | Brown/White 22 | 25 | Vacuum Switch | In | Brown/White
4 | +5VDC for Switches | N/A | Green 4 | N/A | +5VDC for Switches | N/A | Green
6 | GND for Relays | N/A | Green/White 6 | N/A | GND for Relays | N/A | Green/White
# Schematics # Schematics
## The Current Setup ## The Current Setup

View File

@ -0,0 +1,67 @@
const { exec } = require('child_process');
const pins = [
{ key: 'igniter', board: 13, bcm: 27, mode: 'OUT' },
{ key: 'exhaust', board: 15, bcm: 22, mode: 'OUT' },
{ key: 'auger', board: 7, bcm: 4, mode: 'OUT' },
{ key: 'pof', board: 16, bcm: 23, mode: 'IN' },
{ key: 'vacuum', board: 22, bcm: 25, mode: 'IN' }
];
pins.forEach(pin => {
console.log(`Key: ${pin.key}, Board: ${pin.board}, BCM: ${pin.bcm}, Mode: ${pin.mode}`);
});
// Function to toggle a pin on-then-off
function togglePin(pin, callback) {
exec(`python3 src/python/gpio_interface.py toggle ${pin}`, (error, stdout, stderr) => {
if (error) {
return callback(error);
}
if (stderr) {
return callback(new Error(stderr));
}
console.log(`Successfully toggled pin ${pin}`);
});
}
// Function to sense a pin state
function sensePin(pin, callback) {
exec(`python3 src/python/gpio_interface.py sense ${pin}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error sensing pin ${pin}: ${error.message}`);
return callback(error);
}
if (stderr) {
console.error(`Stderr while sensing pin ${pin}: ${stderr}`);
return callback(new Error(stderr));
}
console.log(`Pin ${pin} state: ${stdout.trim()}`);
callback(stdout.trim(), null);
});
}
// Toggle pins sequentially and then sense pin states
function debugInit() {
pins.forEach(async (pin) => {
switch (pin.mode) {
case 'OUT':
togglePin(pin.board, err => {
if (err) throw err;
});
// Wait 1000ms before toggling again.
setTimeout(togglePin(pin.board, err => {
if (err) throw err;
}), 1000);
break;
case 'IN':
sensePin(pin.board, (state, err) => {
if (err) throw err;
console.log(`${pin.key} state: ${state}`);
});
default:
break;
}
});
}

View File

@ -1,102 +1,8 @@
const { exec } = require('child_process'); // Import modules
import gpio from './custom_modules/VoidGPIO.js';
// List of pins for toggling // List of pins for toggling
const togglePins = [7, 13]; const togglePins = [7, 13];
// List of pins for sensing // List of pins for sensing
const sensePins = [16, 22]; const sensePins = [16, 22];
// Function to toggle a pin on-then-off
function togglePin(pin, callback) {
exec(`python3 src/python/gpio_interface.py toggle ${pin}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error toggling pin ${pin}: ${error.message}`);
return callback(error);
}
if (stderr) {
console.error(`Stderr while toggling pin ${pin}: ${stderr}`);
return callback(new Error(stderr));
}
console.log(`Successfully toggled pin ${pin}`);
// Wait for 1 second before turning it off
setTimeout(() => {
exec(`python3 src/python/gpio_interface.py toggle ${pin}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error turning off pin ${pin}: ${error.message}`);
return callback(error);
}
if (stderr) {
console.error(`Stderr while turning off pin ${pin}: ${stderr}`);
return callback(new Error(stderr));
}
console.log(`Successfully turned off pin ${pin}`);
callback(null);
});
}, 1000); // 1-second delay to ensure the pin is toggled
});
}
// Function to sense a pin state
function sensePin(pin, callback) {
exec(`python3 src/python/gpio_interface.py sense ${pin}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error sensing pin ${pin}: ${error.message}`);
return callback(error);
}
if (stderr) {
console.error(`Stderr while sensing pin ${pin}: ${stderr}`);
return callback(new Error(stderr));
}
console.log(`Pin ${pin} state: ${stdout.trim()}`);
callback(null);
});
}
// Toggle pins sequentially and then sense pin states
function controlPins() {
let index = 0;
// Toggle all pins
function toggleNextPin() {
if (index >= togglePins.length) {
console.log('All toggle pins processed.');
// Proceed to sensing pins
senseNextPin();
} else {
togglePin(togglePins[index], (err) => {
if (err) {
process.exit(1); // Exit with error
} else {
index++;
toggleNextPin();
}
});
}
}
// Sense all pins
function senseNextPin() {
index = 0;
function sensePinNext() {
if (index >= sensePins.length) {
console.log('All sense pins processed.');
process.exit(0); // Exit successfully
} else {
sensePin(sensePins[index], (err) => {
if (err) {
process.exit(1); // Exit with error
} else {
index++;
sensePinNext();
}
});
}
}
sensePinNext();
}
// Start with toggling pins
toggleNextPin();
}
// Start the process
controlPins();

View File

@ -2,7 +2,7 @@ import RPi.GPIO as GPIO
import sys import sys
import time import time
# Initialize GPIO # Initialize GPIO using Board mode for pin numbering
GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) GPIO.setwarnings(False)