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

Esquilo IDE - running nuts

JefferyS

Hello, I have a while loop that I'm running in the IDE manually. It stops after one loop, does the IDE only let it loop once and I have to run it at boot to get it to continually run?

// Required Libraries
require("UART");

dofile("sd:/HighTemperatureSensor/LcdDisplay.nut");
//dofile("sd:/HighTemperatureSensor/TempButton.nut");
dofile("sd:/HighTemperatureSensor/TempProbe.nut");

while (true){
// Read the current temperature
temp1 <- sensor1.readT();
temp1 <- ((temp1 * 9) / 5) + 32; 

temp2 <- sensor2.readT();
temp2 <- ((temp2 * 9) / 5) + 32; 

// Initialize the 16x2 serial LCD using UART0 and PWM0 channels 0 - 2
    lcd<-Lcd(20, 4 UART(0));
    lcd.on();

    lcd.print("Temp 1: " + temp1);
    lcd.print("\n");
    lcd.print("Temp 2: " + temp2);

    delay(1000);
    lcd.clear();
}

On side note, the while loop seemed to stop my disconnect problem. Not sure why but now I can make changes and run the nut again without it disconnecting.

Thanks,

Jeffery

Scott_Shumate

It should loop continuously in both the IDE and at boot. It should only stop in the IDE if you press the kill or stop buttons.

I do see one thing suspicious in your code snippet:

There should probably be a comma after the 4:

lcd <- Lcd(20, 4, UART(0));

It could be that the nut is throwing an exception at that line which is why it's not looping. I would also suggest putting that line outside the while() loop so you're not creating the objects over and over.

JefferyS

Yes, that was it, Thanks a lot Scott. Thanks for pointing out the placement of the lcd lines too.

I wasn't getting any exceptions that I could see.

I wonder if that is why I was getting disconnected too. Have to test that out.

Thanks,

Jeffery

JefferyS

Hi, having another problem. I have the temp displayed on my LCD and it works great. I also have a web page that displays the Temp and it works great.

The problem is I can't seem to get them to work at the same time.

I put both nuts in the boot.nut file, even swapped the order but still didn't work on both.

I tried putting the RPC function in the nut that has the LCD code and get nothing from it either.

I thought having two nuts getting the temperature from the DS18B20s was causing problems.

I tried to use the RPC error to see if I could get an Idea of what is happening but couldn't tell if I set it up wrong or if the message was real. Said Unknown Method.

I think it would be better to have the RPC function in the LCD nut as I'm already getting the temp and can just pass back the values without having to get the temp from the probe again.

Any help would be most appreciated. I can send files if you want them.

Also, after I moved the LCD code outside the while loop I started getting disconnected again.

Thanks,

Jeffery

Scott_Shumate

Are you using dofile() with your two nuts in the boot.nut or did you copy and paste the code directly into the boot.nut? There should be no problem doing what you described. If you are using dofile(), try putting a delay(2000) first to give Esquilo time to mount the SD card.

You don't have to worry about threading issues in Esquilo because both the nut and RPC run from the same thread. You have to call delay() at some point in your main nut to give RPC a chance to run.

An "unknown method" means that the RPC function is not know to the Squirrel VM which indicates that the code did not run.

For the disconnect issue, I'm guessing that the Squirrel compiler is crashing on a specific code error in the nut instead of throwing an exception. I've fixed a couple of issues like that in the compiler already. That would explain the lack of running and disconnect. If you can e-mail me your code, it would help me to fix it. scott at esquilo.io

JefferyS

Thanks a whole lot Scott, the delay worked great. Have both the LCD and Webpage updating the temperature.

I've sent you an email with my files. I hope it helps you find the problem.

Thanks,

Jeffery

JefferyS

Hi Scott, was you ever able to find the problem that I get Disconnected all the time?

Thanks,

Jeffery

Scott_Shumate

Yes, that issue should be fixed. It had to do with a double free of a resource in the UART driver potentially causing the Squirrel VM to crash. The fix will be in the next version of EOS.

JefferyS

That's awesome Scott, can't wait. It is really slowing me down having to power off then on to run the program again after a change.

Jeffery