Vista Normal

Hay nuevos artículos disponibles. Pincha para refrescar la página.
AnteayerSalida Principal

USB Dongle Brings Python-Controlled GPIO to the Desktop

6 Junio 2024 at 05:00

Microcontroller dev boards are wonderfully useful items, in testament to which most of us maintain an ample collection of the things. But dragging one out to do a simple job can be a pain, what with making sure you have the whole toolchain set up to support the device, not to mention the inevitable need to solder or desolder header pins. Wouldn’t it be nice if there was a simple plug-and-play way to add a few bits of GPIO to your desktop or laptop machine?

[Nick Bild] thinks so, and came up with the USBgpio. The hardware in the dongle is pretty much what you’d expect — an Arduino Nano 33 IoT. Yes, you could just bust out a Nano and do this yourself, but [Nick] has done all the heavy lifting already. Eleven of the Nano’s IO pins plus 3.3V and ground are broken out to header pins that stick out of the 3D-printed enclosure, and the dongle is powered over the USB cable. [Nick] also built a Python library for the USBgpio, making it easy to whip up a quick program. You just import the library, define the serial port and baud rate, and the library takes care of the rest. The video below shows a quick blinkenlight test app.

Earth-shattering stuff? Perhaps not; [Nick] admits as much by noting the performance doesn’t really dazzle. But that’s hardly the point of the project, and if you need a couple of pins of IO on the desktop for a quick tactical project or some early-stage prototyping, USBgpio could be your friend.

MicroPython 1.23 Brings Custom USB Devices, OpenAMP, Much More

2 Junio 2024 at 14:00
A screenshot of the release page, showing the headline and a crop of the release notes

MicroPython is a wonderful Python interpreter that runs on many higher-end microcontrollers, from ESP8266 to STM32 to the RP2040. MicroPython lets you build devices quickly, and its latest release, 1.23, brings a number of improvements you should be aware of.

The first one is custom USB device support, and it’s a big one. Do you want to build HID devices, or play with MIDI, or do multiple serial streams with help of PIO? Now MicroPython lets you easily create USB devices on a variety of levels, from friendly wrappers for creating HID or MIDI devices, to low-level hooks to let you define your own USB descriptors, with user-friendly libraries to help all the way through. Currently, SAMD and RP2040 ports are supported in this part of code, but you can expect more in the future.

Hooray to 10 years of MicroPython!

There’s more – support for OpenAMP, an inter-core communication protocol, has received a ton of improvements for systems where MicroPython reigns supreme on some of the CPU cores but also communicates with different systems on other cores. A number of improvements have made their way through the codebase, highlighting things we didn’t know MicroPython could do – for instance, did you know that there’s a WebAssembly port in the interpreter, letting you run MicroPython in your browser?

Well, it’s got a significant overhaul in this release, so there’s no better time to check it out than now! Library structure has been refactored to improve CPython compatibility, the RP2040 port receives a 10% performance boost thanks to core improvements, and touches upon areas like PIO and SPI interfaces.

We applaud all contributors involved on this release. MicroPython is now a decade old as of May 3rd, and it keeps trucking on, having firmly earned its place in the hacker ecosystem. If you’ve been playing with MicroPython, remember that there are multiple IDEs, graphics libraries, and you can bring your C code with you!

Don’t Object to Python Objects

3 Mayo 2024 at 02:00

There’s the old joke about 10 kinds of programmers, but the truth is when it comes to programming, there are often people who make tools and people who use tools. The Arduino system is a good example of this. Most people use it like a C compiler. However, it really uses C++, and if you want to provide “things” to the tool users, you need to create objects. For example, when you put Serial in a program, you use an object someone else wrote. Python — and things like Micropython — have the same kind of division. Python started as a scripting language, but it has added object features, allowing a rich set of tools for scripters to use. [Damilola Oladele] shows the ins and outs of object-oriented Python in a recent post.

Like other languages, Python allows you to organize functions and data into classes and then create instances that belong to that class. Class hierarchies are handy for reusing code, customizing behavior, and — through polymorphism — building device driver-like architectures.

For example, you might build a class for temperature sensors and then create specialized subclasses for different specific sensors. The code to convert the sensor reading to degrees would live in each subclass. However, common code, such as getting an average of several samples, could be used in the main class. Even more importantly, any part of your code that needs a temperature sensor will just deal with the main class and won’t care what kind of sensor is actually in use except, of course, when you instantiate the sensor.

Python’s implementation of object orientation does have a few quirks. For example, if you create a class variable, it can be read from a subclass without specifying scope like you’d expect. But if you try to write to it from a subclass, you create a new variable for that particular subclass, which then hides the parent class version.

Still, objects can make your tools and libraries much more reusable, and Python makes it relatively easy compared to some other languages. If you want to see how objects can improve common constructs like state tables, you’ll have to read a different language. If you want to see an admittedly hairy Python example, check out VectorOS, the operating system for the 2023 Hackaday Supercon badge.

Refraction

Por: EasyWithAI
10 Octubre 2023 at 15:39
Refraction is an AI-powered code generation tool for developers that refactors code, generates documentation, creates unit tests, and more. It uses AI to automatically generate code in over 50 programming languages including Python, HTML, JavaScript, C++, and more. Developers simply paste their code into Refraction, select the task they want to automate, and hit “Generate” […]

Source

❌
❌