• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Questions/Comments about the micropyton book

Q&A Forum › Category: ESP8266 › Questions/Comments about the micropyton book
0 Vote Up Vote Down
Eric Herrmann asked 3 years ago

Hello!
I am currently following the micropython book content along with a NodeMCU ESP8266.
Again this is a fantastic course you’ve been providing us (I’ve got almost all of them 🙂 )
I just have a couple of questions and remark.
First remark is that I was struggling with simply changing the state of the built in led and after searching other resources on the internet I learned that the GPIO2 is working the other way around compared to others GPIO meaning that by default it is initialized with status 1 instead of 0 because this is needed when the ESP is booting up. Consequently you have to swap all .on() and .off (or 0/1 or True/False) statements whenever you want to turn the led on or off.
Maybe this is something you should point out in the book as it might be very confusing for beginners (and no luck this is the first experiment, not a good start if you don’t understand this 🙂 )
Then I have a couple of questions for you 🙂

  1. I am currently on the DHT11/DHT22 tutorial and I am just wondering whether it would be possible to auto refresh the web page displaying the 2 graphs with Temp and Hum…? This would be more elegant than having to manually refresh the page.
  2. I am very very bad at designing UIs / Web pages (and therefore I must admit I don’t like it very much as I don’t find it very interesting). Is there any WYSIWYG tool that could produce the HTML/JavaScript/CSS for me and I just have to set all buttons, sliders etc with drag and drop. Maybe not the JavaScript part but at least HTML / CSS?
  3. I am still struggling understanding the variable scope in Python (I am much more familiar with C) . At one point you mentioned a variable must be global so that we can use it everywhere in the code but I also see that when you define a (not global) variable in boot.py (like ‘led’ in the Web server examples) it is also usable in main.py therefore I don’t really understand the concept of variable scope

Thanks a lot!
Eric

Question Tags: micropython ESP8266
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
Yes, you are right about the built-in LED on the ESP8266. That info should definitely be added to the eBook.

1) The easiest way to do that without having to change a lot of things is by adding the following tag to the head of the HTML file:

<meta http-equiv="refresh" content="30">

See: https://www.w3schools.com/tags/att_meta_http_equiv.asp
This will automatically refresh the web page every 30 seconds.
A more elegant solution would be using server-sent events to update the readings without the need to refresh, but I haven’t searched how to do this in MicroPython.

2) I’m not familiar with any software that does that. If you find something, please share it.

3) Why do you say the variable defined in boot.py is not global? You can think of the main.py file as an extension of the boot.py file. As if the instructions were on the same file. I think the following link explains briefly and simply python’s variables scope: https://www.w3schools.com/python/python_scope.asp

I hope this helps.

Regards,
Sara

0 Vote Up Vote Down
Eric Herrmann answered 3 years ago

Hi Sara,
Thank you very much for your time answering my questions!
Regarding 3) ok now I think I understand. You must define a variable with ‘global’ only if the variable is part of a function and you want to make visible globally, throughout your code, right?
I understand then if the variable is defined outside a function then it is global.
For me the tricky point to understand with Python compared to C is when you have multiple files making up your project. 
If I undertand correcly, any variable declared outside a function in any .py file will be seen as a global variable in any others .py files part of the project, right?
Thanks!
Eric

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
First question: Yes, that’s true about global variables.
Sedond question: That’s true for micropython with main.py and boot.py. With other python files, you would need to import the file as a module to access the variables.
Regards,
Sara

0 Vote Up Vote Down
Eric Herrmann answered 3 years ago

Thanks Sara this is all clear now!

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Great!
I’ll close this issue.
If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.