MicroPython | 大叔教你玩板子系列代码仓库 -
kandi X-RAY | MicroPython Summary
kandi X-RAY | MicroPython Summary
MicroPython
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Pause firmware update .
- Relocation of a symbol .
- Freeze constant object .
- Creates a section of the code object .
- Reads the contents of a DFU file .
- Build MPY output .
- Read the raw code .
- Write data to the device .
- Convert from UF2 format to bytes .
- Initialize the LSM device .
MicroPython Key Features
MicroPython Examples and Code Snippets
Community Discussions
Trending Discussions on MicroPython
QUESTION
I am trying to get my robot to communicate with my PC via sockets by using local IP addresses on my own home network (not devices outside my network). The robot is acting as the server and my own PC is acting as the client/host. I don't really know what ports are open on my robot but I do definitely know that port 22 on the robot is open (which is the SSH port). The robot is a lego EV3 robot apart from it has had some ev3python software put onto it. When I run my program I am getting the following error on the server (my robot):
...ANSWER
Answered 2021-Jun-14 at 12:24hostIPAddress = "xx.xx.xx.xx" #the local IP address of my PC on my home network
backlog = 1
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((hostIPAddress,22))#22 is the port number I am using. (THIS IS ALSO THE LINE WHERE THE ERROR IS COMING FROM)
s.listen(backlog)
QUESTION
I started several attempts to get this complex working. As mentioned in so many other discussions the micropython modules are not recognized, e.g. machine. Python modules like numpy were also not found.
I think, the python environment is not working correctly and the modules are there but not found. But, there is no recommendation or tutorial that really solves this. How can I set this up?
What I did so far:
manually installed all components according to tutorials
another way: installed the pything coding pack which contains a lot of stuff.
The Windows paths have the correct folder paths to the components.
I set the obviously correct python interpreter in vscode
connection/communication with board is working. I can set up codes which dont contain micropython modules.
in other IDE's like thonny/mu the modules are found.
I also installed a python venv: I could install numpy inside this venv and later it was found in vscode (wasn't found before) when I used the venv python as interpreter in vscode. But I wasn't succesful with micropython in venv.
PS: I can use the micropython modules like machine or network and upload the sketch to the esp32 board. It is working on the board. But I cant run any of the sketches in vscode. I think that Vscode uses cpython instead of micropython but shouldn't this be working after the installations I mentioned?
...ANSWER
Answered 2021-May-24 at 00:00It sounds like you're confusing modules you install on the machine running Visual Studio Code and modules you install in Micropython on the ESP32.
They're totally separate.
Python on your Windows machine can use venv.
MicroPython doesn't use venv at all (there apparently is a clone of venv for MicroPython but it's not readily apparent what it does or why or how you'd use it). It is a completely separate instance of Python from the one on your Windows machine, and it doesn't operate the same way. Modules you install under venv won't be visible or usable by MicroPython. Numpy in particular is not available for MicroPython.
Many modules need to be written specially to work with MicroPython. MicroPython isn't running in a powerful operating system like Windows, MacOS or Linux. It's running in a highly constrained environment that lacks much of the functionality of those operating systems, and that has extremely little memory and storage compared to them. You can't expect that a module written for regular Python will just work on MicroPython (and likewise, many MicroPython modules use hardware features like I2C or SPI access that may not be available on more powerful, general purpose computers).
Only modules available with upip
will be available for MicroPython. They'll need to be installed in the instance of MicroPython running on the ESP32, not in the instance of Python running under Windows. They're two, totally separate instances of Python.
QUESTION
I am currently using an SRF-10 sensor connected to an esp32. It's being powered by 5V and I am using a level converter to bring down the voltage to 3.3V to be able to use it on the esp32. Both the SCL and SDA have a 1.8K pull up resistor as recommended on the datasheet.
I have written the following script to try to get a read from the sensor. I am not entirely sure if it is correct but soon as it reaches line 16 I get an error saying [Errno 19] ENODEV. Eveything I could find suggests that the i2c connection isn't working properly but when I run i2c.scan()
it returns the sensor address so I am guessing connections aren´t the problem.
My script is as follows:
ANSWER
Answered 2021-May-26 at 22:27The proper use of i2c.writeto_mem
requires the following order of arguments:
QUESTION
I am a software engineer working on a microcontroller system for a side project. The microcontroller I am using is the SparkFun ProMicro (based on the RP2040 board). I am trying to flash the board so that I can write data to the onboard flash memory.
All of the tutorials I have found online suggest starting in boot mode, dragging and dropping the UF2 file, and done!
When I do this, the microcontroller ejects from my computer. Is that meant to happen? It just reboots then doesn't reboot in bootloader?
Once I got MicroPython installed I moved on to writing and flashing code to the board.
I am using the Thonny IDE which identified the correct board (albeit the PICO), then saved the following file as main.py (taken from RPI foundation). It prints toggle, and I believe the output shows that it is being printed from the board, but the light on the board isn't blinking. (code and output below)
I considered that the pinout could be different from this board and the PICO, but some research shows they both use Pin 25 for the LED control.
All this leads me to believe I am on the right path, but I think I am missing something that is taken for granted in the tutorials. My end goal is to write arbitrary text data to flash storage, but I understand it can only take about 8000-10,000 writes before it becomes unreliable, so I want to test that I can write working code before I use some of those.
Is there something I am missing, or am I not thinking about this in the right way?
...ANSWER
Answered 2021-May-18 at 03:31When I do this, the microcontroller ejects from my computer. Is that meant to happen? It just reboots then doesn't reboot in bootloader?
Yep.
but the light on the board isn't blinking.
Maybe your LED is busted, cause your code is right.
My end goal is to write arbitrary text data to flash storage
That's a terrible idea, unless you just like burning up boards for no good reason. Get an SD Card reader or concoct one out of a solution like this one, and use this sdcard library that will even mount your card, and add it to the syspath
. Then you can essentially write all the arbitrary text data you like without burning up your RP2040.
QUESTION
I'm using Pymakr on VScode to program a Pycom L01, which is connected to several sensors.
i'm trying to use smbus2 library, but i can't import it.
I created a python virtual enviroment and installed it using 'pip install smbus2', but when i try to upload the sketch, the output is:
ANSWER
Answered 2021-May-19 at 08:41May be You have not installed smbus2 module. Please install it and import it in your program.
QUESTION
I am using the latest stable release of micropython and below is my entire program.
...ANSWER
Answered 2021-Apr-27 at 15:55It appears that 64kb of RAM are automatically allocated to fit the firmware.elf
. So, not only do you not actually get 264k of RAM (due to Hypervisor using 8k), but you don't get 256k of RAM either. Changing the edit in my question to:
QUESTION
I want to do a Python implementation (actually MicroPython) of a specific checksum calculation based on CRC16-CCITT. It will be used on a microcontroller to check data integrity over a serial connection.
The algorithm is available as C implementation.
The checksum is a 16 bit, type CCITT. The checksum starts at the first byte of the message. Sample code to calculate the CRC16 CCITT in the C language:
...ANSWER
Answered 2021-Apr-15 at 20:55The CRC implemented in the provided Python code is not the CCITT CRC-16. It is referred to interestingly as a false CCITT CRC-16 in this catalog. The CRC implemented in the provided C code is in fact the CCITT CRC-16.
The Python code is easily modified to reflect the correct definition:
QUESTION
I'm writing a Windows Forms application in C# that allows a user to connect to a microcontroller and upload program files via FTP.
I can successfully upload program files via Filezilla. But when I run the code below I receive the error "The remote server returned an error: (451) Local error in processing." at the line "ftpstream.Close();" every single time no matter what file I try to upload, regardless of size or file type, and the new file does show up in Filezilla on the FiPy but with a size of 0 bytes.
I've erased all program files on the microcontroller so I know storage space is not the issue and I don't think its a firewall issue since I can upload successfully through Filezilla.
The WebException thrown shows no extra details in the InnerException and the StatusDescription comes back as an empty string.
I posted this question to the forum for the specific microcontroller I'm using but didn't get a solution. Here's the link to that post, it includes FTP logs and some solutions that were tried in the comments: https://forum.pycom.io/topic/6937/fipy-ftp-upload-in-c-returns-451-local-error-in-processing
I've exhausted all google results.
Can anyone help me out?
My code:
...ANSWER
Answered 2021-Apr-13 at 17:42I got it to work with FluentFTP. I'm not 100% sure what the issue was, maybe using CWD fixed it, maybe some underlying logic/command in FluentFTP handled it better, either way, the FTP log now more closely matches the one from Filezilla and no more errors!
My New Code:
QUESTION
I recently started working on a small driver for the raspberry pico and the bme280 sensor. I wanted to use the official bosh API written in C and therefore decided to write all the code in C using the micropython C api to write usermodules. I managed to get my code compiled into a UF2 file and my module shows up when I try to list the modules with help('modules')
. When I import my module the class with the driver code shows up in dir(mymodule)
but when I try to create an object the terminal connected to the PICO hangs and doesn't respond anymore.
ANSWER
Answered 2021-Apr-06 at 08:58You have .print
defined but it doesn't exist in your code.
QUESTION
I have the following code. I want to run it on an ESP32. The MicroPython is already installed. The problem is that nothing happens. I get no errors but the testThread() method is not called at any time. I really don't know where the problem lies.
Thank you in advance for your answers.
Code:
...ANSWER
Answered 2021-Apr-06 at 03:34Same problem with esp32 thread execution - no output from thread function invoking a print statement. Not only that when the thread exited it crashed the esp32.
However, I fortunately had another esp32 and the threaded function worked as expected, output was printed to the repl.
The problem seems to be the latest version of micropython which can be checked by executing uos.uname()
.
The working version 1.12.0
while version 1.14.0
fails.
The uname
output:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install MicroPython
You can use MicroPython like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page