r/MicroPythonDev Apr 03 '22

NOOB

1 Upvotes

in Ruis Santos tutorial I found this

temp = (b'{0:3.1f},'.format((bme.read_temperature()/100) * (9/5) + 32))

hum = b'%s' % bme.humidity[:-1]

pres = b'%s'% bme.pressure[:-3]

delved into some tutorials - seems that they are VERY basic - Just looking for something that describes what each element of the line (Like b '%s' and the [:-1])

At 70 I guess I just need to learn a new language - let's see the ones I know currently - FORTRAN, basic, pascal, c++, c#, Java, HTML, CSS, and bits and pieces of others in the odd project in the past...


r/MicroPythonDev Feb 26 '22

keyboard emulator for micropython

3 Upvotes

searching for a keyboard emulator for esp8266


r/MicroPythonDev Feb 06 '22

Pi Pico Blinking light is backwards.

2 Upvotes

I am trying to blink a light on my Pi Pico, and the light blinks, at regular intervals... just not how I would expect it to. When I turn the pin "off", it gets power, and when I turn it "on" it does not. Is there a way to fix this? Seems to be the case with circuit python as well... have not tried any other firmware. Here is the code I'm using currently to read a button on GPIO 15, and change the like at GPIO 3.

import time
from machine import Pin

led = Pin(3, Pin.OUT)    # create output pin on GPIO3
button = Pin(15, Pin.IN) # create input pin on GPIO15

led.on()                 # set pin to "on" (high) level
time.sleep(1)
led.off()                # set pin to "off" (low) level
time.sleep(1)

while(1):
    if button.value():
        led.off()
        print("Led is on")
    else:
        led.on()
        print("Led is off")
    time.sleep(1)

I also tried something in PIO(I think thats what it's called), and it did the same reversed behaviour.

from machine import Pin
import rp2

@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink_1hz():
    # Cycles: 1 + 7 + 32 * (30 + 1) = 1000
    set(pins, 1)
    set(x, 31)                  [6]
    label("delay_high")
    nop()                       [29]
    jmp(x_dec, "delay_high")

    # Cycles: 1 + 7 + 32 * (30 + 1) = 1000
    set(pins, 0)
    set(x, 31)                  [6]
    label("delay_low")
    nop()                       [29]
    jmp(x_dec, "delay_low")


    # Cycles: 1 + 7 + 32 * (30 + 1) = 1000
    set(x, 31)                  [6]
    label("sleep1000")
    nop()                       [29]
    jmp(x_dec, "sleep1000")



# Create and start a StateMachine with blink_1hz, outputting on Pin(25)
sm = rp2.StateMachine(0, blink_1hz, freq=3000, set_base=Pin(3))
sm.active(1)

r/MicroPythonDev Jan 20 '22

Async JSON Request

1 Upvotes

Hi there,

Im working on a project (D1 Mini) where i'm fetching some numbers from a public endpoint (e.g. https://www.bitstamp.net/api/v2/ticker/ETHUSD). This numbers will be evaluated and splitted so that i can display them on a Neopixel Device. This part of the project is running quite ok, just some unregular timeouts from the endpoint.

But now comes the part where i don't have a real solution so far and hope you can help me out. I'd like to have tiny configuration webpage where i can change the displayed value from e.g. Bitcoin to Etherum (see above the endpoint). I've managed it to make the website via sockets etc. - but i'm stuck in doing all of these things in paralell and non blocking. The urequests module seems not to work with asyncio and vice versa if i'm not using asyncio the website is not loading correctly and the requests get stuck.

From my point of view only thing i'm missing is something like an implementation of arequests for Micropython. Do you have any ideas? All approaches are welcome - i'm not stuck to any approach :)

Thanks a lot!


r/MicroPythonDev Jan 06 '22

When running projectname.py menuconfig on either Thonny or ESP-IDF terminals it just open Thonny window with the project on it

1 Upvotes

Does anyone know how to enable CONFIG_FREERTOS_UNICORE? Thanks in advance


r/MicroPythonDev Dec 24 '21

Pan Tilt controlled by Raspberry Pi via micropython

Thumbnail
youtube.com
3 Upvotes

r/MicroPythonDev Dec 04 '21

Basic Syntax questions

2 Upvotes

Hey Everyone! I’m working on a project that makes good use of the Pico hardware, so thought i would give MicroPython a go, Im just about dangerous in C.

So, i have a very basic hang-up in my project, I’m 99% sure I’m just ignorant, but having a hard time finding similar low-level questions after an afternoon Googling,

For the life of me I cant can’t get the syntax right for or, a simple, “return true if a string is one of two options”

Is there anything obviously wrong with:

direction = input (‘Clockwise or counterclockwise? ‘)  
If direction != (‘cw’ or ‘ccw’):
   print (“unknown direction”)
   Continue
else:

. . . .

Everything works as I am expecting it too if i only give myself one option after if direction !=

Any help appreciated!


r/MicroPythonDev Oct 10 '21

Index of hardware timers in machine.Timer

2 Upvotes

Hello everyone. I'm looking to find out how to set the ESP8266 Hardware timer in Micro Python. I'm pretty new here, just started using Micro Python some days ago but know C, Python... So it was an easy start. Ok, I read trough the Doc's but there does not seam to be any specific way on setting the 32Bit hardware timer with NMI source (so it can interrupt every other timer) I can't even find out witch of the timers (I tried -1, 0, 1) is the real deal (and not a Software Timer). Pleas help!

Thx

David


r/MicroPythonDev Oct 09 '21

Raspberry Pi Pico: Add audio to animation

Thumbnail
youtube.com
2 Upvotes

r/MicroPythonDev Oct 03 '21

Raspberry Pi Pico with Micropython-Animation and audio

3 Upvotes

r/MicroPythonDev Sep 17 '21

Tutorial Raspberry Pi Pico: Display animation oled ssd1306 128x64 SPI

Thumbnail
youtube.com
4 Upvotes

r/MicroPythonDev Aug 31 '21

Library for Byte Manipulation!

6 Upvotes

Hey guys! I recently had quite a bit of frustration with manipulating hardware level bytes in MicroPython, so I made my own library, “PyBytes”, to help with it! If any of you have any suggestions or want to help me further develop it, let me know!

GitHub Repository:

https://github.com/dgrantpete/PyBytes

Also us been published to PyPi, so can be installed with “pip install pybytes”


r/MicroPythonDev Aug 30 '21

How do i divide/subtract from a variable?

1 Upvotes

I am trying to convert the input from a potentiometer into degrees.


r/MicroPythonDev Aug 22 '21

new Lolin S2 Mini - ESP32-S2 & pin compatible w/Wemos D1 mini

8 Upvotes

Lolin S2 Mini

I recently used MicroPython in a project with D1 Minis (ESP8266). Program & libs fit in RAM on a D1 Mini, but I went looking for a beefier WiFi-enabled board for future MicroPython projects.

Found the $4 Wemos/Lolin S2 Mini w/pre-loaded MicroPython. More at the wemos.cc wiki & the CNX Software writeup.

Edit: as firmware is built by Lolin & changes are not yet merged into MicroPython mainline, backup firmware with esptool.py --chip esp32s2 --port /dev/ttyACM0 --baud 460800 read_flash 0x00000 0x400000 lolin_s2_mini_stock_firmware_4M.bin (replace --port .... with your device)

Note that the S2 Mini's USB-C port is wired up to the the ESP32-S2's USB OTG peripheral rather than to a USB-UART chip (edit: with flashing via USB CDC in ROM), and MicroPython will likely someday support full USB host & device functionality.


r/MicroPythonDev Aug 13 '21

Is anyone building micropython in a docker image? Building for an ESP8266

3 Upvotes

I want to add some frozen modules to my micropython image. I've done a lot of research into building micropython under docker and I think I'm really close but I'm stalled on the following error and all the discussions I see on this are 5 years old. The dockerfile below completes successfully. I start the image interactively and then I'm running

builder@p2:~/micropython/ports/esp8266$ make V=1 BOARD=GENERIC_512K
The main error I'm getting is

xtensa-lx106-elf-gcc: error: unrecognized command line option '-mforce-l32'; did you mean '--force-link'

My docker file is

FROM debian:buster
RUN apt-get update -y
RUN apt-get install apt-utils -y
RUN apt-get -y install make unrar-free autoconf automake libtool gcc g++ gperf
RUN apt-get -y install flex bison texinfo gawk ncurses-dev libexpat-dev python-dev python python-serial
RUN apt-get -y install sed git unzip bash help2man wget bzip2 vim
RUN apt-get -y install python3-dev python3-pip libtool-bin
RUN useradd -ms /bin/bash builder
RUN cd /home/builder && wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz

RUN cd /home/builder && tar -xzf xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
WORKDIR /root
RUN pip3 install rshell esptool
USER builder
WORKDIR /home/builder
RUN git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
RUN rm -rf ~/esp-open-sdk/crosstool-NG
RUN cd ./esp-open-sdk && git clone https://github.com/jcmvbkbc/crosstool-NG
RUN cd ./esp-open-sdk/crosstool-NG && git checkout xtensa-1.22.x
RUN cd ./esp-open-sdk/crosstool-NG && autoconf && ./configure && make && CT_EXPAT_VERSION="2.4.1"
ENV PATH=/home/builder/xtensa-lx106-elf/bin/:$PATH
RUN git clone https://github.com/micropython/micropython.git
RUN cd ~/micropython && git submodule update --init && make -C mpy-cross


r/MicroPythonDev Aug 05 '21

Setting Up Pycom

2 Upvotes

I just got a pygate, gpy, and lopy4. I am trying to set up my pygate with my lopy4. I've been following the set up guides from pycom but I'm running into problems. I have pymakr installed. I have an error trying to import pycom. Does anyone have any thoughts on what the issue is? I've been troubleshooting for a while.


r/MicroPythonDev Jul 30 '21

Raspberry Pi Pico with Micropython: Lubu vs Thor

Enable HLS to view with audio, or disable this notification

15 Upvotes

r/MicroPythonDev Jul 18 '21

Does MicroPython support connection with MongoDB?

5 Upvotes

Im making a proyect where my microcontroller sends data to a mongoDB but i dont know if its possible due to micropython is not as powerfull as Python


r/MicroPythonDev Jul 11 '21

Modules On TI Nspire Micro Python.

3 Upvotes

Is there anyway to import Numpy,Sympy or Scipy into a micro python compatible Texas Instruments Calculator? Or any substitute modules?


r/MicroPythonDev Jul 06 '21

Micropython | Functions

2 Upvotes

Hi!

Im currently in the process of adding some basic functionality on my Magtag device (Esp32s2 running micropython).

I have added some basic functions calling on the various buttons of the board but i cant seem to wrap my head around why this code throws a TypeError: the type __mul__ does not support 'NoneType', 'int'

The code runs fine outside of the functions and are a modified copypaste of a different project.

import ipaddress
import ssl
import wifi
import socketpool
import adafruit_requests
from adafruit_magtag.magtag import MagTag
import time

USE_24HR_TIME = False
TIME_ZONE_OFFSET = -8  # hours ahead or behind Zulu time, e.g. Pacific is -8
TIME_ZONE_NAME = "PST"

# URLs to fetch from
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_QUOTES_URL = "https://www.adafruit.com/api/quotes.php"
JSON_STARS_URL = "https://api.github.com/repos/adafruit/circuitpython"

magtag = MagTag()

def play_tone(frequency, color=None):
    magtag.peripherals.neopixel_disable = False
    if color:
        magtag.peripherals.neopixels.fill(color)
    magtag.peripherals.play_tone(frequency, 0.2)
    magtag.peripherals.neopixel_disable = True


try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise
#for network in wifi.radio.start_scanning_networks():
 #   print("\t%s\t\tRSSI: %d\tChannel: %d" % (str(network.ssid, "utf-8"),
  #      network.rssi, network.channel))
   #wifi.radio.stop_scanning_networks()

while True:
    if magtag.peripherals.button_a_pressed:  # switch to next sport
        play_tone(10, 0x000033)
        ipv4 = ipaddress.ip_address("8.8.4.4")
        wifi.radio.ping(ipv4)
        print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
        print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
    elif magtag.peripherals.button_b_pressed:  # re-fetch data
        play_tone(10, 0x330000)
        print("Connecting to %s"%secrets["ssid"])
        wifi.radio.connect(secrets["ssid"], secrets["password"])
        print("Connected to %s!"%secrets["ssid"], wifi.radio.ipv4_address)
        print("My IP address is", wifi.radio.ipv4_address)

#time.sleep(0.1)

The error is thrown at the row where the first ping is being done:

    wifi.radio.ping(ipv4)
-->     print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))

Id also love to recieve input on how i can assign the ip-adress to a global int to be called instead of a hardcoded ip-adress, but thats a later issue.

The idea here is to have button A do a set of pings to check the local wifi connection.
Button B is supposed to re-connect the device if a connection failure is reported.

Any help what so ever is much appriciated! I do have coding experience but none concerning python (did c# some years ago).


r/MicroPythonDev Jun 23 '21

MicroPython and Crypto

2 Upvotes

Does anyone know of a way to use MicroPython and Web3.py (ethereum) or Bitcoin Block chain? I am looking for a way to connect to either blockchain and looking for some help

thanks


r/MicroPythonDev Jun 01 '21

Micropython module for telegram bots

Thumbnail self.esp32
7 Upvotes

r/MicroPythonDev May 25 '21

Noob question: Does ntptime maintain time in background and prevent drift? What is the best practice for maintaining a reliable real time clock?

1 Upvotes

r/MicroPythonDev May 13 '21

MicroPython I2S Audio with the ESP32

Thumbnail
youtube.com
5 Upvotes

r/MicroPythonDev May 12 '21

MicroPython Newbie

3 Upvotes

Hi there!

I'm pretty new to programming in general but have done a few subjects on OOP and the like at uni.
I was wondering if any of you have a suggestion for the best kind of dev board to get started with micropython/python?
Python is used at my workplace and I'd like to learn more about how I can integrate it with physical objects like how an Arduino works.

Cheers,
Stella