News:

We're live! Join us!

Main Menu

Micropython & ESP32 internet radio

Started by Jeff_T, Feb 28, 2024, 10:13 PM

Previous topic - Next topic

Jeff_T

I'm glad you posted the Arduino example Chris I was impressed you got an example to show so quickly.

Like I said I'll try and make a video too, I need to work quickly as my computer access is going to be severely restricted on Monday and Tuesday.

Chris Savage

Quote from: Jeff_T on Apr 20, 2024, 02:14 PMI'm glad you posted the Arduino example Chris I was impressed you got an example to show so quickly.

Like I said I'll try and make a video too, I need to work quickly as my computer access is going to be severely restricted on Monday and Tuesday.

A video would be awesome. I found myself a bit confused at a few points while trying to save the code for this project.

        I'm only responsible for what I say, not what you understand.

Jeff_T

Hi Chris, there is a video on "A little fun with displays" @ https://savagechats.com/index.php?topic=133.0

I also modified the original post of that thread to fall in line with what I was trying to put across, the driver in that post inherits from the framebuffer so will accept any commands the framebuffer does.

You can see the effect this has in the test code just make sure to call the driver file "sc_ST7735.py"

Initially those two files will be enough to give you a feel for the drivers capability.

The video is actually about a different subject but it gives a pretty clear view of navigating Thonny and uploading files to the ESP32.

Of course you will need Micropython firmware on your controller and the instructions are at https://docs.arduino.cc/micropython/basics/board-installation/

I saw your post about the Canakit, you have some great toys, I believe Thonny is part of pios so this little demo should help you get the feel for Thonny if you decide to go that way with the rasberry pi


Chris Savage

I saw the display video, but in this thread I went to save the code for Part 1, but as I went down I missed something the first time when adding the individual blocks of code to the channels.py.

When I got to Part 2, I realized I was going to be modifying original source, so I ended up copying that code into a Part 1 directory and starting over from copies in a Part 2 folder.

But then I had a bigger question. You mentioned adding individual pieces of code to the microcontroller, but for me and the 7 languages I know, that is atypical of how things usually work, so I felt like I missed something.

Normally, a main program with imports would compile everything together into one binary that is downloaded to the MCU. Once downloaded, that code would then be acted upon. In this cade, it seems we're downloading individual source files onto the microcontroller and then running a specific file.

I'm not sure how that is done. I will have to take a closer look at things, possibly a tutorial video for Thonny. I've just never worked with a system that dealt with individual files on the target controller. It is a very different paradigm for me. Perhaps we should chat some time.

Also, something to consider...when explaining code in a post, using the code blocks is very beneficial and a proper thing to do. However, you can also attach a ZIP file of the code at the end of the message for those who want to save the original files.

        I'm only responsible for what I say, not what you understand.

Jeff_T

Hi Chris, I agree Micropython is different, the modules which could be considered libraries in some cases are in our case just regular ".py" files.

This has benefits and writing your own "include" file is quite easy. When it comes to the display driver that is a simple Class and has to follow a few different set of rules.

So there are micropython modules that come with the firmware and it's enough to just import them at the head of the main file, files that you create have to be present on the flash of the microcontroller so that the main file can access them. The image files I would lean toward SD storage for those but for the example the flash is fine.

The test file in the demo is run from the IDE again just for example purposes. When you have finally developed a program you obviously don't want to run it from the IDE so you call it "main.py". A "main.py" file will run automatically on power up.

I can produce any kind of video the ones I have posted so far have been generic so if you could give an example of what would be most beneficial let me know that goes for any other interested party, I would like to see us all on the same page.

Chris Savage

#20
My problem is two-fold...first of all, I used to get ESP32 boards sent to me ALL THE TIME back when I had 1500 members on the original Savage///Circuits website and Twitter. Most of those members / followers were companies interested in my reviews, etc.

Every MSP board and ESP board was given away either in the monthly giveaway or TFOTTPB. I never gave python a second thought until the Raspberry Pi became popular. However, the version of python I used on the R-Pi was actually called Scratch. It was much like Blockly on the Propeller. When compiled, the code was converted to python, but I never really looked at the output.

Tonight I was looking at some examples for my board using MicroPython and one example in particular involved the following code to simply blink the on-board LED.

import machine
import time

led = machine.Pin(2, machine.Pin.OUT)

while True:
    led.value(1)
    time.sleep(1)
    led.value(0)
    time.sleep(1)

Like the person who posted this, I too was confused. No LED came on or started blinking. Then I saw some of the replies, and a light bulb came on once I saw this diagram.

You cannot view this attachment.

After looking at some of the MicroPython docs on the hardware (machine), I came up with this sample that blinks the LED 10 times and, after adjusting the pin number, it works!

from machine import Pin
from time import sleep

led = Pin(48, Pin.OUT)

for _ in range(10):
    led.value(1)
    sleep(1)
    led.value(0)
    sleep(1)

I now understand what you meant with the multiple files being on the ESP32. The IDE asks me if I want to save to PC or MCU. When I select OPEN, it shows me the files on the MCU. Took me getting used to the architecture.


        I'm only responsible for what I say, not what you understand.

Jeff_T

Hi Chris, I was so glad to see this post, it's a great starting place.

I have heard of Scratch but never used it, do you have Thonny installed?

The pinout diagram is essential, every darn ESP varies in some way.

You can see a few of the basic and most often used methods in your sketch, you have two firmware module imports from which you are using two objects/methods then you create a variable assigned to a Pin set as output after that there is the for loop and led control. I'm guessing you called your sketch main because it started at reset. Every sketch is similar they just get bigger.

Let me know if I can help in any way and yes I am always open for a call if you want to do that at some time


Chris Savage

#22
Quote from: Jeff_T on Apr 23, 2024, 01:55 PMHi Chris, I was so glad to see this post, it's a great starting place. I have heard of Scratch but never used it, do you have Thonny installed? The pinout diagram is essential, every darn ESP varies in some way. Let me know if I can help in any way and yes I am always open for a call if you want to do that at some time

Yeah, Scratch made it easy for me to quickly print a message on an LCD Module from a Raspberry Pi, which is what I was trying to do at the time.

I do have Thonny installed. It's what I used to write the code for the ESP32 Module. Between the pinout guide and understanding the architecture of an ESP32 a little better, I think things will go more quickly from here on.

We should totally have a call sometime. DM me when a good time is and I will reply back with my number. Also, I am on the east coast now (again).

        I'm only responsible for what I say, not what you understand.

Chris Savage

This weekend I am going to prep the other ESP32 module (load the firmware) so it can be used with ESP-NOW. I probably won't get to coding much, other than running the test code on the second module. Then I will probably set up one of my development boards for both modules so I can run some of your demos.

I did receive the second display, through it was in slightly worse shape than the first. I need to test that one to see if it needs to go back.

I am still waiting for the VS1053B shield module (says it will arrive May 2-6). I am still planning on getting the one from Adafruit as well, which I will place that order today. That one had the built-in amplifier.

        I'm only responsible for what I say, not what you understand.

Chris Savage

So, the VS1053 Shield arrived exactly as I expected it would...in a bubble envelope. When I opened it, this is what I saw:





So of course the pins on both headers are bent.



And the PCB has been scratched.


        I'm only responsible for what I say, not what you understand.

Jeff_T

That is so aggravating, do you think you will keep it or return it Chris.

Chris Savage

Quote from: Jeff_T on Apr 28, 2024, 04:40 PMThat is so aggravating, do you think you will keep it or return it Chris.

Like the displays, I will attempt to straighten the pins and make sure no traces are broken. Then I will test it. If it passes, I will keep it. Just frustrating. I did order the Adafruit unit as well. Let's see how that arrives.

        I'm only responsible for what I say, not what you understand.

Chris Savage

UPDATE! After some careful pin bending and minor adjustments, I finally got the shield connected. I have NOT tested it yet. That will happen this week. This is an Arduino UNO R3.




        I'm only responsible for what I say, not what you understand.

Jeff_T

Looking good, Adafruit have a library for that shield that you can download from the Arduino IDE.

Chris Savage

Quote from: Jeff_T on Apr 30, 2024, 03:23 PMLooking good, Adafruit have a library for that shield that you can download from the Arduino IDE.

Perhaps I will use that to do a quick test before trying to use this in the project. Still waiting for the Adafruit module to arrive. I have plenty of speakers to use in this project, so I should be set once that arrives.

        I'm only responsible for what I say, not what you understand.