Hi Sara, hi Rui,
during the last few days I have been struggling with micropython and Thonny a lot. Based on the samples from the micropython book, I have managed to call openweather data and display it on a SSD1306 – 0.96 display selectively. This means, I have also added the button with the LED example to make sure I can call most recent / updated data from openweather.org
here is my setup:
Board: ESP32 DOIT DEVKIT V1
first I start the modified ssd1306 driver, I have added into it my network login credentials and verify correct log in. Then I start main.py which includes:
- button control
- OLED definitions
- variables plus open_weather call
- with a lot of if ..elif…else I display the following in micropython:
******************************************************************************************
Ready to download this file,please wait! ....................................................... download ok exec(open('main.py').read(),globals()) Connection successful ('192.168.178.64', '255.255.255.0', '192.168.178.1', '192.168.178.1') Location: Neuss - DE Description: Clear Temp: 9.14*C, Tendenz ↑ Pressure: 1024hPa, Tendenz ↑ Humidity: 58% kein Regen in der letzten Stunde der Wind kommt mit 2.1m/s aus: E Uhrzeit der Abfrage: 1586031840 Location: Neuss - DE Description: Clear Temp: 9.14*C, Tendenz → Pressure: 1024hPa, Tendenz → Humidity: 58% kein Regen in der letzten Stunde der Wind kommt mit 2.1m/s aus: E Uhrzeit der Abfrage: 1586031840 7 ******************************************************************************************
the second block appears after I pushed the button after 7 seconds. So far so good.
but this only works if the board stays connected to the PC and micropython remains active. I have tried to rename ssd1306.py to boot.py ( and changed the import call to boot instead of ssd1306), but that didn’t work,
Trying to use the working configuration with Thonny failed as thonny forgot the ssd1306 driver when I call main.py.
so here is my question:
do you know a setup / solution how the ESP32 plus the OLED, plus pushbutton can be used separated from the micropython software ? I would like to use the ESP32/openweather kit, without starting the PC.
Am I too critical or am I right in assuming that the ESP32 Board is a bit tricky. Please allow the comparison to a young horse: it is not easy to tame it but you can, in the end …
Looking forward to hearing your suggestions. In case you would like to see the two files, I have no problem sharing them with you in original form ( taking out my private data of course).
Please stay safe and enjoy the weekend. I am retired and have to stay at home, talking to the kids and grandchilden via facetime….
Last but not least, actually most of all, thank you for your great way of helping the community to understand this stuff.It is a fantastic hobby and I have managed to build quite some projects which I can use day by day.
Best regards
Jos Wich
Well, sleeping over it one night, to my surprise I see that the application is working independently from the PC. Something must have changed over night. But the result is all what counts.
Still, any suggetsions or comments are warmly welcomed
Jos
well, surprise, surprise….
after adding the wind speed in Km/h to the display message, I noticed that again the unit would not run without the PC, I was kinda lucky to copy my modified ssd1306.py to boot.py. When starting boot.py, an error message comes up afer loading: “ssd1306 not found”. Then loading ssd1306.py and subsequently main.py, everything runs perfectly.
As I said earlier:
Am I too critical or am I right in assuming that the ESP32 Board is a bit tricky. Please allow the comparison to a young horse: it is not easy to tame it but you can, in the end …
Good luck everybody and stay healthy !
Jos
for your reference, please have a look at the intermediate product:
https://drive.google.com/open?id=1KuiMLL3cKcRo0Cnn20vzkc4m9EsJawpZ
It still requires a housing from my 3D printer. Any comment always welcome !
Jos
Hi Jos.
Thanks for sharing your project with us.
Here’s what you should do when programming your boards with MicroPython using Thonny IDE.
- Upload all additional libraries to the board. In your case, it is the ssd1306 library.
- Ensure that the library files are actually saved on the ESP32 board.
- Upload the code to your board.
Upload a Library
1. Open a new file and copy the library code to the new file.
2. Save that file as ssd1306.py.
3. Go to Device > Upload current script with the current name
This uploads a file called ssd1306.py to the ESP32 board. So, you can check that the files are actually uploaded to your board by writing on the shell when there’s the >>.
%lsdevice
It should return the files saved on the ESP32.
Upload the Code to the Board
When you disconnect the ESP32 form your computer, it will run the boot.py file and then, the main.py file, where your main code should be.
If there isn’t any main.py file, the ESP32 will do nothing. For example, if you have your main code saved on the ESP32 on a file called example.py, it won’t run.
So, to make sure your code is uploaded to the board as main.py. You need to go to Device > Upload current script as main script.
After this, the code should be uploaded to the ESP32. You can check that using the %lsdevice command.
After uploading the code, you should press the ESP32 RST button, so that it starts running the code (if it is connected to your computer or from another power supply).
IMPORTANT NOTE: In Thonny IDE, there’s a green play button. That button runs the current code on the ESP32. It only runs the code, it doesn’t upload the code to the ESP32.
So, if you press that button, it works well when connected to the computer. But if you disconnect, it won’t work because it didn’t upload any file to the board.
I hope this is clear and that you can make it work. Then, give me some feedback.
Thanks for following and supporting our work.
Regards,
Sara
Hi Sara, thanks for your detailed reply. You really made me aware of how to ensure that the code remains on the board. Following your guidelines, it works well !
Still I have some comments:
I have Thonny in the version 3.2.7 running on my Win10 PC. Here some MicroPython commands have been moved or replaced. With your great explanation I now understand that in this version you have to Upload current script with ” …use current script as main/boot/current name (one of them) and then : use “File => Save copy …” to save the code to the board.
So in the end, it works fine, only a little different.
Oh, where have I turned wrong ? Your suggestion to use
>> %lsdevice
is answered with:
Unknown command: lsdevice
Looking forward to receiving your comments,
and please stay healthy
Jos
Hi Jos.
I’m happy that you understand and that you got it working.
I was using Thonny IDE version 3.1.2. And that command worked well.
I’ve updated to the most recent version and it seems that things are a little different now.
The code you want to run on the board should be saved with the main.py name and you should go to Save Copy as you mentioned.
To see the files that are saved on the device, go to View > Files and it should show the files saved on your board under “MicroPython device”.
I wasn’t aware that the IDE has changed so much since my oldest version.
I hope you understand.
Regards,
Sara