r/MicroPythonDev • • Oct 26 '23

OutGauge and MicroPython

Thumbnail self.beamng
2 Upvotes

r/MicroPythonDev • • May 20 '23

Micropython with Thonny and a Raspberry Pi Pico

2 Upvotes

have pin14 setup to react to a rising IRQ upon which time it prints "button pushed". Now how would I have those rising IRQ's caused by a button push increment to a given count and when that count is reached make pin13 high to light an LED? I have pin14 setup and its working I have pin13 setup with a led. But i am new and trying to tie together an IRQ and a Count to make pin13 go high is eluding me. Coffee isnt helping.... Following is what I currently have...

import machine

import utime

button = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)

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

count = 0

def button_handler(pin):

utime.sleep_ms(100)

if pin.value():

print("button pushed")

print(count)

led.toggle()

button.irq(trigger=machine.Pin.IRQ_RISING, handler=button_handler)


r/MicroPythonDev • • Jul 24 '23

compare bit in byte array

1 Upvotes

i want to make a way to draw images, im currently using string arrays but thats slow

i dont know how to use byte arrays and compare bits in each byte


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 • • May 08 '24

10 Zone ESP32 Sprinkler Controller using micropython

2 Upvotes

I just finished the code for this sprinkler controller if anyone is interested. The reason I made it is to have sprinkler scheduling kept locally in case of network connection failure. However, I included MQTT integration so you can monitor and control each zone from home assistant if you choose. This is my first real github project that I'm sharing with people so feel free to let me know what you think and where I can improve!

https://github.com/TannerNelson16/sprinkler_controller


r/MicroPythonDev • • Sep 03 '23

Is there a good tool or something that allows you to convert some python code into Micropython code?

2 Upvotes

I've written some code in python and i want to use it on my casio cg50 that uses Micropython. I've tried using chatgpt to convert the code but it gives me a Syntax error: invalid syntax (it doesn't say the line). Do you have any idea.

For reference, this is the original code:

def max_num(head, sequence):
for i in sequence:
if i > head:
return i

def min_num(head, sequence):
for i in range(len(sequence) - 1, -1, -1):
if sequence[i] < head:
return sequence[i]

def CLOOK(N, head, sequence):
seek_sequence = []
stop_condition = min_num(head, sequence)
seek_operations = 0
seek_sequence.append(head)
near_num = max_num(head, sequence)
for i in range(len(sequence)):
if near_num > head:
difference = near_num - head
seek_operations += difference
head = near_num
seek_sequence.append(head)
near_num = max_num(head, sequence)
if head == stop_condition:
break
if head == max(sequence):
difference = head - min(sequence)
head = min(sequence)
near_num = max_num(head, sequence)
seek_operations += difference
seek_sequence.append(head)
print("Seek Sequence :  ", end=" ")
for i in seek_sequence:
if i == stop_condition:
print(i)
else:
print(i, " ==> ", end=" ")
return seek_operations

if __name__ == "__main__":
Number_disk = int(input("Enter the number of disks: "))
if Number_disk > 0:
head = int(input("Enter initial header position :   "))
while not head in range(Number_disk + 1):
head = int(input("Please enter valid initial head position :"))
sequence = []
sequence = list(map(int, input("Enter the sequence :    ").split()))
sequence.sort()
if min(sequence) < 0 or max(sequence) > Number_disk:
print("Sequence out of range")
exit(0)
seek_operations = CLOOK(Number_disk, head, sequence)
print("Total number of seek operations : ", seek_operations)


r/MicroPythonDev • • Feb 27 '23

How to upload main.py instead of boot.py from Thonny?

2 Upvotes

I got Thonny working with my ESP32.. The blinking led example worked and I am now trying a webserver example that consists of a boot.py and main.py part. The boot.py part seems to work and I can see the ESP32 getting an IP number. But how do I get the main.py part uploaded to my board?


r/MicroPythonDev • • Aug 25 '24

Guide for connection Esp32 to 16x2 displays without I2C?

2 Upvotes

I want to connect a NDS1602 that came with a Arduino starter kit to an Esp32. Googling around all tutorials assume that the display has an I2C backpack which mine doesn't.

Are there any drivers and wiring diagrams out there that I haven't been able to find?


r/MicroPythonDev • • May 30 '24

CASE

2 Upvotes

Does MicroPython have Match-Case yet?


r/MicroPythonDev • • Jun 28 '24

Morse keys to mouyse adapter for xcwcp

Thumbnail
self.amateurradio
1 Upvotes

r/MicroPythonDev • • Feb 10 '24

MicroPython error codes when I run code with an oled screen.

1 Upvotes

I recently started coding on a rasberry pi pico. I found it super exciting when my blink project worked. But now when i try to run some code with ssd1306 i get this error:

Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "/lib/ssd1306.py", line 119, in __init__
  File "/lib/ssd1306.py", line 38, in __init__
  File "/lib/ssd1306.py", line 75, in init_display
  File "/lib/ssd1306.py", line 124, in write_cmd
OSError: [Errno 110] ETIMEDOUT

How do I fix this? Please help.


r/MicroPythonDev • • Dec 02 '22

BME280 Webserver With Raspberry Pi Pico W ( Weather Station)

Thumbnail
gallery
6 Upvotes

The BME280 sensor module measures temperature, humidity, and altitude. So, you can easily build a mini and compact weather station and monitor it using your Raspberry Pi Pico W web server.

If you are interested in this then you can see the complete tutorial here:-

https://diyprojectslab.com/raspberry-pi-pico-w-web-server-with-bme280/


r/MicroPythonDev • • Jan 02 '24

Micropython sockets seems to be using more and more RAM with every socket timeout

2 Upvotes

I have a Pi Pico W running Micropython. The code creates a socket and awaits a connection. After 10 seconds it times out and re-opens the socket. With each timeout it seems to be using more and more RAM until it crashes the Pico. I have the socket set to timeout because the device on the other end may move out of WiFi range after it connects but the Pico is unaware that the socket is not in use and keeps it open forever without the timeout. The Full code below:

import network
import socket
import time
import gc

ssid = 'myssid'
password = 'mypassword'

def connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(ssid, password)
    ErrCount = 0 
    while wlan.isconnected() == False:
        ErrCount += 1
        if ErrCount > 12:
            ErrCount = 0
            print("Retrying")
            wlan = network.WLAN(network.STA_IF)
            wlan.active(True)
            wlan.connect(ssid, password)
        print('Waiting for connection...')
        time.sleep(1)
    ip = wlan.ifconfig()[0]
    print(f'Connected on {ip}')
    return ip

ip = connect()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = ip
port = 49662
s.bind((host, port))
s.settimeout(10)
s.listen()
while True:
    try:
        c, addr = s.accept()
        print(f"Connection from {addr}")
        time.sleep(0.5)
        data = c.recv(1024).decode()
    except:
        print("Socket Timeout, re-trying")
        print(f"Memory: {gc.mem_alloc()} used with {gc.mem_free()} bytes remaining.")
        gc.collect

The result is this:

Connected on 192.168.1.77

Socket Timeout, re-trying

Memory: 6288 used with 186480 bytes remaining.

Socket Timeout, re-trying

Memory: 6464 used with 186304 bytes remaining.

Socket Timeout, re-trying

Memory: 6640 used with 186128 bytes remaining.

Socket Timeout, re-trying

Memory: 6816 used with 185952 bytes remaining.

etc...

Any ideas how to stop this as I need the Pico W to run reliably for a week without stopping?


r/MicroPythonDev • • Aug 11 '24

Windows 11 - Do I need to install a USB to Serial driver ?

2 Upvotes

I am setting up PyMakr 2 in VS Code on Windows 11 to work with a Esp32 dev board

I installed this USB to Serial driver : https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads

But I have trouble connecting - is busy.


r/MicroPythonDev • • Jul 19 '22

Looking for micropython pid controller for position of a motor shaft

1 Upvotes

Anyone seen any example micropython code for a pid controller for positional control of a dc motor with encoder.


r/MicroPythonDev • • Jan 11 '23

Micropython for ESP8266

3 Upvotes

Hi,

I have been working on ESP8266 for a while. I have flashed Micropython firmware into it. As working on it, I face many problems while integrating sensors with it (like HC SR04). can anyone help me with to go though it??


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

Micropython Programming IO Pins Question

2 Upvotes

I'm Using Micropython in Thonny. I have made a script that has my RaspberryPi Pico when powered up set GPIO Pin 13 as an Output then Set GPIO Pin 4 and an Input and then set GPIO Pin 13 high. I now want it to monitor GPIO Pin 14 for an input (High). When receiving the Input High on GPIO Pin14 it will finish the script and start a 10 minute countdown and then set GPIO Pin 13 Low. I think..."think" I have it mostly resolved except for the monitoring pin 14 for the high. I have a while statement calling out monitoring pin 14 with a break statement but not having any luck getting it working correctly. To Trigger pin 14 I have been jumpering pin 36 (3.3vdc) to pin 19 (gpio 14) manually with a jumper wire and i cannot get it to break from the while statement. I have attached the code i have thus far below the line. Again I am using Micropython on a RaspberryPi Pico W. In the shell window on thonny im seeing a "repeating Value is 0" even when jumpering the pin36 to pin 19. can anyone offer assistance?

Thank You! -Brian-

-----------------------------------------------------

#New Script written in Micropython for Pi Pico

#Using RaspberryPi Pico Interpreter and Micropython MicroPython v1.20.0 on 2023-04-26

import machine

from machine import Pin

import utime

from machine import Timer

#Used for the OnBoard LED of the pico

led = machine.Pin("LED", machine.Pin.OUT)

led.off()

led.on()

#Create output for Pin 13

p13 = Pin(13, Pin.OUT)

#Create input for Pin 4

p14 = Pin(14, Pin.IN, Pin.PULL_DOWN)

#Set Pin 13 Value High Initially

Pin(13, mode=Pin.OUT)

p13.value(1)

print("Pin 13 now set high")

print("Pin 13 is set to:")

print(p13.value())

print()

#(Section is for reading Input High on Pin 4)

input = (p14.value())

print("Input Value to Pin 14 is:")

print(input)

print()

while input == 0:

print("Value is 0")

check2 = (p14.value())

if check2 == 1:

print("HIGH")

break

x = 0

for y in range(0, 12):

utime.sleep(1)

x += 1

print(x)

led.toggle()

print()

p13.value(0)

print("Pin 13 is now set Low")

print("Pin 13 is set to:")

print(p13.value())

led.on()

utime.sleep(2)

led.off()


r/MicroPythonDev • • Dec 12 '22

Usage of Classes

1 Upvotes

Hi!

Does MicroPython support creating classes?


r/MicroPythonDev • • Nov 17 '22

SafeMode for ESP32 Development Boards

2 Upvotes

How to enter SafeMode with an ESP32 Development Boards?

Everything is documented for the PyBoard but I can't find anything for the ESP32.

Thanks !


r/MicroPythonDev • • Feb 06 '24

What is the most recent workflow to develop a MicroPython project?

3 Upvotes

There is now a package manager called mip, but it only downloads packages to the board. I use VSCode + PyMakr to develop MicroPython project currently. So there won't be IntelliSense if I install packages this way.

What is your way to install packages to your project? Copy and Paste source code in your workspace directly from Git Hub?

I also found there are much less libraries in micropython-lib than in arduino/library-registry. Is MicroPython a good choice for production development? I'm still pretty new to both MicroPython and Arduino, and hesitate on which way to go.

Thank you.


r/MicroPythonDev • • Nov 10 '22

Big News: MicroPython officially becomes part of the Arduino ecosystem

Thumbnail
blog.arduino.cc
16 Upvotes

r/MicroPythonDev • • Nov 13 '22

ESP32 - pyboard.py - TCP - Connection refused

3 Upvotes

Hello everyone,

I can't connect to my ESP32 via pyboard.py and I can't find the info of what I need to set up on the ESP32 side.

The WebRepl works.... but I need to install a telnet server or is it native?

./pyboard.py -d 192.168.1.202 -p "print('hello')"

Traceback (most recent call last):

File "/Users/jb/Documents/MicoPython/pyboard.py", line 832, in <module>

main()

File "/Users/jb/Documents/MicoPython/pyboard.py", line 753, in main

pyb = Pyboard(

File "/Users/jb/Documents/MicoPython/pyboard.py", line 266, in __init__

self.serial = TelnetToSerial(device, user, password, read_timeout=10)

File "/Users/jb/Documents/MicoPython/pyboard.py", line 97, in __init__

self.tn = telnetlib.Telnet(ip, timeout=15)

File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/telnetlib.py", line 218, in __init__

self.open(host, port, timeout)

File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/telnetlib.py", line 235, in open

self.sock = socket.create_connection((host, port), timeout)

File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 845, in create_connection

raise err

File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 833, in create_connection

sock.connect(sa)

ConnectionRefusedError: [Errno 61] Connection refused


r/MicroPythonDev • • Jan 15 '23

How to set the local time manually without NTP?

1 Upvotes

r/MicroPythonDev • • Apr 10 '24

Circuitpython Brainbuster for the μPython Crowd

Thumbnail
gallery
4 Upvotes

I have an Optocoupler connected to my Adafruit Feather ESP32-S2 - 2Mb PSRAM and Stemma QT/Qwiic Adafruit 5000 on a custom PCB where it receives a steady 4.95volts and 0.5 amps. The optocoupler requires power on its 5v pin and a GND(duh) then it has a signal pin which is connected to pin D6 on the feather. I have a single piece of dark material that blocks the signal from the Optocoupler as the entire PCB spins.

I use analogio to set a variable as an analog input for the D6 pin. With board.D6 in the usual way. The code is working as it perfectly reads the value 50976 when the Optocoupler does not have the dark material in its path; the .value reads the pin at around 4000 or so when it is blocked by the dark material.

The problem is that when I rotate the sensor fast it doesn’t even detect a change in the 50976 analog read. When I rotate it really slow with my hand, it will detect the drop in the analog value. Though it’s nowhere near the speed at which I will have this sensor moving when the motor is on.

I even tried appending an array with the .value method where I fill an array of 250 or so values and that entire array is the same 50975 value when I rotate it fast. Which makes no sense at all. I even tried making the array sample size at like 2000, and had a start time.monotonic() and stop.monotonic() where the array was filled in a ridiculously short amount of time. More than enough time to actually detect a signal drop at even a super slow hand spun speed of like 3 rotations per second.

I even tried bit shifting the analog output to 32 bit and that number still doesn’t even detect the drop in signal. As you can see commented out in the 1st and 2nd photo.

Rotaryio doesn’t work because it needs two sensor values like MOSI and SPI or whatever it requires and measure the two pins; typically for slow potentiometers.

Pulseio has horrible documentation and only references how to use it for remotes.

What I really need to do is use some lower level python syntax code to read the ADC but I can’t find out how to do that anywhere and each attempt to do so gives me errors because nothing is supported in circuitpython.

It the third reference image I have the optocoupler on the right of the photo with the led on showing it’s signal is at 50976 and in the 4th photo the signal is lower at like 4000 or so and the led is off. In the first photo of my ide you can see the array where it’s all populated with the correct readings when the led on the optocoupler is off because the signal is blocked.

In the 5th photo the motor is on and the frame rate of the camera is showing an inaccuracy. With your eyes you see an almost full arc where the led on the optocoupler cuts out exactly with my dark material is. So the led is reacting to the infrared sensor but the code is too slow.

You may say I’m not hand spinning the motor fast enough when the array is being filled. Though when I remove the 5 second time.sleep() and continue to spin the motor it has the same effect so it’s not that.

What should I do? Help!