An archive of community.esquilo.io as of Saturday January 26, 2019.

Newbe help with Squirrel

d.tkach

Hello, Im new to the Esquilo air and Squirrel and would like to know where to go for a few sample programs. I need to cycle a solenoid x times. Thanks David

softwarejanitor

You might try something like this:

//
// Simple Solenoid class for Esquilo
//
class Solenoid
{
    solenoid_A_Pin = 0;
    solenoid_B_Pin = 0;

    cycleDelay = 0;
    fillDelay = 0;

    constructor (_A_Pin, _B_Pin)
    {
        solenoid_A_Pin = GPIO(A_Pin);
        solenoid_B_Pin = GPIO(A_Pin);

        cycleDelay = 10000;
        fillDelay = 500;

        solenoid_A_Pin.output();
        solenoid_B_Pin.output();
    }
}

function Solenoid::setCycleDelay(cd)
{
    cycleDelay = cd;
}

function Solenoid::setFillDelay(fd)
{
    fillDelay = fd;
}

function Solenoid::resetSolenoid()
{
    print("Resetting solenoids...");
    solenoid_A_Pin.low();
    solenoid_B_Pin.high();
    delay(fillDelay);
    solenoid_B_Pin.low();
    print("done\n");
    local i;
    for (i = 5; i > 0; i--) {
        print("Beginning in " + i + " seconds...\n");
        delay(1000);
    }
}

function Solenoid::fireSolenoid()
{
    print("Firing...");
    solenoid_A_Pin.high();
    delay(fillDelay);  // Hold in-valve open for fillDelay
    solenoid_A_Pin.low();
    delay(fillDelay);  // Hold in-valve closed for fillDelay
    print("done\n");
    delay(cycleDelay);  // Wait cycleDelay
}

function Solenoid::retractSolenoid()
{
    print("Retracting...");
    solenoid_B_Pin.high();
    delay(fillDelay);  // Hold out-valve open for fillDelay
    solenoid_B_Pin.low();
    delay(fillDelay);  // Hold out-valve closed for fillDelay
    print("done\n");
    delay(cycleDelay);  // Wait cycleDelay
}


//
// Simple Solenoid Demo
//

require("GPIO");

// Load the libary.
dofile("sd:/Solenoid.nut");

// Instantiate our object.
local mySolenoid = Solenoid(6, 7);

local x = 5;

local l;

resetSolenoid();

for (l = 0; l < 5; l++) {
   fireSolenoid();
   retractSolenoid();
}
softwarejanitor

I hope that helps... I don't have an Esquilo handy to test it, and you may need to adjust the parameters a little to fit your particular solenoid but it should at least be close. I translated some sample code I found onine from C to Squirrel and made it into a class and demo program. Save the first part in something like Solenoid.nut and the last bit in Solenoid_demo.nut and then run Solenoid_demo.nut

softwarejanitor

I'd be interested to hear if that worked for you or even pointed you in the right direction.

d.tkach

Thanks Im working in that direction I will let you know!!!!