micropython and esp32 in greenhouse

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
lazarvgd
Posts: 39
Joined: Sun May 20, 2018 8:57 am

micropython and esp32 in greenhouse

Post by lazarvgd » Tue Feb 25, 2020 6:53 am

Hello,

Probably this question is asked a few times, but I cannot find it with regular forum search, so I will ask it again. If you want please move/remove the question if ti violates some of the rules. :)

I would like to ask you guys, more experience, engineers for an advice using ESP32(or 8266) and micropython for greenhouse project. Since I am mobile engineer and I worked only with high level programming languages, but playing around with micrpython in free time, I still do not have enough knowledge to overcome every issue.

The questions:
1. I am curious how reliable is esp with micropython? Is it capable to withstand 24h/365 days checking of temperature, turning on/off some solid state relays and sending data over mqtt? Does anybody have experience in this field? Can I relay on the board and the language? What issues can I expect?

2. Multitasking with ESP8266 is it possible? I found that esp32 is capable doing multitasking, but esp8266 is single code, theoretically it should be able, but can you guys point me in right direction regarding this question?

3. Interfacing with i2c devices - I found that is possible to target i2c peripherals by giving the address, but how to read the address of the device? For example if display, rtc and one dht22 is connected to the board, how can I communicate with each of the device if I don't know the address? I am not sure did I explain the problem, but if you need more information, I will explain in details.

I hope that you will find time to help me out with this project. I will appreciate any help.
thanks :)

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: micropython and esp32 in greenhouse

Post by Roberthh » Tue Feb 25, 2020 7:21 am

My few cents about that:

0) Use an ESP32, not an ESP8266. The price difference is 0, but the ESP32's memory is way larger and offers more interfaces.

1) Micropython is pretty mature, the combination of ESP32 and Micropython is not 24/265 stable. Using a Pyboard V1.1 or Pyboard D is much more reliable.

2) There is no multitasking. You can use asyncio or threading. Asyncio is preferred.

3) The interface addresses of I2C devices are most of the time hardwired. And when not, a master can usually only select between a few hardwired choices. So the code has to know these.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: micropython and esp32 in greenhouse

Post by jimmo » Wed Feb 26, 2020 1:35 am

In addition to what Robert said, some extra notes:

"multitasking" is a bit of a vague term. To clarify -- the ESP32 hardware has two cores, but MicroPython only runs on one of them. It still supports threads though (via the "_thread" module) - so you can have multiple MicroPython threads running on that core. But just use asyncio, it's well worth the effort to learn and results in much simpler and more obviously correct code.

Two links that will be useful to you:
- https://github.com/peterhinch/micropython-mqtt
- https://github.com/peterhinch/micropyth ... UTORIAL.md

ALso with i2c -- you can use the follow code to discover the address of a device on the bus:

Code: Select all

import machine
i2c = machine.I2C('X')  # this is for pyboard, on ESP32 you'd write machine.I2C(sda=1, scl=2) (where 1 and 2 are your pin numbers)
print(i2c.scan())

Post Reply