logo elektroda
logo elektroda
X
logo elektroda

LoLin ESP8266 and MicroPython Quick Start.

TechEkspert 10104 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • LoLin ESP8266 and MicroPython Quick Start.
    It's worth watching gadgets elektroda.pl because once in a while there will be a LoLin module based on ESP8266. The module can be programmed with the use of Arduino, LUA, MicroPython, the module provides WiFi 802.11b / g / n connectivity, is equipped with a USB UART CH340 converter that allows you to put the code in flash memory (4MB). It is worth reading the previous materials about ESP8266:
    - installing drivers for the CH340 converter
    - Start with ESP8266, WIFI start, IoT with Blynk and Thingspeak, TMP36 temperature sensor, ESP.deepSleep deep sleep function ()
    - ESP8266 and DS18B20
    - ESP8266 and SPIFFS - flash file system

    LoLin ESP8266 and MicroPython
    ESP8266 integrates well with Arduino, but it is also worth trying other possibilities such as MicroPython.
    First, install the Python environment on the computer: https://www.python.org/downloads/
    Then, using the pip tool, we install esptool .
    I used Python 2.7.x but esptool is also compatible with Python 3.4 and above.
    If during the installation of Python we have configured the paths (you can check it by issuing the command echo% PATH%), just type in cmd the command:
    pip install esptool

    More information about the tool here: https://github.com/espressif/esptool
    After connecting ESP8266 and determining the port number on which the USB UART converter works, you can test the operation of esptool.
    For example for the COM15 port:
    esptool.py -p COM15 read_mac
    will allow you to read the MAC of the connected ESP8266
    esptool.py -p COM15 flash_id
    will show information about the module and the size of the flash memory.

    Of course, you replace COM15 with the actual port number on which the converter available on the board appeared,
    The baud rate can be set using the -b switch, e.g. 115200.

    We download and install the firmware as described:
    http://docs.micropython.org/en/latest/esp8266...66/tutorial/intro.html#deploying-the-firmware
    We choose the last stable firmware:
    http://micropython.org/download#esp8266

    Erasing the firmware:
    esptool.py -p COM15 erase_flash

    We put the new firmware:
    esptool.py -p COM15 write_flash --flash_size = detect 0 path and download_file_name.bin

    We should get a result similar to:
    Code: Text
    Log in, to see the code


    After these actions, by connecting to the speed 115200 using, for example, PuTTY to the COM port on which the converter connected to ESP8266 works, we get REPL (read-eval-print loop) which is the Python interpreter command line.
    We can test the operation by entering a code snippet:
    print ("Test")

    which will display the inscription:
    Test

    and then we introduce:
    import esp
    esp.check_fw ()
    which will check the integrity of the firmware.

    After installing new firmware ESP8266 works in WiFi AP mode, ESSID: MicroPython-xxxxxx where xxxxxx is replaced with MAC part of the device. The WiFi password is: micropythoN, module address: 192.168.4.1.

    More on using WiFi in MicroPython can be found here:
    https://docs.micropython.org/en/latest/esp8266/library/network.html

    We can easily scan available wireless networks nearby:
    Code: Python
    Log in, to see the code


    The way in which we can disable said built-in AP:
    Code: Python
    Log in, to see the code


    During the tests, I noticed a very high sensitivity of ESP in this module, it detected networks that were not seen by e.g. smartphones, it would probably not be possible to connect to these APs, but they were visible on the list.

    Buses and sensors in MicroPython
    In the online documentation you will find examples of I2C, SPI, DS18B20 temperature sensors:
    http://docs.micropython.org/en/latest/esp8266/esp8266/quickref.html

    Let's try a code that reads data from a sensor DTH22 , it can be compared with the code used to read the temperature and humidity on the Arduino platform:
    Arduino UNO and DTH22 .
    Remember to pull up the power supply through the ~ 5.1kom resistor of the AM2302 data sensor (unless it is in the form of a module and there is a resistor on the board connecting the data pin with vcc). We will use the D4 pin to communicate with DTH22, the sensor is connected to ground and the 3.3V power supply on the LoLin board. Pin D4 will correspond to GPIO2, e.g. here you can find pin assignments in typical ESP8266 modules: http://escapequotes.net/esp8266-wemos-d1-mini-pins-and-diagram/

    Code: Python
    Log in, to see the code


    Startup scripts
    Issuing commands to the serial console is a good way to test, but the target of the MicroPython code file will be in a file stored in flash memory. The startup files will allow the execution of specific code after the module is powered.

    It's worth getting a helpful tool called Adafruit ampy :
    https://github.com/adafruit/ampy

    Just like when installing esptool in cmd on PC, we issue the command:
    pip install adafruit-ampy

    We test:
    ampy -p COM15 ls
    We have various commands at our disposal: ls list files, get display a file, put put, and rm delete a file.

    There is a file in the flash memory boot.py performed after startup, let's see what its content is:
    ampy -p COM15 get boot.py

    We will get something like:
    Code: Text
    Log in, to see the code


    Let's create a file on the PC main.py which, when copied to flash on ESP8266, will run after each module is powered right after boot.py is done,
    for example, it will be a code in the loop reading temperature and humidity from the DTH22 sensor and displaying the data in the serial console.

    Code: Python
    Log in, to see the code


    We precede everything under "while True" with a tab.
    We save the file in a specific location on the PC.

    We put the file in flash memory:
    ampy -p COM15 put path \ main.py

    After restarting the module in the serial console, we will see the effect of main.py
    LoLin ESP8266 and MicroPython Quick Start.

    You can find many interesting examples of ESP8266 and MicroPython connection, e.g .:
    Weather station collecting data from the DTH22 sensor and the BMP180 pressure sensor.
    A weather station that downloads data from the internet.

    What ideas do you have for using MicroPython and LoLin board based on ESP8266?

    What kind of working environment with ESP8266 do you prefer MicroPython, Arduino or maybe LUA?


    LoLin ESP8266 and MicroPython Quick Start.
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
    About Author
    TechEkspert
    Editor
    Offline 
    TechEkspert wrote 6246 posts with rating 4908, helped 16 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #3 17049906
    Atreyu Makiavel
    Level 34  
    Brother irritates people with this. With some backtrack it broadcasts deauth and disconnects other devices or generates a lot of networks with the same SSID :-D
  • #4 17107167
    radogost-59
    Level 2  
    great, although I do not know why after connecting the DHT11 sensor, the read temperature is about 800 degrees C.
    and one more request - question: how to send it via wifi? (using microPython)
    Besides, thanks a lot - toturial helped me start my adventure with micropython and esp8266.
    I greet
    Leslaw
  • #5 17108950
    TechEkspert
    Editor
    @ radogost-59 DTH11 must be debugged at the software and hardware level where the error occurs,
    as for connecting to the internet via WiFi it is quite simple:
    http://docs.micropython.org/en/v1.9.3/esp8266/esp8266/tutorial/network_basics.html
    you can test directly from the REPL.

    If you manage to do something interesting on MicroPython, it is worth describing it on elektroda.pl, e.g. in DIY or articles.
  • ADVERTISEMENT
  • #6 17116476
    radogost-59
    Level 2  
    Hello
    thanks for the suggestions, but I edited the question incorrectly:
    In uPython, I wrote a program for measuring the temperature on the ds18b20 with an alarm function when a certain threshold is exceeded, the point is that now the data is sent automatically every 60 seconds, or at least information about the exceeded product. preferably in the form of a text message, or to another esp8266 module in any form.
    At this stage, I can communicate with the module via wifi and ask for it, but I don't know how to make the module send the message itself.
    (The point is that My Lady boils water very often in CO ...)
  • ADVERTISEMENT
  • #8 17561839
    Anonymous
    Level 1  

Topic summary

The discussion revolves around the LoLin ESP8266 module, which can be programmed using MicroPython, Arduino, and LUA. Users share ideas for applications, such as controlling robots and monitoring temperature with sensors like DHT11 and DS18B20. Issues encountered include incorrect temperature readings and the need for WiFi communication to send alerts. Solutions involve debugging sensor connections and utilizing platforms like Blynk and Thingspeak for notifications. The importance of installing the Python environment and using pip for package management is also highlighted.
Summary generated by the language model.
ADVERTISEMENT