Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Aussie_Barry
#61999 I have reformatted twice and and reflashed in both 2M and 4M builds - all with the same reboot problem.
Given the simplistic nature of the two programs I am running:

Code: Select all 
memclear
button "Load Toggle", [Toggle]
wait
[Toggle]
load "/toggle.bas"
wait

end


and

Code: Select alllet led_pin = 16
let led_state = 1
timer 1000, [toggle_led]
wait

[toggle_led]
if led_state = 1 then
    led_state = 0
else
    led_state = 1
end if
 
io(po, led_pin, led_state)
wait
end


I suspect that it is unlikely to be an out of memory issue - would you agree?
If not, how would you suggest that I go about reducing memory usage?

Cheers
Barry
VK2XBP
User avatar
By flywire
#62000 I have a Lolin NodeMcu V3 Dev Board flashed with ESP Basic 3.0.Alpha 66 (and a 4MB chip). Using Aussie_Barry's example I modified /toggle.bas line to 'let led_pin = 2' and ran it to confirm that it blinked the blue led.

When I run /load.bas the toggle.bas code never seems to finish loading:
Code: Select allLoading . . . . /toggle.bas

Aussie_Barry wrote:... Oldbod, would you please post your two working files so that I can try to emulate your success?
Also, what hardware are you using? I have a nodeMCU flashed at 4M with ESP Basic 3.0.Alpha 65

++1
User avatar
By Oldbod
#62006 This is default.bas....


Code: Select allmemclear
button "Load Toggle", [Toggle]
wait
[Toggle]
load "/blinker.bas"
wait

end


and this is blinker
Code: Select alllet led_pin = 16                     ' Assign onboard blue gpio16 to led
let led_state = 1
let loop_ct = 0                   ' Create a variable for remembering on/off condition of led
timer 1000, [toggle_led]             ' Set timed interrupt to periodically toggle led
wait

[toggle_led]
let loop_ct = loop_ct + 1
if loop_ct > 10 then load "/default.bas"
if led_state = 1 then
    led_state = 0
else
    led_state = 1
end if                               ' Toggles LED state
 
io(po, led_pin, led_state)
wait
end




I'm using a nodemcu 4M same as you, running rel 66 espbasic. i've not dug into the delays - but it does take a while to run it seems. Probably need to look into how basic loads a program.

Don't know what's causing your exception I'm afraid. not had this myself and I'm a real beginner with C++ - never even looked at it until I pulled the source for espbasic.
User avatar
By Electroguard
#62008 If reflash to 1Mb cured long-lasting 4Mb problems then common-sense logic says it was due either to previous corruption or lack of memory. Or perhaps there's been something else relevent that has not been noticed. One thing to be aware of is that if a different program gets loaded you are still only going to see the original if you browser back to the Edit window - you then need to click the Edit button to load the ESP's new script into the browser Edit window... which is something easily missed by anyone not looking.

But whatever your problems have been, I've included a pair of programs that are definitely working for me on both 1Mb and 4Mb builds... and I've included a 'tell-tale' so you'll know for sure if it's working for you.

*EDIT*
Yeah, lack of memory shouldn't be your problem. But bear in mind that unless you include a 'memclear' instruction in the loaded program(s), all previous variables will still exist and accululate - which besides eating up memory, can cause interpreter confusion from similarly named branches and vars. I don't know if the same applies to previous 'wait' type interrupt driven declarations such as timer etc, but it's an obvious likely cause of problems if so.
Interpreter problems typically cause a crash and reboot, and once things start getting out of control like that, don't be surprised if it results in a corrupted interpreter.

Code: Select all'/default.bas
memclear
button "Load Toggle", [Toggle]
wait

[Toggle]
load "/toggle.bas"
wait


Code: Select all'/toggle.bas
cls
print "toggle.bas is loaded and running *** Note: browser back then click Edit button to display it in browser ***"
led_pin = 16
led_state = 1
timer 500, [toggle_led]
wait

[toggle_led]
if led_state = 1 then led_state = 0 else led_state = 1
io(po, led_pin, led_state)
wait
Last edited by Electroguard on Sat Feb 04, 2017 7:27 am, edited 2 times in total.