Honey, I Shrunk The Arduino Core

High-level programming languages do a great job of making a programmer’s job easier, but these languages often leave a lot of efficiency on the table as a compromise. While a common thought is to move into a lower-level language like assembly to improve on a program’s speed or memory use, there’s often a lot that can be done at the high level before resorting to such extremes. This, of course, is true of the Arduino platform as well, as [NerdRalph] demonstrates by shrinking the size of the Arduino core itself.

[NerdRalph] had noticed that the “blink” example program actually includes over 1 kB of extraneous code, and that more complicated programs include even more cruft. To combat this issue, he created ArduinoShrink, which seeks to make included libraries more modular and self-contained. It modifies some of the default registers and counters to use less memory and improve speed, and is also designed to improve interrupt latency as well by changing when the Arduino would otherwise disable interrupts.

While there are some limits to ArduinoShrink, such as needing to know specifics about the pins at compile time, for anyone writing programs for Arduinos that are memory-intensive or need improvements in timing, this could be a powerful new tool. If you’d prefer to go in the opposite direction to avoid ever having to learn C or assembly, though, you can always stick with running Python on your embedded devices.

A Magnetic Field Strength Meter Using An Arduino

We’re used to Hall effect devices as proximity sensors in mechanical systems, used to provide detection of something that has a magnet attached to it. However it’s easy to forget that the devices that provide a magnet-or-not digital output are only part of the story, and linear Hall effect devices provide a handy way to measure a static magnetic field. It’s something [mircemk] demonstrates, with an Arduino-powered magnetic field strength meter that uses a UGN 3503U Hall effect device.

The circuit is extremely simple, comprising the sensor, an Arduino Nano, and an OLED display. This device is handy because its voltage output has a known relationship to the gauss level the sensor is experiencing, so while the accuracy of its calibration isn’t verified it can at least give a believable reading derived from the Arduino’s ADC.

The whole is wrapped up in an attractive case that looks as though it has been made from PCB material, with the sensor protruding on what seems to be the shell of a plastic ballpoint pen. It makes a handy instrument that provides a useful function for not a lot of money, so what’s not to like! Take a look at the video below the break for the full story.

Surprisingly such projects are few and far between here at Hackaday, however it’s not the first magnetic field measurement we’ve seen.

Continue reading “A Magnetic Field Strength Meter Using An Arduino”

Arduino CLI For I/O Pin Testing

Need to quickly toggle or read some logic signals without the hassle of writing a quick program? [Thor_x86], aka [Eric], built an Arduino sketch that does just that — and he threw in the ability to send (or receive) serial messages, too. This is a neat idea — kind of a simplified Bus Pirate.

We should warn you that this is an early release, and there are a few minor issues which we are sure [Eric] will iron out soon. We discovered the function strtol() was misspelled in cmd_send.cpp, and there are some configuration #defines which need to be sorted out in file parsePin.cpp, depending on which Arduino module you are running. We got it running on an Arduino Leonardo the quickest, because it has support for Serial1().

Don’t be discouraged by these glitches in this rev 0 deployment — [Eric] has really made quite a nice tool here. Check his GitHub repository for updates (or submit corrections yourself). All in all, it’s a good addition to your digital tool box. On a completely unrelated note, we really like [Eric]’s USB cable with the right-angle micro connector, grungy though it may be.

Besides the standard tools like Bus Pirate, GreatFET, FTDI modules, etc., are there any similar tools you like to use for bit banging and serial testing? Let us know in the comments below.

Arduino And FPGA Done Differently

FPGA guru [Max Maxfield] recently took a look at the XLR8 (pronounced accelerate) board from a company called Alorium. On the surface, it looks like another Arduino UNO clone. But instead of a CPU, it contains an Intel MAX10 FPGA that runs a softcore AVR processor. Of course, that’s only part of the story. If the board was just a mock Arduino using an FPGA, that’s not very interesting for practical purposes. However, by incorporating accelerator blocks or XBs, you can add FPGA modules to the soft CPU. [Max] shows an example that you can see in the video below where an FPGA block controls servos more easily than a standard Arduino. There’s also a version that looks like an Arduino Nano, but can clock much faster as well as use the XBs.

In addition to prebuilt XBs, there is a workflow to build your own if you are familiar with working with FPGAs. The products aren’t exactly new, but we enjoyed [Max’s] take on the product. We also appreciated the simple code examples showing exactly how you would convert a program to use the accelerated functions. Continue reading “Arduino And FPGA Done Differently”

Arduino Serial Vs SerialUSB

[Andrew] wonders why the SerialUSB() function on the Cortex M3-based Arduino Due is so much faster than Serial() on the Uno or Nano, and shares his observations in this short video. He sets up an experiment with a simple sketch on both boards and uses Wireshark to evaluate the results.

Data is sent in the USB packets in groups of four characters on the ATmega-based boards, but the entire string is put in a packet on the Due board. If you look under the hood, the answer is hiding in plain sight. While the Arduino family of boards connect to your computer using a USB virtual serial port, the ATmega ones have an actual serial connection on-board. For instance, on the Nano there is an FT232RL between the USB connector and the microprocessor (on an Arduino Uno board, a small ATMEGA8U2 is used instead of an FTDI chip, but the concept is the same). On the Arduino Due, the USB connects directly to the SAM3X8E processor.

This concept doesn’t apply only to Arduino boards, of course. On any serial connection between two computers, when a virtual USB device is used on both sides of the link (no actual serial signals involved), the serial baud rate is a fictional thing — data transfer speeds depends on USB alone. We are curious why the packets contain four characters in [Andrew]’s ATmega Wireshark captures — why not 1, 2, or 10? Is this something that can be controlled by the programmer, or is it fixed by the protocol and/or the FTDI chip? If you have the answer, let us know in the comments below. Continue reading “Arduino Serial Vs SerialUSB”

Interfacing The Dreamcast Controller With Just An Arduino

The Dreamcast is a somewhat forgotten console today, but for a shining minute in the late 1990s, it was possible to believe Sega were still in the fight. Regardless, their hardware lives on, lovingly preserved by collectors and enthusiasts. [Nicholas FitzRoy-Dale] is one such enthusiast, and set about interfacing the old console’s controllers to an Arduino.

Initial work involved getting the Arduino (presumably a basic 16 Mhz Uno) to read the controller’s buttons, and spitting the data out over serial. The Dreamcast’s Maple bus is fast, which presented some challenges, but it was simple enough. [Nicholas] then moved on to interfacing the VMU, the Dreamcast’s fancy controller-mounted memory card. After initial attempts were shaky and unstable, he redoubled his efforts. Research indicated that the VMU can vary the speed of the bus when it’s in control, so he updated his code to suit. It’s full of great hacks, like connecting the Dreamcast’s two data pins to four input pins on the Arduino, to save a handful of cycles by not having to shift incoming data.

The work is a great read for anyone into assembly-level optimisation of interfaces, as well as proper use of limited resources. Obviously, it’s easy to just throw a faster, more expensive microcontroller at the problem, but then nobody would have learned anything. We’ve featured a great many Dreamcast hacks over the years; [Nicholas]’s work here builds upon [Dmitry]’s work in 2017. We can’t wait to see what comes next out of the underground Sega hacking scene!

Running 57 Threads At Once On The Arduino Uno

When one thinks of the Arduino Uno, one thinks of a capable 8-bit microcontroller platform that nonetheless doesn’t set the world alight with its performance. Unlike more modern parts like the ESP32, it has just a single core and no real multitasking abilities. But what if one wanted to run many threads on an Uno all at once? [Adam] whipped up some code to do just that.

Threads are useful for when you have multiple jobs that need to be done at the same time without interfering with each other. The magic of [Adam]’s ThreadHandler library is that it’s designed to run many threads and do so in real time, with priority management as well. On the Arduino Uno, certainly no speed demon, it can run up to 57 threads concurrently at 6ms intervals with a minumum timing error of 556 µs and a maximum of 952 µs. With a more reasonable number of 7 threads, the minimum error drops to just 120 µs.  Each thread comes with an estimated overhead of 1.3% CPU load and 26 bytes of RAM usage.

While we struggle to think of what we could do with more than a handful of threads on an Arduino Uno, we’re sure you might have some ideas – sound off in the comments. ThreadHandler is available for your perusal here, and runs on SAMD21 boards as well as any AVR-based boards that are compatible with TimerOne. We’ve seen other work in the same space before, such as ChibiOS for the Arduino platform. Video after the break.

Continue reading “Running 57 Threads At Once On The Arduino Uno”