Beginners Guide: Basic On NODEMCU/wifi dev board APR 6 2017
Posted: Sun Dec 06, 2015 7:28 pm
LAST UPDATE: 09-11-16
Other Important Documentation For ESPBASIC
mmiscool (Developer of Basic) Language Reference
Electrogaurds Driving Lessons
PhilTilson's Printable Documentation
NodeMCU/Basic Wifi Dev Board guide for MMISCOOL Basic IDE
---------------------------------------------------------------
Buy the Basic Wifi Dev Board: http://www.esp8266basic.com/store/p1/ES ... Board.html
with the Basic Wifi Dev Board there is no need to flash firmware the firmware is loaded right from the factory! if you need to keep costs down and wish to support espbasic by donation instead Purchase them from Here.
If you have a nodemcu read the following flashing steps.
FLASH THE NODE MCU WITH BASIC FIRMWARE:
Download the Basic Flasher Utility Latest Version: http://www.esp8266basic.com/download.html
Open the utility
Set your Com Port
Select 4MB Flash
Earlier than version 3.17
On Your NodeMCU Dev Board press and hold the flash button
keep holding the flash button and press the reset button for 2 seconds and let that go keep after an additional 2 seconds let go of the flash button.
Now on the flasher utility on your computer click the flash button if it synced right it will start to program if it syncs wrong it will give you an error.
At the end of flashing a screen will pop up with a bunch of .'s ....................................... like so just hit OK and you should be all setup.
Optionally you can watch this video:
EDIT 7-30-16
On version 3.17 and later now almost all bugs are worked out and there has been a ton of upgrades!!! I suggest you donate for all of these new features!!! Visit Hereand click the yellow donate button.
He makes it so easy now in version 3.17 you just hook up your nodemcu or espbasicdevkit and hit flash firmware button in the software and viola instantly starts flashing no holding down buttons or fumbling around just hit flash firmware and go! I donated a 20 spot with all the bugs nearly fixed and making my life way easier with hands free flashing it was worth the donation Be sure to grab the latest version and check it out!!!!
Wifi access point now also has MAC ID included so the wifi you connect to is not ESPXX:XX:XX:XX x's represent the macid of your device.
WPRINT BUG IS GONE!!! this is huge a big day for basic!!! now all html code works correctly!
Format flash works straight away it is a real format now. Basic has went from Zero to Hero overnight grab your copy of 3.17 and don't forget to donate!
7-30-16
If you are having trouble flashing or want to flash dual SPI aka DIO mode cause you did the dio mod to enable GPIO 9 and 10 as outputs check out these instructions:
get the latest bin file from github https://github.com/esp8266/Basic 4MB
use the espdownload tools http://www.electrodragon.com/w/ESP8266_ ... asher_Tool
Select the file bin file with the offset of 0x000000 as the starting address.
sync and program in the same manner. This should bring everything back to normal.
Alternate versions of this program can be found in this thread:
http://bbs.espressif.com/viewtopic.php?f=5&t=433
ACCESS THE BASIC IDE:
With anything that you have be it a Phone, Tablet, Laptop, etc that has wifi connect to your ESP device by scanning for your wifi connections available and connecting to the one labeled ESP. If you connect and disconnect constantly forget your other networks temporarily so you only connect to the ESP to get it up and running. Once connected open a web browser and visit the following web url http://192.168.4.1/settings . From here you can set the NodeMCU to connect to your wifi router by entering your wifi router SSID and Password in the supplied boxes. Be aware that this is now connected to the internet and should at this point be at the least secured with a password don't forget to save the settings and then click the update button to be sure you have the latest version!
URL's for the IDE
http://192.168.4.1/vars - this page holds all the variables and status of all the pins
http://192.168.4.1/edit - this page is the code editor from where you can write, save, open code
http://192.168.4.1/settings - this page holds settings for Station, AP, Interface, Updates, and formatting the device.
http://192.168.4.1/run - This link will run your code instantly after visiting the link
http://192.168.4.1/filemng - This link will take you to the file manager from where you can save files such as a webpage.
note 192.168.4.1 was used only as an example if you are in station mode aka connected to your router your IP will be different! Check your router device list or use Fing on your phone from playstore to find IP of ESP.
Static IP Connections
If you would like to connect with a static IP here is an example you must add this to your code.
You must change the info to reflect SSID PASS IP Gateway Subnet as shown above in that order.
UPDATE NOTICE: V3.8 allows you to configure a static ip right in the settings page!
UPDATES ARE NOW EASY !!!! OVER THE AIR (OTA) UPDATE DEC 25 2016 Merry Xmas!:
Use of 4MB flash will allow you now to do OTA (Over The Air) updates.
What this means is that you can now update Basic IDE over wifi no need to hook up to a PC!!!
Once flashed with basic you can update the dev kit without plugging it in at all!
For those unaware of OTA updates at current this allows you to upgrade firmware without the need to hook it up to a computer it basically downloads the update from the internet while in station mode and connected to a router that has internet access. So if you are in AP mode or an isolated router you can temporarily change your info to connect to an internet bound router and do your update and change your settings back as intended.
For those of you folks who really need OTA updates for the latest firmware I have setup a secondary update server for the time being.
Just add this info to the OTA box
note do not add http:// in front of the link as it will not work this way. Just copy and paste the link as is.
Then save settings
Then hit update.
I have v34 on there currently I may not get everything instantly or I may even miss a build or two but I will check back and update it periodically.
I know this works on nodemcu 4MB flash versions does it work on other smaller flashes or versions I am not sure to be honest have not tested this but their are folders for each version on the server just copy the link and give it a try and report back remember do not use the http:// in front of the link when pasting the link delete this portion.
I have tested it and has worked accurately for the last 6 builds roughly.
May be of use to someone may not who knows I found it rather useful myself so I figured I would share.
How will I know it has worked you say?
How you will know it works is once you click the update button there will be some time that will pass when trying to load the page and it will go offline and reset the unit once it comes back up you can visit the settings page and take note of how the version number has changed.
Enjoy
-forlotto
LOGIN CREDENTIALS UPDATE:
Login key no longer required as of 1.5.8 in the case that your password field is blank in the settings page as well.
HOW MANY LINES OF CODE CAN I USE?
No longer limited to 253 lines of code!!!! <---- NOW UPDATED 5000 lines of code are allowed !!! 5-2-2016
yes five thousand!
CODE SYNTAX NOTES:
- Code for esp8266 basic IS case SeNsiTive!!!
- When comparing to variables if var1 == var2 use two "=" signs.
- When comparing a variable and a value if var1 = 22 use a single "=" sign.
- Brackets don't have to be used onload for example onload mysubroutine will work just as onload [mysubroutine]
IMPORTANT IMPORTANT IMPORTANT BELOW as of 4-17-16
- VERSION 2 alpha 13 introduced a 10 character limit on variable names anything over will make your code DIE!
PINS USED IN BASIC:
See the image below:
For those curious here is how the code looks internally to make the pins easier to assign for the NODEMCU.
You could use the number or the board number when writing code so you have options! Above is a pin map if you will.
ADDRESSING PINS:
To address pins use the board number "D1"
TOGGLE PIN HIGH EXAMPLE:
TOGGLE PIN LOW EXAMPLE:
READ PIN EXAMPLE (NOTE SETS PIN AS INPUT)
WARNING WARNING WARNING if you are trying to monitor the status of a pin and constantly refresh it you must set up your own tracking variable when you change the pin status using po otherwise the value will remain static on the page.
Alternatively you can visit the vars page and it will tell you the status of each pin.
In the case of RX and TX printed on the NODEMCU BOARD:
you use them just as they are printed as well
Usage of these pins for ON/OFF is not recommended!
In the case of A0 it is only analog (Not to be used for on/off) so an example how to use it would be as follows:
PIN A0 EXAMPLE CODE:
The example above would print analog input.
NOTE: There is no pin number associated with A0 it is just ai !
On/Off Button Example:
SPECIAL NOTE: ON/OFF GPIO USE!!!
Avoid using D3 with relays as it will latch on at boot and your wifi will not connect until you remove the GPIO connection from the relay.
D8 Will also latch on and cause conflict do not use this.
D0 can be switched on to reset the device so if you are using an application where a reset may be helpful point to D0 and turn it on to reset the device.
D4 is tied to the LED light there is no conflict here though it is perfectly fine to use D4 for ON/OFF without issue!
This was tested without power applied to the relay board however once power is applied there may be just a quick on then off.
RX and TX should not be used for relays as well they are specific purpose.
GPIO 9 is fair game works for relays just fine I believe it must be flashed in DIO mode to use though!!!
GPIO 10 works on some models Amica models are the only models that I have tested and it works on must be flashed in DIO mode.
NOTE: To flash in DIO mode you must use the esp download tools from electrodragon to do the flashing.
Setting Pin As An Interrupt Example:
Interrupt notes:
Will execute a specific branch when a pins status changes. The interrupt polling only occurs when the esp is waiting and useful for things like push buttons trigger events. The branch must end with the wait command.
interrupt {pin no} {branch label}
to disable an interrupt specify no branch label.
interrupt {pin no}
LED based lighting Dimmer switch example:
I2C:
The I2C is on GPIO 0 or D3 and GPIO 2 or D4
1WIRE:
1wire is GPIO 2 or D4
Date & Timestamp Example UTC:
There is also the time set up function. This allows for setting the time zone and also can toggle daylight savings time.
To set the time zone to New York, (EST) you would use the following code. The 0 is to specify if daylight savings is to be activated. NOTE A DELAY IS A REQUIREMENT TO PROCESS THE TIMEZONE!!!!
IMPORTANT NOTES ON TIMER CODE!!!!!!!!!!!!!!! 4-17-16
old syntax
new syntax
- See more at: viewtopic.php?f=38&t=9428#sthash.0yvzRSzn.dpuf
HOW DO I USE THINGSPEAK?
First I would only request updates using thingspeak every 30seconds or so ... While there is a 15second delay that is required between requests using thingspeak servers. If you are dealing with critical "Real Time" events I would suggest you look not only into different software but also different hardware more capable of the job. 30 seconds is plenty of data for most applications likely even overkill weather data for instance a minute to minute is better than what some big box weather companies intervals between grabbing data ... So it is OVERKILL in a sense don't let common sense escape your project.
Example using the thingspeak api to do a really complicated hello world.
Twitter post using thingspeak example:
Other Important Documentation For ESPBASIC
mmiscool (Developer of Basic) Language Reference
Electrogaurds Driving Lessons
PhilTilson's Printable Documentation
NodeMCU/Basic Wifi Dev Board guide for MMISCOOL Basic IDE
---------------------------------------------------------------
Buy the Basic Wifi Dev Board: http://www.esp8266basic.com/store/p1/ES ... Board.html
with the Basic Wifi Dev Board there is no need to flash firmware the firmware is loaded right from the factory! if you need to keep costs down and wish to support espbasic by donation instead Purchase them from Here.
If you have a nodemcu read the following flashing steps.
FLASH THE NODE MCU WITH BASIC FIRMWARE:
Download the Basic Flasher Utility Latest Version: http://www.esp8266basic.com/download.html
Open the utility
Set your Com Port
Select 4MB Flash
Earlier than version 3.17
On Your NodeMCU Dev Board press and hold the flash button
keep holding the flash button and press the reset button for 2 seconds and let that go keep after an additional 2 seconds let go of the flash button.
Now on the flasher utility on your computer click the flash button if it synced right it will start to program if it syncs wrong it will give you an error.
At the end of flashing a screen will pop up with a bunch of .'s ....................................... like so just hit OK and you should be all setup.
Optionally you can watch this video:
EDIT 7-30-16
On version 3.17 and later now almost all bugs are worked out and there has been a ton of upgrades!!! I suggest you donate for all of these new features!!! Visit Hereand click the yellow donate button.
He makes it so easy now in version 3.17 you just hook up your nodemcu or espbasicdevkit and hit flash firmware button in the software and viola instantly starts flashing no holding down buttons or fumbling around just hit flash firmware and go! I donated a 20 spot with all the bugs nearly fixed and making my life way easier with hands free flashing it was worth the donation Be sure to grab the latest version and check it out!!!!
Wifi access point now also has MAC ID included so the wifi you connect to is not ESPXX:XX:XX:XX x's represent the macid of your device.
WPRINT BUG IS GONE!!! this is huge a big day for basic!!! now all html code works correctly!
Format flash works straight away it is a real format now. Basic has went from Zero to Hero overnight grab your copy of 3.17 and don't forget to donate!
7-30-16
If you are having trouble flashing or want to flash dual SPI aka DIO mode cause you did the dio mod to enable GPIO 9 and 10 as outputs check out these instructions:
get the latest bin file from github https://github.com/esp8266/Basic 4MB
use the espdownload tools http://www.electrodragon.com/w/ESP8266_ ... asher_Tool
Select the file bin file with the offset of 0x000000 as the starting address.
sync and program in the same manner. This should bring everything back to normal.
Alternate versions of this program can be found in this thread:
http://bbs.espressif.com/viewtopic.php?f=5&t=433
ACCESS THE BASIC IDE:
With anything that you have be it a Phone, Tablet, Laptop, etc that has wifi connect to your ESP device by scanning for your wifi connections available and connecting to the one labeled ESP. If you connect and disconnect constantly forget your other networks temporarily so you only connect to the ESP to get it up and running. Once connected open a web browser and visit the following web url http://192.168.4.1/settings . From here you can set the NodeMCU to connect to your wifi router by entering your wifi router SSID and Password in the supplied boxes. Be aware that this is now connected to the internet and should at this point be at the least secured with a password don't forget to save the settings and then click the update button to be sure you have the latest version!
URL's for the IDE
http://192.168.4.1/vars - this page holds all the variables and status of all the pins
http://192.168.4.1/edit - this page is the code editor from where you can write, save, open code
http://192.168.4.1/settings - this page holds settings for Station, AP, Interface, Updates, and formatting the device.
http://192.168.4.1/run - This link will run your code instantly after visiting the link
http://192.168.4.1/filemng - This link will take you to the file manager from where you can save files such as a webpage.
note 192.168.4.1 was used only as an example if you are in station mode aka connected to your router your IP will be different! Check your router device list or use Fing on your phone from playstore to find IP of ESP.
Static IP Connections
If you would like to connect with a static IP here is an example you must add this to your code.
Code: Select all
connect "networkName" "Password" "172.16.0.35" "172.16.0.1" "255.255.255.0"
You must change the info to reflect SSID PASS IP Gateway Subnet as shown above in that order.
UPDATE NOTICE: V3.8 allows you to configure a static ip right in the settings page!
UPDATES ARE NOW EASY !!!! OVER THE AIR (OTA) UPDATE DEC 25 2016 Merry Xmas!:
Use of 4MB flash will allow you now to do OTA (Over The Air) updates.
What this means is that you can now update Basic IDE over wifi no need to hook up to a PC!!!
Once flashed with basic you can update the dev kit without plugging it in at all!
For those unaware of OTA updates at current this allows you to upgrade firmware without the need to hook it up to a computer it basically downloads the update from the internet while in station mode and connected to a router that has internet access. So if you are in AP mode or an isolated router you can temporarily change your info to connect to an internet bound router and do your update and change your settings back as intended.
For those of you folks who really need OTA updates for the latest firmware I have setup a secondary update server for the time being.
Just add this info to the OTA box
Code: Select all
cloudwire.tk/ESP8266Basic.cpp.bin
note do not add http:// in front of the link as it will not work this way. Just copy and paste the link as is.
Then save settings
Then hit update.
I have v34 on there currently I may not get everything instantly or I may even miss a build or two but I will check back and update it periodically.
I know this works on nodemcu 4MB flash versions does it work on other smaller flashes or versions I am not sure to be honest have not tested this but their are folders for each version on the server just copy the link and give it a try and report back remember do not use the http:// in front of the link when pasting the link delete this portion.
I have tested it and has worked accurately for the last 6 builds roughly.
May be of use to someone may not who knows I found it rather useful myself so I figured I would share.
How will I know it has worked you say?
How you will know it works is once you click the update button there will be some time that will pass when trying to load the page and it will go offline and reset the unit once it comes back up you can visit the settings page and take note of how the version number has changed.
Enjoy
-forlotto
LOGIN CREDENTIALS UPDATE:
Login key no longer required as of 1.5.8 in the case that your password field is blank in the settings page as well.
HOW MANY LINES OF CODE CAN I USE?
No longer limited to 253 lines of code!!!! <---- NOW UPDATED 5000 lines of code are allowed !!! 5-2-2016
yes five thousand!
CODE SYNTAX NOTES:
- Code for esp8266 basic IS case SeNsiTive!!!
- When comparing to variables if var1 == var2 use two "=" signs.
- When comparing a variable and a value if var1 = 22 use a single "=" sign.
- Brackets don't have to be used onload for example onload mysubroutine will work just as onload [mysubroutine]
IMPORTANT IMPORTANT IMPORTANT BELOW as of 4-17-16
- VERSION 2 alpha 13 introduced a 10 character limit on variable names anything over will make your code DIE!
PINS USED IN BASIC:
See the image below:
For those curious here is how the code looks internally to make the pins easier to assign for the NODEMCU.
Code: Select all
if (PinDesignaor == "D0") pin = 16;
if (PinDesignaor == "D1") pin = 5;
if (PinDesignaor == "D2") pin = 4;
if (PinDesignaor == "D3") pin = 0;
if (PinDesignaor == "D4") pin = 2;
if (PinDesignaor == "D5") pin = 14;
if (PinDesignaor == "D6") pin = 12;
if (PinDesignaor == "D7") pin = 13;
if (PinDesignaor == "D8") pin = 15;
if (PinDesignaor == "RX") pin = 3;
if (PinDesignaor == "TX") pin = 1;
NOT ADDED YET: but you can use the actual numbers 9 or 10 in place of SD2 and SD3 respectively
if (PinDesignaor == "SD2" pin = 9;
if (PinDesignaor == "SD3" pin = 10;
Not all versions of the nodemcu and wifi dev kit will allow for pin9 to be used properly as a GPIO for on/off function there is a modification that is done on some boards that allows pin 9 to be used in DIO mode...
In order to use GPIO 9 and 10 you will need to flash basic to your nodemcu in DIO mode using flashdownload tools pin 10 does however work well on most every unit I checked if flashed in DIO mode but they are useable pins depending on the hardware. Only way to know if you try but they are useful and useable keep this in mind!
You could use the number or the board number when writing code so you have options! Above is a pin map if you will.
ADDRESSING PINS:
To address pins use the board number "D1"
TOGGLE PIN HIGH EXAMPLE:
Code: Select all
io(po,D1,1)
TOGGLE PIN LOW EXAMPLE:
Code: Select all
io(po,D1,0)
READ PIN EXAMPLE (NOTE SETS PIN AS INPUT)
Code: Select all
if io(pi,D1) = 1 then print "Pin high" else print "pin low"
WARNING WARNING WARNING if you are trying to monitor the status of a pin and constantly refresh it you must set up your own tracking variable when you change the pin status using po otherwise the value will remain static on the page.
Alternatively you can visit the vars page and it will tell you the status of each pin.
In the case of RX and TX printed on the NODEMCU BOARD:
you use them just as they are printed as well
Usage of these pins for ON/OFF is not recommended!
In the case of A0 it is only analog (Not to be used for on/off) so an example how to use it would be as follows:
PIN A0 EXAMPLE CODE:
Code: Select all
ai bla
print bla
The example above would print analog input.
NOTE: There is no pin number associated with A0 it is just ai !
On/Off Button Example:
Code: Select all
Button "On" [on]
Button "Off" [off]
Wait
[on]
io(po,D1,1)
Wait
[off]
io(po,D1,0)
Wait
SPECIAL NOTE: ON/OFF GPIO USE!!!
Avoid using D3 with relays as it will latch on at boot and your wifi will not connect until you remove the GPIO connection from the relay.
D8 Will also latch on and cause conflict do not use this.
D0 can be switched on to reset the device so if you are using an application where a reset may be helpful point to D0 and turn it on to reset the device.
D4 is tied to the LED light there is no conflict here though it is perfectly fine to use D4 for ON/OFF without issue!
This was tested without power applied to the relay board however once power is applied there may be just a quick on then off.
RX and TX should not be used for relays as well they are specific purpose.
GPIO 9 is fair game works for relays just fine I believe it must be flashed in DIO mode to use though!!!
GPIO 10 works on some models Amica models are the only models that I have tested and it works on must be flashed in DIO mode.
NOTE: To flash in DIO mode you must use the esp download tools from electrodragon to do the flashing.
Setting Pin As An Interrupt Example:
Code: Select all
interrupt 0, [test]
wait
[test]
po d4 io(pi,0,)
print "It was triggered"
wait
Interrupt notes:
Will execute a specific branch when a pins status changes. The interrupt polling only occurs when the esp is waiting and useful for things like push buttons trigger events. The branch must end with the wait command.
interrupt {pin no} {branch label}
to disable an interrupt specify no branch label.
interrupt {pin no}
LED based lighting Dimmer switch example:
Code: Select all
lightLevel = 0
slider lightLevel 0 1023
button "Set Light" [setLight]
wait
[setLight]
pwo D4 lightLevel
wait
I2C:
The I2C is on GPIO 0 or D3 and GPIO 2 or D4
1WIRE:
1wire is GPIO 2 or D4
UPDATED 11-23-15 (Yes the same GPIO as the I2C rotohammer integrated without issue so far...)
Date & Timestamp Example UTC:
Code: Select all
print time()
There is also the time set up function. This allows for setting the time zone and also can toggle daylight savings time.
To set the time zone to New York, (EST) you would use the following code. The 0 is to specify if daylight savings is to be activated. NOTE A DELAY IS A REQUIREMENT TO PROCESS THE TIMEZONE!!!!
Code: Select all
timesetup(-3,0)
delay 5000
print time()
end
IMPORTANT NOTES ON TIMER CODE!!!!!!!!!!!!!!! 4-17-16
old syntax
Code: Select all
timer 10000 [branch]
new syntax
Code: Select all
timer 10000, [branch]
- See more at: viewtopic.php?f=38&t=9428#sthash.0yvzRSzn.dpuf
HOW DO I USE THINGSPEAK?
First I would only request updates using thingspeak every 30seconds or so ... While there is a 15second delay that is required between requests using thingspeak servers. If you are dealing with critical "Real Time" events I would suggest you look not only into different software but also different hardware more capable of the job. 30 seconds is plenty of data for most applications likely even overkill weather data for instance a minute to minute is better than what some big box weather companies intervals between grabbing data ... So it is OVERKILL in a sense don't let common sense escape your project.
Example using the thingspeak api to do a really complicated hello world.
Code: Select all
sendts(5C1J2FHRGQM44M7R,1,"HELLO WORLD FROM ESP8266 BASIC")
print readts(5C1J2FHRGQM44M7R,67698,1)
Twitter post using thingspeak example:
Code: Select all
TOP
cls
Textbox MyData
button "Click to send " [postit]
wait
'
[postit]
OPString = "api.thingspeak.com/apps/thingtweet/1/statuses/update?api_key={my API key}&status=" & MyData
print wget(OPString)
wait
goto TOP