Posts with «arduino hacks» label

Secret Serial Port for Arduino/ESP32

If you use the Arduino IDE to program the ESP32, you might be interested in [Andreas Spiess’] latest video (see below). In it, he shows an example of using all three ESP32 UARTs from an Arduino program. He calls the third port “secret” although that’s really a misnomer. However, it does require a quick patch to the Arduino library to make it work.

Just gaining access to the additional UARTs isn’t hard. You simply use one of the additional serial port objects available. However, enabling UART 1 causes the ESP32 to crash! The reason is that by default, UART 1 uses the same pins as the ESP32 flash memory.

Luckily, the chip has a matrix switch that can put nearly any logical I/O pin on any physical I/O pin. [Andreas] shows how to modify the code, so that UART 1 maps to unused pins, which makes everything work. it is a simple change, replacing two parameters to a call that — among other things — maps the I/O pins. You could use the technique to relocate the UARTs to other places if you choose.

If you want to learn more about the ESP32, we covered a good set of tutorials for you to check out. Or if you just want a quick overview, you can start here.


Filed under: Arduino Hacks, ARM
Hack a Day 17 Aug 16:30

Visual Development with XOD

Early programmers had to represent code using binary, octal, or hex numbers. This gave way quickly to representing programs as text to be assembled, compiled, or interpreted by the computer. Even today, this remains the most common way to program, but there have been attempts to develop more visual ways to create programs graphically. If you program microcontrollers like the Arduino, you should check out XOD and see how you like visually creating software. The software is open source and currently, can target the Arduino or Raspberry Pi.

You can launch the IDE in a web browser or download a local copy. You transfer nodes from a palette into a grid-like workspace. These nodes might be inputs, outputs, processing blocks, or represent real-world I/O devices. Nodes have inputs and outputs of specific types and you connect them together, connecting like types only, although there are blocks that can convert.

For example, to the right is a simple set of nodes that forms the prototypical flashing LED program. A clock node creates a pulse that toggles a memory element and a digital output accepts both the signal and a constant value indicating which port it represents.

This is a simple example, but it does show the intuitive flow of joining nodes. There is a reasonable array of node types and sufficient documentation.

There are out-of-the-box nodes for ultrasonic sensors, temperature sensors, servos, LCDs, buttons, and H-bridges. You can create your own super-nodes (patches) and you also can make multiple disjointed flows to execute more than one task at a time.

When you generate the code you get a lot of boilerplate that sets up the run time system and the nodes you use. Your main code appears to be in an evaluate function. For example, here’s a snippet of the code that corresponds to the simple graphical blink program:

void evaluate(Context ctx) {
State* state = getState(ctx);
TimeMs tNow = transactionTime();
TimeMs dt = getValue<input_IVAL>(ctx) * 1000;
TimeMs tNext = tNow + dt;

if (isInputDirty<input_RST>(ctx)) {
if (dt == 0) {
state->nextTrig = 0;
clearTimeout(ctx);
} else if (state->nextTrig < tNow || state->nextTrig > tNext) {
state->nextTrig = tNext;
setTimeout(ctx, dt);
}
} else {
// It was a scheduled tick
emitValue<output_TICK>(ctx, 1);
state->nextTrig = tNext;
setTimeout(ctx, dt);
}
}

There are a few rough edges, which isn’t surprising for new software. For one thing, nodes have fixed numbers of inputs and outputs. So if you want, for example, a ten-input AND gate, you’ll have to build it. Another apparent issue is there is no way we found to select a lot of items at once. If you decide you want to move a whole bunch of nodes down to make room for something new, you are going to be in for a lot of work.

There are other drag-and-drop programming languages, of course. We’ve covered Scratch for the Arduino and the Raspberry Pi, before. However, this is a dead simple way to try flow-based programming with minimal setup.


Filed under: Arduino Hacks, Raspberry Pi

ATMega328 3D!

Small OLED displays are inexpensive these days–cheap enough that pairing them with an 8-bit micro is economically feasible. But what can you do with a tiny display and not-entirely-powerful processor? If you are [ttsiodras] you can do a real time 3D rendering. You can see the results in the video below. Not bad for an 8-bit, 8 MHz processor.

The code is a “points-only” renderer. The design drives the OLED over the SPI pins and also outputs frame per second information via the serial port.

As you might expect, 3D output takes a good bit of math, and the chip in question isn’t very good at handling real numbers. [Ttsiodras] handles this using an old technique: fixed point arithmetic. The idea is simple. Normally, we think of a 16-bit word as holding unsigned values of 0 – 65535. However, if you choose, you can also use it to represent numbers from 0-50.999, for example. Mentally, you scale everything by 1,000 and then reverse the operation when you want to output. Addition and subtraction are straightforward, but multiplication and division require some extra work.

If you want to read more about fixed point math, you are in the right place. We’ve also covered a great external tutorial, too. But if you think this is the first time we’ve covered a 3D graphics engine for the ATmega parts, you’re wrong.


Filed under: Arduino Hacks

Mini Hacker Breaks Down How To Build It

I read the other day that the hot career choice for kids these days is: YouTuber. That means every kid — yes, including mine — has two or three attempts at a YouTube show on their account and then they get into the next big thing and forget about it. On the other hand, sometimes you find someone who has a lot of ideas to share, and the dedication to keep sharing them.

[Kevin Zhou], an 11-year-old from Indonesia, has filmed around  70 videos in the past couple of years, with a fantastic variety of nerdy projects ranging from Mindstorms to Arduino to wood shop projects, and even a Blender tutorial. His projects show a lot of complexity, with serious, real-world concepts, and he shares the technical details about the various components in the project, and he walks you through the code as well.

He made a Mindstorms carving machine, pictured above, with a gantry system holding a motor steady while the user carves into a block of floral foam with LEGO bits. He does a lot of home automation projects using an Arduino and relay board, as well as a number of water-pumping robots. He doesn’t stick to one medium or technology. He has a jigsaw and in one video he shows how to build a Thor’s hammer out of wood. He prints out each layer’s design on office paper and glues the paper to a piece of wood, cutting out the cross-sections on his jigsaw. The whole stack is glued together and clamped. [Kevin]’s design featured a hollow space inside to save weight, which he cut by drilling a 1-inch hole in the center with his drill press, then threading the jigsaw blade through the hole to cut out the inside. As an amateur woodcrafter myself, I like seeing him branching out working on small wood projects.

[Kevin]’s full automatic water dispenser is one of a series of water-pumping projects including a couple of plant-watering robots. [Kevin] uses a relay-triggered pump and a water-level sensor, all running on an Arduino Mega plugged into a 1360-point breadboard.

He has a lot of common modules. He uses a LED display plugged directly into the breadboard, with its backpack plugged into same rows so it can lay flat. He plays around with an IR remote, as well as a 12 V / 5 A Peltier thermo-electric cooler running off of a relay. He has a couple of different relay boards making for a number of home automation projects, including a fairly complicated security system featuring RFID and keypad entry.

There are many LEGO and Mindstorms projects as well, including a complicated robot arm controlled by a smartphone app, as well as a Technic beam sorter that rolls the beams down a conveyor so that shorter elements fall through smaller holes, while longer pieces continue on to fall in larger holes down the line. Intriguingly to me, he did a couple of projects involving mixing Arduinos and LEGO/Mindstorms, and frequently uses the building set to build enclosures and support structure.

I suppose you could say the individual projects aren’t that challenging–connecting a relay board to an Arduino, for instance. All of these parts are fairly simple to run individually but together show he’s been working at this for a long time: 70 videos. A DIY security system is a far cry from turning on a LED.

Besides, I like how [Kevin] finishes projects, then riffs off of them. He tries out a few variants in a row, making changes and improvements. I just hope he keeps building–I can’t imagine what he’ll be making fifteen years from now.

Check out some of his videos:


Filed under: Arduino Hacks, Featured

False Claims On Kickstarter: What’s New?

Kickstarter and its ilk seem like the Wild West when it comes to claims of being “The world’s most (Insert feature here) device!” It does add something special when you can truly say you have the world record for a device though, and [MellBell Electronics] are currently running a Kickstarter claiming the worlds smallest Arduino compatible board called Pico.

We don’t want to knock them too much, they seem like a legit Kickstarter campaign who have at time of writing doubled their goal, but after watching their promo video, checking out their Kickstarter, and around a couple of minutes research, their claim of being the world’s smallest Arduino-compatible board seems to have been debunked. The Pico measures in at an impressive 0.6 in. x 0.6 in. with a total area of 0.36 sq.in. which is nothing to be sniffed at, but the Nanite 85 which we wrote up back in 2014 measures up at around 0.4 in. x  0.7in. with a total area of around 0.28 sq.in.. In this post-fact, fake news world we live in, does it really matter? Are we splitting hairs? Or are the Pico team a little fast and loose with facts and the truth?

There may be smaller Arduino compatible boards out there, and this is just a case study between these two. We think when it comes to making bold claims like “worlds smallest” or something similar perhaps performing a simple Google search just to be sure may be an idea.


Filed under: Arduino Hacks, Crowd Funding

KIM-1 to COSMAC Elf Conversion — Sort Of

In the mid-1970s, if you had your own computer, you probably built it. If you had a lot of money and considerable building skill, you could make an Altair 8800 for about $395 — better than the $650 to have it built. However, cheaper alternatives were not far behind.

In 1976, Popular Electronics published plans for a computer called the COSMAC Elf which you could build for under $100, and much less if you had a good junk box. The design was simple enough that you could build it on a piece of perf board or using wire wrap. We featured the online archive of the entire Popular Electronics collection, but hit up page 33 of this PDF if you want to jump right to the article that started it all. The COSMAC Elf is a great little machine built around a 40-pin RCA 1802 processor, and for many was the first computer they owned. I lost my original 1802 computer in a storm and my recent rebuild in another completely different kind of storm. But there is a way to reclaim those glory days without starting from scratch.  I’m going to repurpose another retro-computing recreation; the KIM-1.

I’ll admit it, Rewiring a real KIM-1 to take an 1802 CPU would be difficult and unnecessary and that’s not what this article is about. However, I did have a KIM UNO — [Oscar’s] respin of the classic computer using an Arduino mini pro. Looking at the keyboard, it occurred to me that the Arduino could just as easily simulate an 1802 as it could a 6502. Heck, that’s only two digits different, right?

The result is pretty pleasing. A “real” Elf had 8 toggle switches, but there were several variations that did have keypads, so it isn’t that far off. Most Elf computers had 256 bytes of memory (without an upgrade) but the 1802 UNO (as I’m calling it) has 1K. There’s also a host of other features, including a ROM and a monitor for loading and debugging programs that doesn’t require any space in the emulated 1802.

Repurpose

The KIM UNO has 24 switches. There are 16 for the hex digits, of course. The top two rows mimic functions from the original KIM-1. A real Elf had a way to input a byte (usually 8 toggle switches), a load switch, a run switch, a memory protect switch, and a push button wired to a CPU pin. That means the hardware has more than enough switches.

On the display side, a normal Elf had a single-byte hex display although some clones had more. There was also the Q LED that a program could light or extinguish. The KIM UNO hardware has many 7-segment displays so it is possible to put those digits to use like an Elf clone. There isn’t an LED, however, except for the Arduino’s built in LED which is not normally visible in operation. However, the digital displays have decimal points and they are connected to the Arduino. So if you don’t mind using those, you have plenty of LEDs, too.

The hardware is open source and easy to duplicate. [Oscar] sometimes has kits as well and they are very inexpensive (about $20).

The KIM UNO software is open source, so I started there. I first stripped all the code out of the main file other than the parts that drove the display and the keyboard, then built up everything need to suppot 1802 emulation. You can find all the code in my 1802UNO GitHub repository.

Inside the 1802

The 1802 instruction set is very regular and quite simple. Most instructions use the top 4 bits as an op code and the bottom 4 bits to select one of sixteen 16-bit registers. So 0x12 increments register 2 and 0x15 increments register 5. There are only a handful of op codes that don’t follow this pattern. There’s also an 8-bit accumulator called “D” (not to be confused with register D).

One unique feature in the 1802 architecture is the program counter. There isn’t one. Well, more precisely, there are up to 16. Any of the registers can be the program counter and a subroutine call can be as simple as switching the program counter. Unfortunately, that isn’t very reentrant (or good for recursion). If you want a proper subroutine call, you had to code it yourself. RCA provided the “standard call and return technique” that had the unfortunate downside of destroying the accumulator.

With so few instructions, the emulator turns out to be a few switch statements and some pretty simple code. Although it is made to run with the KIM UNO hardware, like the KIM UNO, you should be able to use it with just about any Arduino via the serial port. It isn’t quite as fun as having the real hardware, but it is simpler.

Unreal

The emulator is reasonably accurate except it doesn’t simulate interrupts (since there is no source of them). However, it doesn’t faithfully reproduce the 1802’s load mode which used DMA. Instead, load mode is just completely custom code that enters data into memory. It does not simulate the cycle and register manipulations that go on in a real 1802 using DMA in load mode.

In addition to loading a program with the ersatz load mode, you can also move RAM back and forth to EEPROM or a PC via the serial port.

Serial and Push Buttons

The serial port is just the usual Arduino serial port set for 9600 baud. By default, the serial input will mimic the hardware keys. However, you can use the pipe character (‘|’) to shift the serial port into terminal mode. Then the 1802 code can read data from the serial port. You lose the front panel functions and there’s no way to go back until you cycle the power unless you make the 1802 code release the port.

A few of the push buttons have special functions if you hold them down for more than one second. For example, the AD button writes the EEPROM data into RAM. This is useful for storing a self-contained demo, for example.

You can find a summary of the keyboard and serial commands on the GitHub site. The serial port can do things you can’t do from the front panel, like set a trace mode, dump the CPU registers, and more.

Building

The hardware doesn’t require any changes to the stock KIM UNO kit. There’s a lot to solder and once you solder the displays on, it would be hard to get the Arduino back off the board.

You could probably build the software using the Arduino IDE, but I used Platform IO. That lets me use the editor of my choice, but you ought to be able to get the code to work in the IDE, as well. There is enough memory to make the RAM slightly bigger, but I didn’t do it. Since one way to save and load the RAM is to EEPROM, I didn’t want the RAM to be larger than the EEPROM. In addition, the RAM “maps” like a real Elf (that is, RAM at location 0x0 also appears at 0x4000, 0x8000, etc). This would be more difficult if you added a little bit more than 1K of RAM.

There are a few other options at the top of 1802config.h. You can select how often the screen and keyboard refresh. Higher values are slower to refresh but faster to execute code. You can change the I/O ports associated with the keyboard, displays, and serial port. You can also change the serial escape character.

Examples

There are some examples provided that blink the LEDs and manipulate the serial port. If you look around, there’s a lot of 1802 code on the web. However, be aware that most 1802s don’t have a hardware UART. They emulate serial ports using the Q output and one of the EF inputs. That’s fine for a real device even though it takes lots of code, but for this virtual device, it isn’t practical. You’ll need to rip out any code that does serial I/O and replace it with single I/O instructions.

If you have a binary file (or a format you can convert to binary) I have a converter written in C included on GitHub. You can compile it on nearly any platform and use it to convert. It always assumes address. If that’s not right, you can always open the output in a text editor and adjust.

In addition, there are three ROMs included that you can try. By default, there is a simple high-low game. There are also two monitors, one for use with the built-in keyboard and another for use with a serial port. To select a ROM, edit 1802rom.h and change the comments so the ROM you want is not commented and the others are.

Practical?

Emulators are fun, but as the song goes, there’s nothing like the real thing. If that’s not authentic enough for you, it is possible to build a very authentic looking Elf, even today. The reason real 1802s are still around is they had several desirable characteristics, namely low power consumption and resistance to radiation.

The Arduino simulation has neither of those features. However, it is a fun retrocomputing toy, inexpensive, and a great learning tool. The CPU is simple enough to program directly in machine code and the portability is better than most other old school computers.

If you want to learn more about the 1802 there are several sites dedicated to it and a very helpful Yahoo group. One site has a very prolific software author, but most of the code won’t fit in the 1802 UNO’s 1K RAM. Maybe a version with more memory is in the future.


Filed under: Arduino Hacks, classic hacks, computer hacks, Hackaday Columns

Play it Again, Arduino

[MrRedBeard] wanted to play a particular song from an Arduino program and got tired of trying to hand transcribe the notes. A little research turned up that there was a project to convert Music XML (MXL) files to the Arduino. However, [MrRedBeard] wasn’t a fan of the language it used, so he created his own means of doing the same thing. He learned a lot along the way and was willing to share it in a tutorial that will help you if you want to do the same thing. You can see a video of his results, below.

Of course, MXL files are probably not better than sheet music if you had to create them by hand. Luckily, there’s a large collection of them available online and the song of interest was there. Note that the link in [MrRedBeard’s] post erroneously has the site as a .com instead of a .org, so you’ll want to use the link here instead of there.

A C# application reads the MXL file and converts it for use on the Arduino. There’s also sample code for the Arduino to get you started.

The project that inspired him is on GitHub and uses Ruby if that suits you better. We’ve talked about MXL before, by the way. If you want to integrate multi channel music on the Arduino, you might start here.


Filed under: Arduino Hacks, musical hacks
Hack a Day 23 Jul 09:00

JPEG Decoding, Arduino Style

When you think of image processing, you probably don’t think of the Arduino. [Jan Gromes] did, though. Using a camera and an Arduino Mega, [Jan] was able to decode input from an Arduino-connected camera into raw image data. We aren’t sure about [Jan’s] use case, but we can think of lots of reasons you might want to know what is hiding inside a compressed JPEG from the camera.

The Mega is key, because–as you might expect–you need plenty of memory to deal with photos. There is also an SD card for auxiliary storage. The camera code is straightforward and saves the image to the SD card. The interesting part is the decoding.

The use case mentioned in the post is sending image data across a potentially lossy communication channel. Because JPEG is compressed in a lossy way, losing some part of a JPEG will likely render it useless. But sending raw image data means that lost or wrong data will just cause visual artifacts (think snow on an old TV screen) and your brain is pretty good at interpreting lossy images like that.

Just to test that theory, we took one of [Joe Kim’s] illustrations, saved it as a JPEG and corrupted just a few bytes in a single spot in it. You can see the before (left) and after (right) picture below. You can make it out, but the effect of just a few bytes in one spot is far-reaching, as you can see.

The code uses a library that returns 16-bit RGB images. The library was meant for displaying images on a screen, but then again it doesn’t really know what you are doing with the results. It isn’t hard to imagine using the data to detect a specific color, find edges in the image, detect motion, and other simple tasks.

Sending the uncompressed image data might be good for error resilience, but it isn’t good for impatient people. At 115,200 baud, [Jan] says it takes about a minute to move a raw picture from the Arduino to a PC.

We’ve seen the Arduino handle a single pixel at a time. Even in color. The Arduino might not be your first choice for an image processing platform, but clearly, you can do some things with it.


Filed under: Arduino Hacks
Hack a Day 12 Jul 16:00

Tinkercad does Arduino

If you’ve done 3D printing, you’ve probably at least heard of Tinkercad. This popular CAD package runs in your browser and was rescued from oblivion by Autodesk a few years ago. [Chuck] recently did a video about a new Tinkercad feature: building and simulating virtual Arduino circuits. You can watch it below.

There are a variety of components you can add to your design. You’ll find an integrated code editor and a debugger. You can even get to the serial monitor, all in your browser with no actual Arduino hardware. You can also build simple circuits that don’t use an Arduino, although the component selection is somewhat limited.

This could be great for teaching Arduino in classrooms or when you want to do some development in a hotel room. The layout is very visual, so if you are accustomed to reading schematics, you may not appreciate the style. In addition, the selection of components is somewhat limited (including only supporting the Arduino UNO, as far as we could tell). So for educational purposes, it is great. For breadboarding your next great Arduino-powered robot, maybe not so much.

If you remember Circuits123 (or circuits.io), this is the same underlying technology. They’ve just integrated it with Tinkercad. However, there doesn’t seem to be any real integration between the two other than they are on the same web page now. Perhaps in the future, they’ll let you drop components on the circuit that also show up in the 3D design (or, at least, with sockets or holders for those components).

However, having a simulated Arduino with a debugger could come in handy even if you don’t care about the circuit simulations. If you really want to do circuit simulation, it is hard to go wrong with LTSpice. If you really want it to be in your browser, there’s always Falstad.


Filed under: Arduino Hacks

A Live ECU Simulator for OBD2 Projects

If you are working with OBD2 hardware or software, it’s easy enough to access test data, simply plug into a motor vehicle with an OBD2 socket. If, however, you wish to test OBD2 software under all possible fault conditions likely to be experienced by an engine, you are faced with a problem in that it becomes difficult to simulate all faults on a running engine without breaking it. This led [Fixkick] to create an OBD2 simulator using a secondhand Ford ECU supplied with fake sensor data from an Arduino to persuade it that a real engine was connected.

The write-up is quite a dense block of text to wade through, but if you are new to the world of ECU hacking it offers up some interesting nuggets of information. In it there is described how the crankshaft and camshaft sensors were simulated, as well as the mass airflow sensor, throttle position, and speedometer sensors. Some ECU inputs require a zero-crossing signal, something achieved with the use of small isolating transformers. The result is a boxed up unit containing ECU and Arduino, with potentiometers on its front panel to vary the respective sensor inputs.

We’ve brought you quite a few OBD2 projects over the years, for example, there was this LED tachometer, and a way into GM’s OnStar.

Thanks [darkspr1te] for the tip.


Filed under: Arduino Hacks, car hacks
Hack a Day 10 Jul 16:30