Posts | Comments

Planet Arduino

Archive for the ‘code’ Category

The readability of your code can make the difference between your project being a joy to work on, or an absolute headache. This goes double when collaborating with others. Having easily parsed code reduces your cognitive load and makes solving problems easier. To try and help with this, [PTS93] developed the Stator library to make certain common tasks simpler to read.

The aim of the library is to get rid of piles of state tracking variables and endless if/else statements – hence the name. It’s designed primarily for the Arduino IDE but doesn’t have any dependencies on the API, so can be used in other C++ environments. It comes with a variety of neat tools for common jobs, such as reading an analog sensor with hysteresis around a trigger point, as well as easy ways to track state changes across multiple variables. By using basic English terms instead of condition checks and mathematical operators, it can make things more readable and easier to follow.

The power of the Arduino platform has always been in its easy to use libraries that make everything easier, from interfacing LCDs to working with Amazon Dash buttons.

We’ve all been there. When debugging a microcontroller project, we just want to put in a print statement to figure out what’s going on with the microcontroller in real time. However, advanced embedded programmers know that printf statements are verboten: they’re just too SLOW. While not fixing this plight entirely, [Atakan Sarioglu] has come up with a clever way to create readable debug messages with minimal runtime overhead.

[Atakan Sarioglu]’s innovation, called BigBug (Github), is a dynamically-generated codebook. The codebook translates abbreviated messages sent over serial (UART here) to longer-form human-readable messages. To generate the codebook, BigBug automatically parses your comments to create a lookup between an abbreviation and the long-form message. When you are running your program on the microcontroller, BigBug will translate the short codes to long messages in real-time as you send log/debug data over serial.

For example (not restricted to Arduino-only), if you write Serial.println("HW") //@BB[HW] Hello World!, BigBug will translate the received characters HW\n to Hello World!. In this simple example, the abbreviation uses 3 characters while the fully readable message uses 13 characters, for a savings of ~75% with no loss of clarity. More advanced usage lets you log data: Serial.println("DT 1 1") //@BB[DT] Today's Date is: {0}/{1} becomes Today's Date is 1/1. You can also use enumerated variables (last example could showToday's Date is Jan. 1 with the same print command).

In terms of real-world benefit, using a 115200 baud connection (with 8N1 encoding) this is 115200 bits per second /(8+1) bits per byte = 12800 bytes/sec = 1 byte every 80 microseconds. Sending 13 bytes of Hello World!\n (in a naive, blocking UART implementation) takes ~1 ms of CPU time. With the shortcode HW\n, it would take ~0.25 ms to send essentially the same message (then decoded by BigBug). Note that because this just operates on serial data, BigBug is language independent

If you’ve been constrained by serial throughput for debugging, this looks like a well-polished tool to solve your problems. If you are just using an Arduino and throughput is no issue, then try this tool to debug Arduino programs. Or you could always double-down and use a microcontroller to debug another microcontroller.

[Ido Gendel] was thinking about new and interesting ways to send data between devices, when he realized that the answer was right in his hand. Literally: he decided to try sending data using the mouse pointer. What he came up with was an interesting hack that uses small movements of the mouse pointer to send data at up to 1200bps, or about 150 bytes per second.

The way he did this was very, very clever. He used an Arduino Leonardo that is set to emulate a mouse, working alongside his existing mouse. This setup means that he can use his existing mouse: the system just sees the Arduino as a second mouse, and the pointer just looks a little jerky when you zoom in. That is because the Arduino is just sending tiny movements, each of which is a code that represents a nybble (4 binary bits) of data. By using both a combination of three left-right or up-down movements, he was able to create 16 movements, each of which can encode 4 bits of data. Each of these encoding movements also returns the mouse to its origin point, so the mouse doesn’t mysteriously scroll off the screen when data is being sent.

The encoding scheme used by [Ido].
The encoding scheme used by [Ido].
On the computer, a custom program detects and decodes this movement, recreating the stream of data. In his example, this is data from a photoresistor, but it could be anything from random data to the contents of a secret file.

Of course, this isn’t a practical way of sending secret data: it only works when the custom program is active, 150 bytes per second is rather slow and enabling mouse acceleration in Windows stops it working because it masks the small movement. But it is an awesome hack that shows how you can send data in ways that you might not first think of. When you are trying to make a device as simple as possible, this is an important lesson to learn.


Filed under: Arduino Hacks, peripherals hacks
Mar
23

Enigma Machine Wristwatch

arduino hacks, Cipher, clock hacks, code, enigma, enigma machine, wearable hacks, wristwatch Commenti disabilitati su Enigma Machine Wristwatch 

We don’t find smartwatches to be supremely usable yet. This one sets a definition for usefulness. The Enigma machine is of course the cipher process used by the Germans during World War II. This Enigma Machine wristwatch is not only functional, but the appearance is modelled after that of the original machine. With the speckled gray/black case and the Enigma badge branding [Asciimation] has done a fine job of mimicking the original feel.

Driving the machine is an Arduino Pro Mini. We’ve seen Arduino Enigma Machines in the past so it’s not surprising to see it again here. The user interface consists of an OLED display at 128×64 resolution, three buttons, with a charging port to the right and on/off switch on the left.

The device is demonstrated after the break. Quite a bit of button presses are used to set up each of the three encoder wheels. But that’s hardly avoidable when you’re not committing to a full keyboard. We’re pretty impressed by the functionality of [Asciimation’s] interface considering it’s hardware simplicity.

This seems perfect for kids that are proving to have an interest in engineering. They learn about ciphers, embedded programming, and mechanical design and crafting (this is a hand-sewn leather wristband). Of course if you build one and start wearing it into the office we won’t judge.


Filed under: Arduino Hacks, clock hacks, wearable hacks
Set
06

Code generator for custom Android/Arduino menus

Android, arduino, code Commenti disabilitati su Code generator for custom Android/Arduino menus 

FB6OIZFHZB3LPTL.MEDIUM

by drmpf @ instructables.com:

The first instructable shows you how to use the free pfodDesigner available on GooglePlay to design Android menus to switch Ardunio outputs on and off from your Android mobile, without you having to write any program code at all. The Fish Tank picture above shows the example designed in this instructable.

The example project shown here is suitable for complete beginners. This instructable does not require any soldering and No coding experience is required.

Once you have finished this instructable you will be able to design whatever menus you need to switch Arduino outputs on and off. When you have completed the second instructable (to be posted later) you will be able to switch real things on and off from your Android mobile, via relays connected to Arduino’s digital outputs.

Code generator for custom Android/Arduino menus - [Link]

Giu
04

Simple digital code lock using arduino

arduino, code, keypad, matrix Commenti disabilitati su Simple digital code lock using arduino 

digital-codelock

by praveen @ circuitstoday.com:

Digital code lock or digital combination lock are a type of digital locks where a combination of digits/characters or both are used for unlocking the lock. This article is about a simple digital code lock using arduino. Here the code consists of a combination of digits from 1 to 6. There are separate keys for locking and unlocking the system. The system can be unlocked by pressing the unlock button after entering the correct combination of digits. A hex key pad is used as the input device. Only the first two rows of key (1, 2, 3, A, 4, 5, 6, B) are used in this project. A is used for locking the system and B is used for unlocking the system. Read this article Interfacing hex keypad to arduino for knowing more about hex keypad and its interfacing to the arduino. The circuit diagram of the digital code lock using arduino is shown in the figure below.

Simple digital code lock using arduino - [Link]

Giu
04

Simple digital code lock using arduino

arduino, code, keypad, lock, matrix Commenti disabilitati su Simple digital code lock using arduino 

digital-codelock

by praveen @ circuitstoday.com:

Digital code lock or digital combination lock are a type of digital locks where a combination of digits/characters or both are used for unlocking the lock. This article is about a simple digital code lock using arduino. Here the code consists of a combination of digits from 1 to 6. There are separate keys for locking and unlocking the system. The system can be unlocked by pressing the unlock button after entering the correct combination of digits. A hex key pad is used as the input device. Only the first two rows of key (1, 2, 3, A, 4, 5, 6, B) are used in this project. A is used for locking the system and B is used for unlocking the system. Read this article Interfacing hex keypad to arduino for knowing more about hex keypad and its interfacing to the arduino. The circuit diagram of the digital code lock using arduino is shown in the figure below.

Simple digital code lock using arduino - [Link]

Mar
24

Arduino Helper Functions

arduino, arduino day, ArduinoD14, code Commenti disabilitati su Arduino Helper Functions 

Sometimes finding the right snippet of code to use in your Arduino sketch is as simple as reading the Monday Jolt on the MAKE site.

Read more on MAKE

Mag
13

Arduino Helper Functions

arduino, code, Coding, EEPROM, monday jolt, wifi Commenti disabilitati su Arduino Helper Functions 

Sometimes finding the right snippet of code to use in your Arduino sketch is as simple as reading the Monday Jolt on the MAKE site.

Read the full article on MAKE

Apr
29

Designing a Window Manager for a Micro-Controller

arduino, AVR, code, Computers & Mobile, Electronics, gui, monday jolt, The Monday Jolt, VGA, Window Manager Commenti disabilitati su Designing a Window Manager for a Micro-Controller 

Close-up of the Default ConfigurationAndrew Rossignol decided to implement a window manager to run on an ATmega1284p micro-controller using the uVGA-II VGA controller.

Read the full article on MAKE



  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook