Posts with «xod» label

Afroman Teaches Intro to Servos, Builds Laser Turret

After a longish hiatus, we were pleased to see a new video from [Afroman], one of the most accessible and well-spoken teachers the internet has to offer. If you’re new to electronics, see the previous sentence and resolve to check out his excellent videos. The new one is all about servos, and it culminates in a simple build that provides a foundation for exploring robotics.

[Afroman] leaves no gear unturned in his tour de servo, which is embedded after the break. He explains the differences between open vs. closed loop motor systems, discusses the different sizes and types of servos available, and walks through the horns and pigtails of using them in projects. Finally, he puts this knowledge to use by building a laser turret based on a pan-tilt platform.

The Arduino-driven turret uses two micro servos controlled with pots to move by degrees in X/Y space. Interestingly, [Afroman] doesn’t program the board in the Arduino IDE using wiring. Instead, he uses an open-source microcontroller language/IDE called XOD that lets you code by building a smart sort of schematic from drag-and-drop components and logic nodes. Draw the connections, assign your I/O pin numbers, and XOD will compile the code and upload it directly to the board.

XOD seems like a good tool for beginners to do rapid prototyping. On the other hand, a look into the generated code reveals a whole lot of wrappers that obfuscate the bits of code that actually do stuff. There doesn’t seem to be a way to shed them, either, so once you design something in XOD, you’re kind of stuck using it to iterate. That said, the generated code is well documented, and someone who knows what they’re looking at could find, for instance, the I/O pin assigned to the blink sketch LED.

Once the novelty of the double laser cat tormentor has subsided, use the other servos in that 5-pack you bought to flip a light switch, control a knob, or play the glockenspiel.


Filed under: how-to, Laser Hacks

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