r/MicroPythonDev • • Sep 16 '22

Requests.posts from a Pico W

4 Upvotes

I am hoping to deploy a Pico W to monitor a door switch for my security system. When the switch opens or closes, I want the Pico to do a requests.post to URLs that sends the corresponding keyword to my phone. Tasker and AutoRemote digest the keywords to give me appropriate notifications and sounds, and other functions.

I have not found an effective way to import/install requests to do this. Is this possible?


r/MicroPythonDev • • Mar 04 '23

Receive webhooks using Micropython

3 Upvotes

I'm looking into the best way to receive webhooks using (a Pi Pico W that runs) Micropython. There are many posts about sending requests, but I find it difficult to find information on receiving them.

I got some pointers and insights from this post, but still have some questions about the best approach.

I'm primarily puzzled as to why I would need to setup port forwarding while other smart home devices obviously don't require users to do this. Shouldn't this be possible with just software?

As indicated in the post: if it turns out to be very complicated to setup or maintain, or it poses significant security risks, then I'm considering falling back to an implementation where each device would make GET requests every X seconds to check if there are updates.

Would love to know if anyone has experience with this in Micropython, preferably combined with any dev board (Raspberry, Arduino, etc).


r/MicroPythonDev • • Feb 08 '24

please help me im new in coding!!!

2 Upvotes

so I have this object (its in MicroPython for ev3)
EV3 = EV3Brick()
left_motor = Motor(Port.A)
right_motor = Motor(Port.B)
WHEEL_DIAMETER = 55.5
AXLE_TRACK = 104
robot = DriveBase(left_motor, right_motor, WHEEL_DIAMETER, AXLE_TRACK)

and the last line is saying that its an a error and when I'm trying to put something else in this line its still doesn't working


r/MicroPythonDev • • Jan 16 '23

AES MicroPython <=>React

2 Upvotes

I want to develop end-to-end encryption where from my React website I encrypt the data (on the client side) (string 40 char Max), save it in the database

My esp32 MicroPython to be able to decrypt it. (having the same key as react )
I found solutions for both React and MicroPython but I was not able to get the encrypted data from react to be decrypted on esp32.

Could someone help me make both work?


r/MicroPythonDev • • Jun 10 '24

I2C Sensor Returning 0's on Pico but works Perfectly on RPi 3

2 Upvotes

I'm at my wits end over an ENS160 sensor I have working perfectly with a Raspberry Pi 3 (running full Linux OS and Python), but refuses to return any data when interfacing through a Raspberry Pi Pico with MicroPython.

Long story short, I purchased ENS160 + AHT21 breakout boards (two sensors, one board). All of them worked quite well with the Raspberry Pi Pico through MicroPython... for a period of time. After a number of days of continuous reading, the ENS160 readings would eventually start returning 0's for all three readings (AQI, TVOC, and ECO2). Initially, it was intermittent and I was able to do some configuration to get it back to life again. But as time went on, they grew more and more unreliable with the 0's coming back more frequently. At this point, many of the sensors simply don't return any data at all, no matter how I configure them. There is also no sign of any error being logged by the ENS160 from what I can tell. The AHT21 sensors all continue to work perfectly, so I don't think it is a problem involving the I2C lines.

What makes this absolutely puzzling: as soon as I wire one of these sensors (that were proven to not work on the Pico) to a Raspberry Pi 3 (running full Linux OS), it works perfectly. Data comes in, fully reliable, never misses a beat. I've tracked the exact register reads and writes by the Raspberry Pi 3 to the sensor and mimicked them completely with the Pico in MicroPython, both at initialization and read; no luck.

What I've tried:

  • Maybe the Pico's 5V (or 3.3V which I tried too) power supply is unstable. I tried external power. Same results.

  • Adding I2C pull-up resistors when interfacing with the Pi Pico, 10k ohms and 220 ohms. Same results.

  • Using a range of clock speeds (frequencies) - everything from 50,000 Hz to 400,000 Hz. Same results.

I've spent weeks now trying to figure out the issue. I've documented a lot of my trials in this GitHub repo here.

How could this be? I was going to chalk this up as a faulty sensor from a poor manufacturer, but this can't be the case as it works perfectly as soon as I hook it up with the Raspberry Pi 3. Any thoughts are appreciated, thank you!


r/MicroPythonDev • • Sep 11 '23

What is the best way to create a uf2 file with my own libraries?

3 Upvotes

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 • • Sep 14 '23

MicroPython native modules + emlearn = fast Machine Learning with easy install

7 Upvotes

Hi everyone! Lately I have been working on providing core Machine Learning inference for MicroPython. I wanted it to be possible to write an entire TinyML application in Python, but still keeping the efficiency of C code for the computationally intensive parts. And I also wanted the installation to be simple, retaining the "all you need is just an (m)pip install away" feeling.

And thanks to the dynamic native modules support in MicroPython this was possible. The project now provides small .mpy files with the compiled C code (around 3 kB), with nice Python APIs to common Machine Learning models.
https://github.com/emlearn/emlearn-micropython

There were a few hurdles on the way, some fixes were needed in the MicroPython native module support. These have of course been provided upstream:
https://github.com/micropython/micropython/pull/12241
https://github.com/micropython/micropython/pull/12123


r/MicroPythonDev • • Aug 31 '24

How do i encode signal using PCM?

1 Upvotes

I was trying to use ADC on Raspberry Pi Pico to encode analog signals in a way that Linux can play.

But everything is mixed up in my mind. ADC seems like the perfect definition of PCM as its already samples at specific rate 12 bits up to 500kHz sampling rate and it doesnt compress or add headers or magic values.

So my question is, can i use first 8bits of the ADC and sample it by 48kHz to encode this signal as PCM and hopefully stream in Linux ?


r/MicroPythonDev • • Sep 09 '24

Hypnosis device wip help needed

2 Upvotes

I'm working since 2018 on a hypnosis device (because l'm a chronical insomniac). My 3 first prototypes are working fine but need some fixes. The process of action is brain-waves training with isochronic tones. I also included a white noise generator (since first prototype). I also planned to implement sacred solfeggio frequencies. My three first prototypes were coded brick by brick like a Lego. If some people are interested, please let me know. Old prototypes were arduino uno based. I decided to switch on m5stack cardputer. Last thing : everything will be open source.


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 • • Jul 13 '24

problem with rpi pico w micropython script

1 Upvotes

im a major newbie to python in general, including micropython, so after recently buying a 1.3" waveshare display and a rpi pico w, i tried to start up a project... but a function doesn't seem to be working. i already have all the libraries installed and the lcd commands defined, but this specific while loop isn't working on my display. can anyone help me?

my screenshot wasnt working...

cx = 120;

cy = 120;

def cursor(cx, cy):

lcd.line(cx-5, cy, cx+5, cy, colour(255, 255, 255))

lcd.line(cx, cy-5, cx, cy+5, colour(255, 255, 255))

while (up == 1):

cy += 1

utime.sleep(0.05)


r/MicroPythonDev • • Jun 22 '22

MicroPython display issues on the TTGO T-watch S76G (GPS + LoRa edition)

Thumbnail self.esp32
3 Upvotes

r/MicroPythonDev • • Feb 28 '23

Pre Release Release Note Discussion

Thumbnail
youtube.com
3 Upvotes

r/MicroPythonDev • • Jun 08 '23

How to adjust esp32-s2 memory layout?

Post image
3 Upvotes

I’m learning how to build my own micropython firmware and was hoping to get some input on how to restructure the firmware based on my custom boards needs.

In the firmware I am planning to implement over the air updates to flash the opposite partition then set the next boot to it then boot over to it. I have checks in there as well and the ability for user to manually fail back if an error occurs.

On my board I also have 1 mb FRAM that I use for storing all my essential configuration data. So the esp32-s2 is really just responsible for executing code. My esp32-s2 is the 4mb 2sram model: ESP32-S2FN4R2

The attached picture is the generic ota memory layout from micropython

So here is where I need help. What I want to do is split my available resources directly in half. OTA_O and OTA_1 that’s straight forward. But since I am using an external FRAM with 1 mb of storage do I need the NVS? Second, do I need the “otadata” if I only intend to use either partition? I can’t think of why or how to use the otadata partition in this situation. And I don’t know what the VFS is. Any guidance here is appreciated. Thanks!


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 • • Jul 10 '22

Servo motor or stepper motor

1 Upvotes

I am trying to build a very small solar tracking program, which I already have the code to give me azimuth and elevation of the sun. I think I could easily use say a 35g servo motor and it should be easy to complete the code, but was wondering if a say Sequre 42 closed loop stepper motor would be more powerful, also the code for the stepper motor to track the sun in azimuth and elevation might be harder to write. Any suggestions? I do not want to use ldr’s.

Thanks


r/MicroPythonDev • • Jan 10 '24

Thread modul in Micropython

3 Upvotes

Hello! I hope this question is not too silly. I have to run three function at the same time in micropython so its obvious i need threading. My main problem is that i can not reach the "us level" (microsecond time) with the "asyncio" library in Micropython (just the millisecond time). Does anyone have any ideas on how I can achieve the microsecond time? I mean with other libraries or maybe with a built-in modul? Thank you so much for your answer! (i am using Pyboard)


r/MicroPythonDev • • Sep 10 '23

Non-Blocking Keyboard Input during code execution on Pico?

1 Upvotes

Hi all,

Whilst trying to code an algorithm for an elevator I ran into a question. The elevator would run the algorithm laid out in this document: https://github.com/j-bellavance/Tutorials/blob/master/State%20machines%20Tutorial/Part%203/State%20machine%20with%20Arduino%20(Part%203).pdf. I want to implement this program in micropython running on a Raspberry Pi Pico.

The relevant feature here is this: the elevator in this example has eight floors. A "real" elevator would therefore have eight buttons in the elevator car to make it go to a floor, and (in this example) two buttons on each floor to summon the car to that floor, either to go up or to go down. That would make for 24 buttons.

As I would also need some pins for the ultrasonic distance measurement (it's gonna be used to determine the position of the elevator car) and possibly a display, I would like to replace the buttons with input over a serial port (whilst connected to the computer).

In Arduino, this has a well-known solution: the serial port is available during code execution for both output AND input. An example is in the linked document above. In the example linked above, the keyboard input is read using a state machine loop which allows the keyboard inputn to be processed without halting code execution for other functions.

Alas I can't see any example of the serial port of a Pico (or any other uPython board) being used for non-halting keyboard input during code execution.

If anyone could point me in the right direction, that would be appreciated. If that would entail switching to CircuitPython or using one of the four state machines of the Pico, that might exceed my experience and comfort zone, but that's a risk I'm willing to take (Farquaad has entered the chat).


r/MicroPythonDev • • Apr 30 '24

My open source, ESP32-S3 based, multi-RAT (cellular LTE-M and NB-IoT and WiFi/BLE) module Walter is featured on the IoT show from Oliver Bloch.

2 Upvotes

Hi fellow MicroPython developers,
I'm so glad to share that my project Walter will be featured in the IoT Show from Olivier Bloch. It will air coming Wednesday at 7AM PDT, make sure to subscribe to his channel to sit on the first row: https://www.youtube.com/obloch

I can already share some sneak peak:

Walter is an open source (https://github.com/QuickSpot) module that combines an ESP32-S3 together with a Sequans monarch 2 cellular modem. This gives Walter LTE-M, NB-IoT, WiFi, BLE, GPS and GLONASS capabilities. It is pin and software compatible with the former Pycom GPy and thus a drop-in replacement for it. We opted to go with mainstream MicroPython support for Walter and made the complete asyncio based modem library open source on github. We have tested Walter with various beta testers all over the world: https://walterdemo.quickspot.io/

The open source Walter cellular and WiFi/BLE/GPS module crowd funding is only running for two more days. Now is your chance to get Walter at the early bird price of 70USD: https://www.crowdsupply.com/dptechnics/walter


r/MicroPythonDev • • Mar 21 '23

Code for raspberry pico

4 Upvotes

This is my first project with raspberry pico. I want to control a servo that moves from position one to position two at any random time between 30 sec to 70 sec. Can anyone please help me with the code?


r/MicroPythonDev • • Sep 27 '22

Cross posting from RPIPico - requests.post issue

Thumbnail self.raspberrypipico
1 Upvotes

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 • • Dec 04 '23

Update: now more than 170 tips

3 Upvotes

A few weeks ago I posted that there are 90 tips on my MicroPython tips site.

Well now there are more than 170 !!!

Have a look: https://micropython-tips.weebly.com/

No advertising, no tricks. All tips documented with an example.
Keep following as there are more tips to come !!