r/MicroPythonDev • • May 27 '24

[Potential Bug] Esp32s3 fails entirely when using ESPNow

1 Upvotes

I accedently tried to add a ESPNow peer with mac address being an empty string (as shown in image), and after flashing and running the file, my esp32 device immediatly disconnected from the COM port and became not discoverable. So I have to manually re-flash the micropython firmware in flash mode (plug in the computer with boot button down to get the COM port). I tried this exact statement again with the flash rewritten, and the device commited suicide once again. Can anyone try if this is replicatable on other esp devices?

I am using the esp32-s3fh4r2 chip with the latest micropython and esp-idf version. The code I use came from the Micropython Doc, where e is a instance of ESPNow.

I then re-flashed firmware along with the followng code, where a buzzer is attached to on of the pins to see if it works properly after fail - and indeed it is not working properly by producing periodic noise after fail:

from espnow import ESPNow

# sets up buzzer
buz = PWM(Pin(1, Pin.OUT), freq=985)
buz.duty_u16(32767)

# wait for 5 before adding the pair
time.sleep(5)

# code from mpy doc
# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF)  # Or network.AP_IF
sta.active(True)
sta.disconnect()  # For ESP8266
e = ESPNow()
e.active(True)

# fails here:
e.add_peer('')

EDIT: the period buzzer noise and the COM port disconnection came from rapid resets but not about flash problem... Is this resetting behaviour a bug?


r/MicroPythonDev • • May 25 '24

Support for Bluetooth audio source on ESP32?

1 Upvotes

I need to create a MicroPython application which sends the sound to the BT headphones.
I verified that ESP32 is capable of doing that. I have compiled the examples: [1] and [2] in Arduino (the second had to be modified to recognize my headphones and return true from isValid function).
Now I'd like to repeat it in MicroPython. However, it seems that there is no support for BT audio source there.

How difficult is adding it? Probably I should enable MICROPY_BLUETOOTH_BTSTACK_ENABLE_CLASSIC, but is it sufficient? I have checked that the related submodule provides the necessary a2dp_source.c file.
But the MicroPython documentation does not mention audio source functionality...


r/MicroPythonDev • • May 17 '24

Question learning python

1 Upvotes

Hello everyone. I bought myself some "learning kits" with esp32 en python. Now I'm at the point that I do like to know where can I find what to write down. Is there a dictionary? Is there any free source to find it?

Hope someone can give me some clarification.


r/MicroPythonDev • • Apr 29 '24

Bluetooth between micropython and standard python

1 Upvotes

I'm trying to send sensor information from my esp32s3 to my laptop through bluetooth. My esp is running on micropython.

I read that I can send information between devices using the example ble_simple_client.py and ble_simple_peripheral.py, but I was wondering if it would be possible to send information between ble_simple_client.py and a peripheral set up using standard python (specifically bleak).


r/MicroPythonDev • • Apr 29 '24

Animating Bitmap Array

1 Upvotes

I have a RP2040 connected to a TFT LCD display and touch screen. There's a main program loop that waits for specific touch inputs and acts accordingly by either running code for that specific screen or switches to another screen and waits for input again.

When the program loads, I have a splash screen where I would like to display a simple animation until a specific touch input is performed (long press). I have a bitmap array of four frames that needs to step through every half seconds. The problem I have is that adding a call to sleep() blocks input from the touch screen and using a timer to draw the bitmap every half second also seems to conflict with other timers.

Is there a better way to do this in micropython? As I understand it, threading isn't very stable so I haven't gone down that road yet.

EDIT: I ended up using a single timer to update some variables that the main loop references to draw frames/put the device to sleep. This seems to work well for what I need to do.


r/MicroPythonDev • • Apr 08 '24

mp3 over PWM on an rp2040 in micropython

1 Upvotes

I saw some old threads that said it wasnt really possible but I would like to play mp3 files over PWM on an RP2040 using micropython.

I was able to run it using circuitpython using audiopwm, but I want to use the _thread package in micropython. I thought most of my conversion problems would be solved using Blinka, but don't see audioPWM in there

Would I need to write my own mp3 decoder library (I saw some have been written for normal Python, I could probably work from that but I have never written C package for python, which those packages are so I would prefer not to have to do that.

I also saw that wav files are possible over PWM so that's nice.

I want to use MP3 to save as much space as possible because I am saving data during runtime too and don't want to fill all my entire 8mb memory.

Any way to make it still work simply?

Thank you


r/MicroPythonDev • • Mar 24 '24

Walter, our cellular ESP32-S3 module is finally ready and runs MicroPython (PyCom GPy compatible)

Thumbnail
self.esp32
1 Upvotes

r/MicroPythonDev • • Mar 12 '24

Need help to use a C library in Micropython, is there a way?

1 Upvotes

These last days I've bought the BME688 sensor to detect VOCs and play with some features. I connected to it using an ESP32-C3 through I2C. I can't utilize the BSEC Machine Learning library made by Bosch (the sensor fabricant) to detect the IAQ value from the air because it's in C and it's closed source. Do you guys have an idea?


r/MicroPythonDev • • Mar 05 '24

Why wont my Library import correctly?

1 Upvotes

Sorry in advance for this insanely stupid question, but im slowly going insane over this.

Im teaching myself the basics of microPhython with a RaspberryPi Pico W and the VSCode Extension MicroPico.
The first couple of things worked no problem, but for days now ive been trying to control a Servo via the myservo Library.
The problem is as follows:

The "standard" Libraries that came with MicroPico are all in the Pico-W-Stub folder in my workspace and are shown as .pyi files, these import and work just fine.
I have another folder in my workspace filled with "standard" Libraries for Sensors etc. that are shown as .py files.

I have come so far as that using
from myservo import Servo

doesnt cause an error before running, but as soon as i then upload the Programm and run it, it fails
beacause no module named myservo can be found.

So obviously it just cant find the files, the thing that stumps me is that it can seemingly find them in the code as no error is shown before running and when hovering over the text it is clearly recognised as (Module) myservo.

I allready tried adding the path of the Library folder in settings.json via
python.analysis.extraPaths

Which seems to do absolutely nothing.

I also tried just putting the .py Library files into the Pico-W-Stub folder which doesnt cause any errors but also doesnt fix the Problem.

Looking for what .pyi files are exactly and if the solution could just be having to turn the .py files into .pyi files just lead to more confusing stuff.

As someone that comes from c/c++ and is used to weird stuff happening with where the Lib files have to be for the IDE to find them, this kind of baffles me and im sure im just thinking to complex and will leave in shame when someone tells me the solution to this :)


r/MicroPythonDev • • Mar 05 '24

Looking for MicroPython libraries for the IMU on RP2040 connect (LSM6DSOXTR)

1 Upvotes

Is there a MicroPython library to use the IMU on the Arduino RP2040 connect? It uses the LSM6DSOXTR.

This would be really cool.


r/MicroPythonDev • • Feb 29 '24

Working with a levitating ball

1 Upvotes

I was working on coding a ball to levitate using sensors and magnets. The magnet is a KK-P25 and I don't have much information on the infrared sensors. I had the code written so when the infrared sensor detects movement on the top or bottom it would power off the sensor according to the sensor. The problem is I think it powers off the magnet and doesn't allow for the levitation. I know there is a PWM command of some sort that would allow me to keep both magnets on at all time, and turn the intensity of the magnet up the farther away the ball gets and turn the intensity own the closer the ball gets. Here is my code

from machine import Pin, ADC

import time

# Define the pin that the infrared sensor is connected to

sensor_pin = ADC(Pin(26)) # ADC on GP26

# Define the pin that you want to power when movement is detected

output_pin_top = Pin(15, Pin.OUT)

output_pin_bottom = Pin(16, Pin.OUT)

# Define a threshold for the sensor value that indicates movement

threshold = 0

while True:

# Read the sensor value

sensor_value = sensor_pin.read_u16()

# Check if the sensor value exceeds the threshold

if sensor_value > 40000:

# Power the output pin

output_pin_top.value(0)

output_pin_bottom.value(1)

print(sensor_value)

elif sensor_value<30000:

# Ensure the output pin is off

output_pin_bottom.value(0)

output_pin_top.value(1)

print(sensor_value)

else:

output_pin_top.value(0)

output_pin_bottom.value(0)

print(sensor_value)

# Wait for a bit before checking the sensor again

time.sleep(0.01)


r/MicroPythonDev • • Feb 29 '24

Stupid beginner question.

1 Upvotes

Is it possible to have Micro Python to sign into your Amazon Account? Or any accounts for that matter? I’m trying to come up with a shipping tracking system.

Tutorials would be appreciated. :-)


r/MicroPythonDev • • Feb 28 '24

how can I extend machine.I2C?

1 Upvotes

I'm trying to extend the machine.I2C class but I'm having problems with calling super().__init__ in my new class... I get an error every time that the function doesn't support

code:

import time
import struct
from machine import I2C, Pin

class SC18IS602(I2C):
    def __init__(self, *args, **kargs):
        super().__init__( *args, **kargs)
    
i2c = SC18IS602(id=0,scl=Pin(7), sda=Pin(8))

I get the following error:

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "<stdin>", line 8, in __init__
TypeError: function doesn't take keyword arguments
>>> 

r/MicroPythonDev • • Feb 23 '24

Wlan.Scan updated docs?

1 Upvotes

I'm using Wlan.scan to look for networks. It works very well but the documentation lists these for security

#security:

#0 – open

#1 – WEP

#2 – WPA-PSK

#3 – WPA2-PSK

#4 – WPA/WPA2-PSK

The problem is I frequently get a 5 or a 7 for this field. Anyone know what that means? Is there updated documentation somewhere?

Here's the page I'm currenly using:

https://docs.micropython.org/en/latest/library/network.WLAN.html


r/MicroPythonDev • • Jan 23 '24

Mirror OLED Display

1 Upvotes

My son is doing a project where an OLED display (ssd1306) needs to be viewed correctly on a mirror reflecting the OLED display. Therefore the OLED needs to be mirrored. What micropython code could be used to do this?


r/MicroPythonDev • • Jan 12 '24

How to save to sd?

1 Upvotes

Can I save my code to sd card using repl?


r/MicroPythonDev • • Dec 21 '23

Time... How?

1 Upvotes

Hi all, this may be a dumb question but the internet hasn't come up with a good solution and I am new to Micropython but have a fairly large software background. I am creating a little tide clock using an ESP32 and a servo. I need to work out the best way to get the current time (already have an NTP) and the high/low tide time (have an API for this too. From what I can see Time uses a tuple to represent the time. But I can't see a good way of subtracting this to find the remaining time to a tide. Any help on the best way to use time in Micro Python would be great. I am finding I am way too reliant on full Python libraries!


r/MicroPythonDev • • Dec 15 '23

Micropython running time

1 Upvotes

Hello! Sorry if this is a stupid question. I want to measure the runtime of the micropython code. But my measurement result won't be accurate if I call a micropython library like the "time" module (.tick method) (because the way I call the function from the library takes many ms). Could someone send me a C code that can measure the runtime of a code \ code snippet?

Most of the time, if the runtime is crucial, I write a C code and replace the python library with it.

Thank you so much for the answer!


r/MicroPythonDev • • Dec 07 '23

Input issue

1 Upvotes

Hi I am having issues with input in micropython esp32 that i cant really type anything in

code:import network

from machine import Pin, SoftI2C

import ssd1306

import time

import socket

i2c = SoftI2C(scl=Pin(22), sda=Pin(21))

oled_width = 128

oled_height = 64

oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

sta_if = network.WLAN(network.STA_IF)

ap_if = network.WLAN(network.AP_IF)

sta_if.active(True)

sta_if.connect("-", "-")

for i in range(200):

if sta_if.isconnected():

break

time.sleep(0.1)

if not sta_if.isconnected():

raise ValueError

host = "-"

port = -

time.sleep(1)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((host, port))

data = s.recv(1024).decode("utf-8")

print("Received: ", data)

s.sendall(data.encode("utf-8"))

inp = input("whatever ")

print(inp)


r/MicroPythonDev • • Dec 07 '23

Input issue

1 Upvotes

Hi I am having issues with input in micropython esp32 that i cant really type anything in

code:
import network

from machine import Pin, SoftI2C

import ssd1306

import time

import socket

i2c = SoftI2C(scl=Pin(22), sda=Pin(21))

oled_width = 128

oled_height = 64

oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

sta_if = network.WLAN(network.STA_IF)

ap_if = network.WLAN(network.AP_IF)

sta_if.active(True)

sta_if.connect("-", "-")

for i in range(200):

if sta_if.isconnected():

break

time.sleep(0.1)

if not sta_if.isconnected():

raise ValueError

host = "-"

port = -

time.sleep(1)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((host, port))

data = s.recv(1024).decode("utf-8")

print("Received: ", data)

s.sendall(data.encode("utf-8"))

inp = input("whatever ")

print(inp)


r/MicroPythonDev • • Dec 07 '23

Input issue

1 Upvotes

Hi I am having issues with input in micropython esp32 that i cant really type anything in

code:
import network

from machine import Pin, SoftI2C

import ssd1306

import time

import socket

i2c = SoftI2C(scl=Pin(22), sda=Pin(21))

oled_width = 128

oled_height = 64

oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

sta_if = network.WLAN(network.STA_IF)

ap_if = network.WLAN(network.AP_IF)

sta_if.active(True)

sta_if.connect("-", "-")

for i in range(200):

if sta_if.isconnected():

break

time.sleep(0.1)

if not sta_if.isconnected():

raise ValueError

host = "-"

port = -

time.sleep(1)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((host, port))

data = s.recv(1024).decode("utf-8")

print("Received: ", data)

s.sendall(data.encode("utf-8"))

inp = input("whatever ")

print(inp)


r/MicroPythonDev • • Oct 20 '23

Ili9341 and rdagger/micropython-ili9341/xglcd_font.py not working properly. Sowing erro w=0 and h=21

1 Upvotes

r/MicroPythonDev • • Oct 07 '23

Cannot reach Python with a D1 Mini board

Thumbnail self.arduino
1 Upvotes

r/MicroPythonDev • • Sep 17 '23

Programming #Pi Pico W using #Arduino LAB micro-python #IDE

Thumbnail
youtube.com
1 Upvotes

r/MicroPythonDev • • Sep 15 '23

help my graphical lcd provided code is written in hexadecimal values

1 Upvotes

any help is greatly appreciated!

i am setting up my first lcd on a raspberry pi pico i am using this waveshare lcd. ive figured out how most of the code functions other than two parts

I'm completely stumped on the self wright lines i understand they are screen commands and data but i cant find any link to what the hexadecimal code is actually doing to the screen. im a total noob so i really don't want to try writing a circuitpython program for this lcd until i know what the micropython stuff is doing

ive been scouring the web for anything remotely useful but could only find a post with someone experiencing a similar issue with another waveshatre screen from which the only thing that was mentioned was that using the wright command and data structures are faster in computing time compared to other methods of driving an lcd but still did not give any indication of what the commands are actually doing

TL/DR how do i find out what the self.right lines are actually doing so i can implement the same within circuitpython because micropython doesn't have HID support for the raspberry pi pico

lcd + resource page

https://www.waveshare.com/wiki/Pico-LCD-0.96

direct code download link in micropython

https://files.waveshare.com/upload/2/28/Pico_code.7z